Installation
$ npm install @munesoft/isxDocumentation
@munesoft/isx
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.
๐ Why isx?
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
๐ฆ Installation
npm install @munesoft/isx
โก Quick Start
import 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); // true๐ API Reference
Type Detection
is.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"Primitives
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)
Numbers
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) // true
Objects
is.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.iteratorObject Helpers
is.hasKey(obj, 'key') // own property check is.hasKeys(obj, ['a', 'b']) // all own properties present
Functions
is.function(value) // typeof === 'function' is.asyncFunction(value) // async function is.generatorFunction(value) // function*
Nil / Existence
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) // !value
Collections
is.empty([]) // true
is.empty('') // true
is.empty({}) // true
is.empty(new Map()) // true
is.notEmpty([1, 2]) // trueDeep Equality
is.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.
๐ฅ Advanced Features
Functional Style
Wrap a value for method chaining:
is('hello').string() // true
is(42).number() // true
is(3).odd() // true
is([]).empty() // trueAssertion Mode
Throws 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.
Schema Matching
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 });Reusable Schema Validators
const validateUser = is.schema({
id: 'number',
name: 'string',
});
validateUser({ id: 1, name: 'Alice' }) // { valid: true, errors: [] }
validateUser({ id: 'oops' }) // { valid: false, errors: ['...'] }Custom Validators
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
Strict Mode
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); // reset
๐ฒ Tree-Shaking
Import 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';๐ Comparison
| 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 | โ ๏ธ varies | โ
yes |
| Performance | โ ๏ธ varies | โ
optimized |
๐งช Running Tests & Benchmarks
# Tests npm test # Benchmarks npm run bench
๐ Keywords
javascript 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
๐ License
MIT ยฉ munesoft
