type-of-is provides a reliable mechanism for JavaScript type detection and comparison, addressing the well-known quirks of the native `typeof` operator (e.g., `typeof null` being 'object', or arrays being 'object'). It uses a combination of `Object.prototype.toString` and constructor checks to determine the true type of a value, including primitives, built-in objects, and custom constructors. The package is currently at version 3.5.1, though the latest publicly listed version on npm (3.4.0) was published in February 2017, suggesting a very slow or effectively halted release cadence. Its key differentiator is its commitment to 'sensible / unsurprising' type results, making it suitable for validation and conditional logic where native `typeof` falls short. It offers functions like `Type.of` to get the constructor, `Type.string` for a string representation, and `Type.is` for comparison against a type or string.
npm install type-of-isVerified import paths — ran on the pinned version, not inferred.
Demonstrates core type detection, string representation, and type comparison functionalities using both direct methods and the shorthand `Type()` function.
Use `Type.of(value)` when you need the constructor function (or primitive value for null/undefined). Use `Type.string(value)` when you need a consistent string name for the type.
Evaluate the stability requirements for your project. Consider alternative, actively maintained type-checking libraries if continuous updates and community support are critical. If using, thoroughly test against your specific use cases.
For direct constructor matching, use `Type.is(obj, Constructor)`. For checking against the prototype chain (like `instanceof`), use `Type.instance(obj, Constructor)`.
Change the import statement to `import Type from 'type-of-is';`.
Ensure `Type` is imported as a default export: `import Type from 'type-of-is';`.
If you intend to check inheritance (e.g., if an array is ultimately an `Object`), use `Type.instance([], Object)` which will return `true` as it leverages JavaScript's `instanceof` operator. `Type.is` is for more specific, direct type comparisons.
No dependency data recorded yet.