百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
I

is.js

> 编程语言
开源

微检库

9.1K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

微检库

is.js

This is a general-purpose check library.

  • No dependencies
  • AMD, Node & browser ready

Usage:

Node.js:

npm install is_js

Bower:

bower install is_js

Build:

npm run build

Test:

npm test

Contributing:

Thanks for considering to contribute. Check here

Contributors:

Many thanks to our contributors: https://github.com/arasatasaygin/is.js/graphs/contributors

Type checks

is.arguments(value:any)

Checks if the given value type is arguments.

interfaces: not, all, any

var getArguments = function() {
    return arguments;
};
var arguments = getArguments();

is.arguments(arguments);
=> true

is.not.arguments({foo: 'bar'});
=> true

is.all.arguments(arguments, 'bar');
=> false

is.any.arguments(['foo'], arguments);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.arguments([arguments, 'foo', 'bar']);
=> false

is.array(value:any)

Checks if the given value type is array.

interfaces: not, all, any

is.array(['foo', 'bar', 'baz']);
=> true

is.not.array({foo: 'bar'});
=> true

is.all.array(['foo'], 'bar');
=> false

is.any.array(['foo'], 'bar');
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.array([[1, 2], 'foo', 'bar']);
=> false

is.boolean(value:any)

Checks if the given value type is boolean.

interfaces: not, all, any

is.boolean(true);
=> true

is.not.boolean({foo: 'bar'});
=> true

is.all.boolean(true, 'bar');
=> false

is.any.boolean(true, 'bar');
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.boolean([true, 'foo', 'bar']);
=> false

is.date(value:any)

Checks if the given value type is date.

interfaces: not, all, any

is.date(new Date());
=> true

is.not.date({foo: 'bar'});
=> true

is.all.date(new Date(), 'bar');
=> false

is.any.date(new Date(), 'bar');
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.date([new Date(), 'foo', 'bar']);
=> false

is.domNode(value:any)

Checks if the given object is a dom node.

interfaces: not, all, any

var obj = document.createElement('div');
is.domNode(obj);
=> true

is.domNode({nope: 'nope'});
=> false

is.not.domNode({});
=> true

is.all.domNode(obj, obj);
=> true

is.any.domNode(obj, {nope: 'nope'});
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.domNode([obj, {nope: 'nope'}]);
=> false

is.error(value:any)

Checks if the given value type is error.

interfaces: not, all, any

is.error(new Error());
=> true

is.not.error({foo: 'bar'});
=> true

is.all.error(new Error(), 'bar');
=> false

is.any.error(new Error(), 'bar');
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.error([new Error(), 'foo', 'bar']);
=> false

is.function(value:any)

Checks if the given value type is function.

interfaces: not, all, any

is.function(toString);
=> true

is.not.function({foo: 'bar'});
=> true

is.all.function(toString, 'bar');
=> false

is.any.function(toString, 'bar');
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.function([toString, 'foo', 'bar']);
=> false

is.nan(value:any)

Checks if the given value type is NaN.

interfaces: not, all, any

is.nan(NaN);
=> true

is.not.nan(42);
=> true

is.all.nan(NaN, 1);
=> false

is.any.nan(NaN, 2);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.nan([NaN, 'foo', 1]);
=> false

is.null(value:any)

Checks if the given value type is null.

interfaces: not, all, any

is.null(null);
=> true

is.not.null(42);
=> true

is.all.null(null, 1);
=> false

is.any.null(null, 2);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.null([null, 'foo', 1]);
=> false

is.number(value:any)

Checks if the given value type is number.

interfaces: not, all, any

is.number(42);
=> true

is.number(NaN);
=> false

is.not.number('42');
=> true

is.all.number('foo', 1);
=> false

is.any.number({}, 2);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.number([42, 'foo', 1]);
=> false

is.object(value:any)

Checks if the given value type is object.

interfaces: not, all, any

is.object({foo: 'bar'});
=> true

// functions are also returning as true
is.object(toString);
=> true

is.not.object('foo');
=> true

is.all.object({}, 1);
=> false

is.any.object({}, 2);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.object([{}, new Object()]);
=> true

is.json(value:any)

Checks if the given value type is pure json object.

interfaces: not, all, any

is.json({foo: 'bar'});
=> true

// functions are returning as false
is.json(toString);
=> false

is.not.json([]);
=> true

is.all.json({}, 1);
=> false

is.any.json({}, 2);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.json([{}, {foo: 'bar'}]);
=> true

is.regexp(value:any)

Checks if the given value type is RegExp.

interfaces: not, all, any

is.regexp(/test/);
=> true

is.not.regexp(['foo']);
=> true

is.all.regexp(/test/, 1);
=> false

is.any.regexp(new RegExp('ab+c'), 2);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.regexp([{}, /test/]);
=> false

is.string(value:any)

Checks if the given value type is string.

interfaces: not, all, any

is.string('foo');
=> true

is.not.string(['foo']);
=> true

is.all.string('foo', 1);
=> false

