Registry / serialization / is-what-type

is-what-type

JSON →
library1.1.4jsnpmunverified

is-what-type is a lightweight and comprehensive JavaScript/TypeScript utility library designed for robust type checking of various values. It offers a single default export, `isWhatType`, which returns a string representation of a value's type, alongside numerous named exports like `isString`, `isNumber`, `isObject`, `isArray`, and `isPromise` for specific boolean checks. Currently at version 1.1.4, this library focuses on providing a wide array of type-checking functions, from primitive types to complex browser and Node.js-specific objects like Blob, File, and Buffer, making it suitable for both front-end and back-end development. Its main differentiator lies in its extensive collection of precise `isX` functions and the flexibility of getting a detailed type string, catering to detailed validation scenarios.

npm install is-what-type
INSTALL
IMPORT
SIG · IS-WHAT-TYPE
I
is-what-type
serializationjavascriptv1.1.4
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.

isWhatType
import isWhatType from 'is-what-type';
import { isWhatType } from 'is-what-type';
The primary `isWhatType` function is a default export, returning the type name as a string.
isString, isNumber
import { isString, isNumber } from 'is-what-type';
const isString = require('is-what-type').isString;
CommonJS `require` for specific named exports works, but ESM named imports are preferred in modern TypeScript/JavaScript projects.
all named exports
import * as TypeChecks from 'is-what-type';
import TypeChecks from 'is-what-type';
To import all individual `isX` functions into a namespace object, use `* as`. The default export (`isWhatType`) will not be on this object.

Demonstrates importing both the default `isWhatType` function and several named `isX` type-checking functions, showing their usage with various data types and conditional checks.

import isWhatType, { isString, isNumber, isPlainObject, isArray } from 'is-what-type'; console.log(isWhatType('hello')); // 'string' console.log(isWhatType(123)); // 'number' console.log(isWhatType({ a: 1 })); // 'object' console.log(isWhatType([1, 2, 3])); // 'array' console.log(isWhatType(null)); // 'null' console.log(isWhatType(undefined)); // 'undefined' const myString = 'TypeScript'; const myNumber = 42; const myObject = { key: 'value' }; const myArray = [true, false]; if (isString(myString)) { console.log(`${myString} is indeed a string.`); } if (isNumber(myNumber)) { console.log(`${myNumber} is definitely a number.`); } if (isPlainObject(myObject)) { console.log(`The value ${JSON.stringify(myObject)} is a plain object.`); } if (isArray(myArray)) { console.log(`The value ${JSON.stringify(myArray)} is an array.`); } // Example with a complex type not always easy to check const myDate = new Date(); import { isDate } from 'is-what-type'; if (isDate(myDate)) { console.log(`${myDate} is a Date object.`); }
Debug
Known issues
gotchaMixing CommonJS `require` with ESM `import` statements for this library can lead to unexpected import resolution issues or runtime errors, especially in environments that strictly enforce ESM.
fix
Always use `import` statements for both default and named exports (`import isWhatType from 'is-what-type';` or `import { isString } from 'is-what-type';`) when working in an ESM-compatible environment. If CommonJS is required, ensure your bundler or environment correctly transpiles the imports.
affects: >=1.0.0
gotchaThe default export `isWhatType` returns a string (e.g., 'string', 'number', 'array', 'object', 'null', 'undefined'). It is crucial to use strict equality (`===`) when comparing its output, as loose equality (`==`) can lead to subtle bugs.
fix
Always use `isWhatType(value) === 'typeString'` for reliable comparisons, or prefer the specific named `isX` functions (e.g., `isString(value)`) for boolean checks which are less prone to string comparison errors.
affects: >=1.0.0
gotchaWhile comprehensive, the `isPlainObject` function specifically checks for objects created by `Object` constructor or `Object.create(null)`, excluding instances of custom classes or objects with different prototypes.
fix
Understand the distinction: `isObject` will return true for any object, including class instances, while `isPlainObject` is stricter. Choose the appropriate function based on whether you need to check for any object or only plain JSON-like objects.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , is_what_type__WEBPACK_IMPORTED_MODULE_0__.isWhatType) is not a function
Attempting to use `isWhatType` as a named import when it is a default export in a bundled environment (e.g., Webpack/Rollup).
fix
Change your import statement from `import { isWhatType } from 'is-what-type';` to `import isWhatType from 'is-what-type';`.
TypeError: Cannot read properties of undefined (reading 'isString')
Attempting to access a named export (`isString`) from the default import or a CommonJS `require()` call that resolves to the default export without destructuring.
fix
Ensure you are using named imports correctly: `import { isString } from 'is-what-type';`. If using CommonJS, it should be `const { isString } = require('is-what-type');`.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
is-what-type — npm install is-what-type · libregistry