Skip to content

πŸ›‘οΈ Elegant and type-safe value validation library for TypeScript.

License

Notifications You must be signed in to change notification settings

shahradelahi/is

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

@se-oss/is

CI NPM Version MIT License npm bundle size Install Size

@se-oss/is is an elegant and type-safe value validation library for TypeScript and JavaScript.


πŸ“¦ Installation

npm install @se-oss/is
Install using your favorite package manager

pnpm

pnpm install @se-oss/is

yarn

yarn add @se-oss/is

πŸ“– Usage

Basic validation

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

Type detection

import is from '@se-oss/is';

is('hello');
//=> 'string'

is(new Map());
//=> 'Map'

is(new Uint8Array());
//=> 'Uint8Array'

Type narrowing

import is from '@se-oss/is';

const value: unknown = 'β˜•';

if (is.string(value)) {
  console.log(value.length);
  //=> 2
}

Logical operators

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

Advanced usage

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

Web & String validation

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

πŸ“š Documentation

For all configuration options, please see the API docs.

🀝 Contributing

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! πŸ™

License

MIT Β© Shahrad Elahi and contributors.

About

πŸ›‘οΈ Elegant and type-safe value validation library for TypeScript.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published