All packages
Core 449/mo
@munesoft/

isx

Tiny, fast, unified type-checking and validation library. Replace dozens of is-* packages.

Installation

$ npm install @munesoft/isx

Documentation

@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.

version license dependencies tests bundle node


๐Ÿš€ 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.json files, node_modules directories, 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 โ€” typeof first, tag-based fallback only when needed
  • โ—†โœ… Tree-shakable โ€” import only what you use
  • โ—†โœ… Universal โ€” Node.js and browsers

๐Ÿ“ฆ Installation

bash
npm install @munesoft/isx

โšก Quick Start

js
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

js
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

js
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

js
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

js
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.iterator

Object Helpers

js
is.hasKey(obj, 'key')          // own property check
is.hasKeys(obj, ['a', 'b'])    // all own properties present

Functions

js
is.function(value)          // typeof === 'function'
is.asyncFunction(value)     // async function
is.generatorFunction(value) // function*

Nil / Existence

js
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

js
is.empty([])         // true
is.empty('')         // true
is.empty({})         // true
is.empty(new Map())  // true
is.notEmpty([1, 2])  // true

Deep Equality

js
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)                                   // true

Uses an iterative algorithm (no recursion) โ€” safe for deeply nested structures.


๐Ÿ”ฅ Advanced Features

Functional Style

Wrap a value for method chaining:

js
is('hello').string()   // true
is(42).number()        // true
is(3).odd()            // true
is([]).empty()         // true

Assertion Mode

Throws a TypeError if the check fails:

js
is.assert.string('hello')   // passes silently
is.assert.string(42)        // throws TypeError: expected string, got number
is.assert.integer(1.5)      // throws TypeError

Use in validation functions, constructors, or anywhere you want fail-fast behaviour.

Schema Matching

Validate an object against a schema in one call:

js
const result = is.match(user, {
  id:     'number',
  name:   'string',
  active: 'boolean',
});

result.valid   // true / false
result.errors  // string[] โ€” one message per failing field

Schema 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 }) |

js
// 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

js
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:

js
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')  // passes

Custom 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:

js
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:

js
// 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

bash
# 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