Registry / serialization / type-of-is

type-of-is

JSON →
library3.5.1jsnpmunverified

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-is
INSTALL
IMPORT
SIG · TYPE-OF-IS
T
type-of-is
serializationjavascriptv3.5.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Type
import Type from 'type-of-is';
import { Type } from 'type-of-is'; // or import * as Type from 'type-of-is';
The library primarily uses a default export pattern where the main 'Type' object/function is exported. Attempting named imports or wildcard imports might lead to unexpected behavior if not configured for CommonJS interop. Since v3.x, it should support both CJS and ESM.
Type.of
import Type from 'type-of-is'; const typeName = Type.of({});
import { of } from 'type-of-is';
Methods like `of`, `is`, and `string` are properties of the main `Type` export, not individual named exports. They must be accessed via the imported `Type` object.
Type
const Type = require('type-of-is');
This is the original and most documented import style for CommonJS environments.

Demonstrates core type detection, string representation, and type comparison functionalities using both direct methods and the shorthand `Type()` function.

import Type from 'type-of-is'; // Determine type using Type.of() or Type(single_argument) console.log('Type.of("hello"):', Type.of('hello')); // [Function: String] console.log('Type(123):', Type(123)); // [Function: Number] console.log('Type.of([]):', Type.of([])); // [Function: Array] console.log('Type.of(null):', Type.of(null)); // null console.log('Type.of(undefined):', Type.of(undefined)); // undefined // Get type as a string using Type.string() console.log('Type.string("world"):', Type.string('world')); // "String" console.log('Type.string({}):', Type.string({})); // "Object" console.log('Type.string(null):', Type.string(null)); // "null" // Test if an object is of a specific type using Type.is() or Type(obj, type) function CustomObject() {} const myObj = new CustomObject(); console.log('Type.is(true, Boolean):', Type.is(true, Boolean)); // true console.log('Type.is("test", "String"):', Type.is('test', 'String')); // true console.log('Type.is(myObj, CustomObject):', Type.is(myObj, CustomObject)); // true console.log('Type.is(myObj, Object):', Type.is(myObj, Object)); // false (Type.is checks direct constructor, not prototype chain by default) // Type.instance() wraps instanceof console.log('Type.instance(myObj, CustomObject):', Type.instance(myObj, CustomObject)); // true console.log('Type.instance(myObj, Object):', Type.instance(myObj, Object)); // true
Debug
Known issues
gotchaThe `Type.of()` method returns `null` for `null` and `undefined` for `undefined`. This differs from `Type.string()` which returns the string literals "null" and "undefined" respectively. Be mindful of which method you use based on whether you need the actual primitive value or its string representation.
fix
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.
affects: >=1.0.0
deprecatedThe npm registry lists version 3.4.0 as the latest public release, last published on February 7, 2017. While the package.json indicates version 3.5.1, the lack of public updates in over 7 years suggests the package might be unmaintained or have a very inactive development cycle. Use with caution for new projects requiring active support or frequent updates.
fix
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.
affects: >=3.4.0
gotchaBy default, `Type.is(obj, type)` checks for direct constructor match, not inheritance. For example, `Type.is(new CustomObject(), Object)` will return `false`. If you need to check if an object is an instance of a class anywhere in its prototype chain, use `Type.instance(obj, type)` (which is a wrapper around `instanceof`).
fix
For direct constructor matching, use `Type.is(obj, Constructor)`. For checking against the prototype chain (like `instanceof`), use `Type.instance(obj, Constructor)`.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined (in ESM context)
Attempting to use `const Type = require('type-of-is');` in an ES Module (`.mjs` file or `type: 'module'` project) context.
fix
Change the import statement to `import Type from 'type-of-is';`.
TypeError: Type.of is not a function (when using named import)
Incorrectly importing `Type` as a named export (e.g., `import { Type } from 'type-of-is';`) or a wildcard import (e.g., `import * as Type from 'type-of-is';`) instead of a default import, in a way that doesn't correctly resolve the default export.
fix
Ensure `Type` is imported as a default export: `import Type from 'type-of-is';`.
console.log(Type.is([], Object)); // false (unexpected for some users)
Misunderstanding `Type.is` behavior: it primarily checks for a direct constructor match rather than `instanceof` behavior (i.e., checking against the prototype chain). An array's direct constructor is `Array`, not `Object`.
fix
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.
Upgrade
Version history
3.5.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
type-of-is — npm install type-of-is · libregistry