Elegant and type-safe value validation library for TypeScript and JavaScript.
npm install @se-oss/is


!npm bundle size

_@se-oss/is_ is an elegant and type-safe value validation library for TypeScript and JavaScript.
---
- Installation
- Usage
- Documentation
- Contributing
- License
``bash`
npm install @se-oss/is
Install using your favorite package manager
pnpm
`bash`
pnpm install @se-oss/is
yarn
`bash`
yarn add @se-oss/is
`typescript
import is from '@se-oss/is';
is.string('☕');
//=> true
is.number(42);
//=> true
is.array([1, 2, 3]);
//=> true
is.urlInstance(new URL('https://example.com'));
//=> true
`
`typescript
import is from '@se-oss/is';
is('hello');
//=> 'string'
is(new Map());
//=> 'Map'
is(new Uint8Array());
//=> 'Uint8Array'
`
`typescript
import is from '@se-oss/is';
const value: unknown = '☕';
if (is.string(value)) {
console.log(value.length);
//=> 2
}
`
`typescript
import is from '@se-oss/is';
// Check if any of the predicates match
is.any([is.string, is.number], 'hello');
//=> true
// Check if all of the predicates match
is.all([is.array, is.nonEmptyArray], [1, 2, 3]);
//=> true
// Check if a value is optional
is.optional(undefined, is.string);
//=> true
// Use as predicate factories
const isStringOrNumber = is.any([is.string, is.number]);
isStringOrNumber('hello');
//=> true
`
`typescript
import is from '@se-oss/is';
// Validate array elements
is.array([1, 2, 3], is.number);
//=> true
// Check if a number is in range
is.inRange(3, [0, 5]);
//=> true
// Check for plain objects
is.plainObject({ a: 1 });
//=> true
`
`typescript
import is from '@se-oss/is';
is.json('{"a":1}');
//=> true
is.base64('SGVsbG8gd29ybGQ=');
//=> true
is.ipv4('127.0.0.1');
//=> true
is.hexColor('#ffffff');
//=> true
``
For all configuration options, please see the API docs.
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub
Thanks again for your support, it is much appreciated! 🙏
MIT © Shahrad Elahi and contributors.