is.any.string('foo', 2);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.string([{}, 'foo']);
=> false

is.char(value:any)

Checks if the given value type is char.

interfaces: not, all, any

is.char('f');
=> true

is.not.char(['foo']);
=> true

is.all.char('f', 1);
=> false

is.any.char('f', 2);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.char(['f', 'o', 'o']);
=> true

is.undefined(value:any)

Checks if the given value type is undefined.

interfaces: not, all, any

is.undefined(undefined);
=> true

is.not.undefined(null);
=> true

is.all.undefined(undefined, 1);
=> false

is.any.undefined(undefined, 2);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.undefined([{}, undefined]);
=> false

is.sameType(value:any, other:any)

Checks if the given value types are same type.

interface: not

is.sameType(42, 7);
=> true

is.sameType(42, '7');
=> false

is.not.sameType(42, 7);
=> false

is.windowObject(value:any)

Checks if the given object is window object.

interfaces: not, all, any

is.windowObject(window);
=> true

is.windowObject({nope: 'nope'});
=> false

is.not.windowObject({});
=> true

is.all.windowObject(window, {nope: 'nope'});
=> false

is.any.windowObject(window, {nope: 'nope'});
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.windowObject([window, {nope: 'nope'}]);
=> false

Presence checks

is.empty(value:array|object|string)

Checks if the given value is empty.

interfaces: not, all, any

is.empty({});
=> true

is.empty([]);
=> true

is.empty('');
=> true

is.not.empty(['foo']);
=> true

is.all.empty('', {}, ['foo']);
=> false

is.any.empty([], 42);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.empty([{}, 'foo']);
=> false

is.existy(value:any)

Checks if the given value is existy. (not null or undefined)

interfaces: not, all, any

is.existy({});
=> true

is.existy(null);
=> false

is.not.existy(undefined);
=> true

is.all.existy(null, ['foo']);
=> false

is.any.existy(undefined, 42);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.existy([{}, 'foo']);
=> true

is.truthy(value:any)

Checks if the given value is truthy. (existy and not false)

interfaces: not, all, any

is.truthy(true);
=> true

is.truthy(null);
=> false

is.not.truthy(false);
=> true

is.all.truthy(null, true);
=> false

is.any.truthy(undefined, true);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.truthy([{}, true]);
=> true

is.falsy(value:any)

Checks if the given value is falsy.

interfaces: not, all, any

is.falsy(false);
=> true

is.falsy(null);
=> true

is.not.falsy(true);
=> true

is.all.falsy(null, false);
=> true

is.any.falsy(undefined, true);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.falsy([false, true, undefined]);
=> false

is.space(value:any)

Checks if the given value is space.

interfaces: not, all, any

is.space(' ');
=> true

is.space('foo');
=> false

is.not.space(true);
=> true

is.all.space(' ', 'foo');
=> false

is.any.space(' ', true);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.space([' ', 'foo', undefined]);
=> false

RegExp checks

is.url(value:any)

Checks if the given value matches url regexp.

interfaces: not, all, any

is.url('http://www.test.com');
=> true

is.url('foo');
=> false

is.not.url(true);
=> true

is.all.url('http://www.test.com', 'foo');
=> false

is.any.url('http://www.test.com', true);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.url(['http://www.test.com', 'foo', undefined]);
=> false

is.email(value:any)

Checks if the given value matches email regexp.

interfaces: not, all, any

is.email('[email protected]');
=> true

is.email('foo');
=> false

is.not.email('foo');
=> true

is.all.email('[email protected]', 'foo');
=> false

is.any.email('[email protected]', 'foo');
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.email(['[email protected]', 'foo', undefined]);
=> false

is.creditCard(value:any)

Checks if the given value matches credit card regexp.

interfaces: not, all, any

is.creditCard(378282246310005);
=> true

is.creditCard(123);
=> false

is.not.creditCard(123);
=> true

is.all.creditCard(378282246310005, 123);
=> false

is.any.creditCard(378282246310005, 123);
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.creditCard([378282246310005, 123, undefined]);
=> false

is.alphaNumeric(value:any)

Checks if the given value matches alpha numeric regexp.

interfaces: not, all, any

is.alphaNumeric('alphaNu3er1k');
=> true

is.alphaNumeric('*?');
=> false

is.not.alphaNumeric('*?');
=> true

is.all.alphaNumeric('alphaNu3er1k', '*?');
=> false

is.any.alphaNumeric('alphaNu3er1k', '*?');
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.alphaNumeric(['alphaNu3er1k', '*?']);
=> false

is.timeString(value:any)

Checks if the given value matches time string regexp.

interfaces: not, all, any

is.timeString('13:45:30');
=> true

is.timeString('90:90:90');
=> false

is.not.timeString('90:90:90');
=> true

is.all.timeString('13:45:30', '90:90:90');
=> false

is.any.timeString('13:45:30', '90:90:90');
=> true

// 'all' and 'any' interfaces can also take array parameter
is.all.timeString(['13:45:30', '90

GitHub Issues· 0 开放

在 GitHub 查看全部

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言