is-type-of is a comprehensive utility library for performing various type checks on JavaScript values, primarily targeting Node.js environments. It offers a wide array of functions to identify primitive types (like string, number, boolean, bigint, symbol, null, undefined), standard JavaScript objects (array, function, object), and Node.js-specific constructs such as generator functions and async functions. The package ships with full TypeScript support, including type guards, enhancing development with strong typing. The current stable version is 2.2.0, released in December 2024, which includes Node.js 14 support for `hasOwn`. The library maintains a regular release cadence, with version 2.1.0 (November 2023) introducing dual CommonJS and ES Module support using `tshy`, ensuring broad compatibility. Its key differentiators include its extensive and specific type checking methods and seamless TypeScript integration, making it a reliable tool for robust type validation.
npm install is-type-ofVerified import paths — ran on the pinned version, not inferred.
Demonstrates both default and named imports for various type checks, including basic primitives, objects, generator functions, and BigInt. It also illustrates the usage of TypeScript type guards provided by the library.
Manually iterate through array elements and apply `is.typeOf()` checks or use a third-party deep validation library if element-level validation is required.
Always use primitive literals for values expected to be primitive types. If object wrappers might be encountered, convert them to primitives (`String(value)`) or check for both (`is.string(val) || is.object(val) && val instanceof String`).
For ESM, use `import is from 'is-type-of'` for the main object and `import { isArray } from 'is-type-of'` for individual helpers. For CJS, use `const is = require('is-type-of')` and access methods via `is.isArray`. Ensure `"esModuleInterop": true` in `tsconfig.json` for TypeScript projects consuming CJS packages that export a default.If importing the main `is` object, access the method as `is.isArray(value)`. If you want `isArray` as a direct function, use named import: `import { isArray } from 'is-type-of';`.Ensure `import is from 'is-type-of';` (for ESM/TypeScript) or `const is = require('is-type-of');` (for CommonJS) is used to correctly import the main utility object.Since v2.1.0, `is-type-of` is built with `tshy` for dual ESM/CJS support. Ensure your Node.js version is recent enough to handle dual packages correctly (Node.js 12+ usually suffices, but Node.js 14+ is recommended for full feature set). If possible, refactor your consuming code to use `import` syntax if your project is ESM-first, or ensure your bundler/loader is correctly configured for dual-package consumption.
No dependency data recorded yet.