The last "is-*" package you'll ever need.
A tiny, fast, zero-dependency type-checking and validation library for JavaScript and TypeScript. Replace dozens of fragmented is-* micro-packages with one unified, tree-shakable utility.
The npm ecosystem has hundreds of tiny packages like is-odd, is-array, is-number, is-plain-object, and kind-of. They are:
- Fragmented β you need 10+ packages for basic type checking
- Inconsistent β each has its own API quirks
- Inefficient β dozens of
package.jsonfiles,node_modulesdirectories, and dependency trees to maintain
isx solves this with:
- β A unified API β one import for everything
- β Zero dependencies β nothing to audit or update
- β
Optimized hot paths β
typeoffirst, tag-based fallback only when needed - β Tree-shakable β import only what you use
- β Universal β Node.js and browsers
npm install @munesoft/isximport is from '@munesoft/isx';
is.string('hello'); // true
is.number(123); // true
is.array([1, 2, 3]); // true
is.object({}); // true
is.plainObject({}); // true
is.odd(3); // true
is.even(4); // trueis.type(value) // Returns type name as a string
is.type('hello') // "string"
is.type(42) // "number"
is.type(NaN) // "nan"
is.type([]) // "array"
is.type({}) // "object"
is.type(new Date()) // "date"
is.type(new Map()) // "map"
is.type(null) // "null"is.string(value) // typeof value === 'string'
is.number(value) // typeof value === 'number' && !isNaN(value)
is.boolean(value) // typeof value === 'boolean'
is.symbol(value) // typeof value === 'symbol'
is.bigint(value) // typeof value === 'bigint'
is.primitive(value) // value !== Object(value)is.integer(10) // true β Math.floor(v) === v
is.float(1.5) // true β not an integer
is.odd(3) // true β bitwise fast path
is.even(4) // true β bitwise fast path
is.nan(NaN) // true
is.positive(1) // true
is.negative(-1) // true
is.finite(1) // true
is.infinite(Infinity) // true
is.safeInteger(42) // true
is.zero(0) // trueis.object(value) // non-null, typeof === 'object'
is.plainObject(value) // {} or Object.create(null), no class instances
is.array(value) // Array.isArray(value)
is.map(value) // value instanceof Map
is.set(value) // value instanceof Set
is.date(value) // value instanceof Date && valid
is.regexp(value) // value instanceof RegExp
is.error(value) // value instanceof Error
is.promise(value) // duck-typed .then check
is.iterable(value) // has Symbol.iteratoris.hasKey(obj, 'key') // own property check
is.hasKeys(obj, ['a', 'b']) // all own properties presentis.function(value) // typeof === 'function'
is.asyncFunction(value) // async function
is.generatorFunction(value) // function*is.nil(value) // null or undefined
is.null(value) // strictly null
is.undefined(value) // strictly undefined
is.defined(value) // not undefined
is.truthy(value) // !!value
is.falsy(value) // !valueis.empty([]) // true
is.empty('') // true
is.empty({}) // true
is.empty(new Map()) // true
is.notEmpty([1, 2]) // trueis.deepEqual({ a: 1, b: [2, 3] }, { a: 1, b: [2, 3] }) // true
is.deepEqual(new Date('2024'), new Date('2024')) // true
is.deepEqual(NaN, NaN) // trueUses an iterative algorithm (no recursion) β safe for deeply nested structures.
Wrap a value for method chaining:
is('hello').string() // true
is(42).number() // true
is(3).odd() // true
is([]).empty() // trueThrows a TypeError if the check fails:
is.assert.string('hello') // passes silently
is.assert.string(42) // throws TypeError: expected string, got number
is.assert.integer(1.5) // throws TypeErrorUse in validation functions, constructors, or anywhere you want fail-fast behaviour.
Validate an object against a schema in one call:
const result = is.match(user, {
id: 'number',
name: 'string',
active: 'boolean',
});
result.valid // true / false
result.errors // string[] β one message per failing fieldSchema rule types:
| Rule | Behaviour |
|---|---|
'string' |
type name match via is.type() |
'number' |
same β works for all type names |
Date (constructor) |
instanceof Date |
(v) => boolean |
custom validator function |
{ β¦ } (nested) |
deep sub-schema (requires { deep: true }) |
// Deep schema
is.match(data, {
user: { id: 'number', name: 'string' },
}, { deep: true });
// Constructor rule
is.match({ createdAt: new Date() }, { createdAt: Date });
// Custom function rule
is.match({ age: 25 }, { age: (v) => v >= 18 });const validateUser = is.schema({
id: 'number',
name: 'string',
});
validateUser({ id: 1, name: 'Alice' }) // { valid: true, errors: [] }
validateUser({ id: 'oops' }) // { valid: false, errors: ['...'] }Extend is with your own named checks:
is.extend('email', (v) =>
typeof v === 'string' && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v)
);
is.email('user@example.com') // true
is('bad').email() // false
is.assert.email('user@example.com') // passesCustom validators are immediately available in:
is.name(value)is(value).name()is.assert.name(value)is.match(obj, { field: 'name' })β via type string
In strict mode, is.match stops on the first failing field:
is.strict(true);
is.match(value, schema); // stops at first error
is.strict(false); // resetImport only what you need for minimal bundle impact:
// Full default import
import is from '@munesoft/isx';
// Named imports β works with any bundler (Rollup, Vite, esbuild, webpack 5)
import { isString, isNumber } from '@munesoft/isx';
// Sub-path imports
import { isOdd, isEven } from '@munesoft/isx/number';
import { isPlainObject } from '@munesoft/isx/object';
import { isString } from '@munesoft/isx/string';| Feature | is-* micro-packages |
@munesoft/isx |
|---|---|---|
| Unified API | β one package per check | β everything in one |
| Zero dependencies | β chains of deps | β none |
| Tree-shakable | β mostly not | β yes |
| Deep equality | β separate package | β built-in |
| Schema validation | β no | β built-in |
| Assertion mode | β no | β built-in |
| Custom validators | β no | β
is.extend() |
| Functional style | β no | β
is(v).type() |
| Browser + Node.js | β yes | |
| Performance | β optimized |
# Tests
npm test
# Benchmarks
npm run benchjavascript type checking, is array javascript, is number nodejs, is odd javascript, is plain object, kind-of replacement, validation library js, type checker npm, unified type utils, tree shakable validation
MIT Β© munesoft