Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

35

index.js

@@ -10,7 +10,7 @@

var object = {};
var owns = object.hasOwnProperty;
var toString = object.toString;
var objProto = Object.prototype;
var owns = objProto.hasOwnProperty;
var toString = objProto.toString;
var isActualNaN = function (value) {
return is.number(value) && value !== value;
return value !== value;
};

@@ -209,3 +209,5 @@ var NON_HOST_TYPES = {

is.arguments = function (value) {
return '[object Arguments]' === toString.call(value);
var isStandardArguments = '[object Arguments]' === toString.call(value);
var isOldArguments = !is.array(value) && is.arraylike(value) && is.object(value) && is.fn(value.callee);
return isStandardArguments || isOldArguments;
};

@@ -348,3 +350,2 @@

&& value instanceof HTMLElement
&& owns.call(value, 'nodeType')
&& value.nodeType === 1;

@@ -383,4 +384,5 @@ };

is.fn = is['function'] = function(value) {
return '[object Function]' === toString.call(value);
is.fn = is['function'] = function (value) {
var isAlert = typeof window !== 'undefined' && value === window.alert;
return isAlert || '[object Function]' === toString.call(value);
};

@@ -655,3 +657,3 @@

is.object = function (value) {
return '[object Object]' === toString.call(value);
return value && '[object Object]' === toString.call(value);
};

@@ -666,3 +668,3 @@

* @api public
* /
*/

@@ -707,14 +709,1 @@ is.hash = function (value) {

/**
* is.hash
* Test if `value` is a plain object, ie a hash.
*
* @param {Mixed} value value to test
* @return {Boolean} true if `value` is a hash, false otherwise
* @api public
*/
is.hash = function (value) {
return is.object(value) && value.constructor === Object && !value.nodeType && !value.setInterval;
};

@@ -26,3 +26,3 @@ {

"main": "index.js",
"version": "0.2.5",
"version": "0.2.6",
"scripts": {

@@ -32,7 +32,7 @@ "test": "node test/index.js"

"devDependencies": {
"tap": "~0.4.1",
"foreach": "~2.0.2"
"tape": "~1.0.1",
"foreach": "~2.0.3"
},
"testling": {
"files": "test.js",
"files": "test/index.js",
"browsers": [

@@ -39,0 +39,0 @@ "iexplore/6.0..latest",

@@ -1,5 +0,6 @@

var test = require('tap').test;
var test = require('tape');
var is = require('../index.js');
var forEach = require('foreach');
var now = Date.now || function () { return +new Date(); };

@@ -9,3 +10,3 @@ test('is.type', function (t) {

forEach(booleans, function (boolean) {
t.true(is.type(boolean, 'boolean'), '"' + boolean + '" is a boolean');
t.ok(is.type(boolean, 'boolean'), '"' + boolean + '" is a boolean');
});

@@ -15,3 +16,3 @@

forEach(numbers, function (number) {
t.true(is.type(number, 'number'), '"' + number + '" is a number');
t.ok(is.type(number, 'number'), '"' + number + '" is a number');
});

@@ -21,3 +22,3 @@

forEach(objects, function (object) {
t.true(is.type(object, 'object'), '"' + object + '" is an object');
t.ok(is.type(object, 'object'), '"' + object + '" is an object');
});

@@ -27,6 +28,6 @@

forEach(strings, function (string) {
t.true(is.type(string, 'string'), '"' + string + '" is a string');
t.ok(is.type(string, 'string'), '"' + string + '" is a string');
});
t.true(is.type(undefined, 'undefined'), 'undefined is undefined');
t.ok(is.type(undefined, 'undefined'), 'undefined is undefined');

@@ -37,5 +38,5 @@ t.end();

test('is.undefined', function (t) {
t.true(is.undefined(), 'undefined is undefined');
t.false(is.undefined(null), 'null is not undefined');
t.false(is.undefined({}), 'object is not undefined');
t.ok(is.undefined(), 'undefined is undefined');
t.notOk(is.undefined(null), 'null is not undefined');
t.notOk(is.undefined({}), 'object is not undefined');
t.end();

@@ -45,5 +46,5 @@ });

test('is.defined', function (t) {
t.false(is.defined(), 'undefined is not defined');
t.true(is.defined(null), 'null is defined');
t.true(is.defined({}), 'object is undefined');
t.notOk(is.defined(), 'undefined is not defined');
t.ok(is.defined(null), 'null is defined');
t.ok(is.defined({}), 'object is undefined');
t.end();

@@ -53,6 +54,6 @@ });

test('is.empty', function (t) {
t.true(is.empty(''), 'empty string is empty');
t.true(is.empty([]), 'empty array is empty');
t.true(is.empty({}), 'empty object is empty');
(function () { t.true(is.empty(arguments), 'empty arguments is empty'); }());
t.ok(is.empty(''), 'empty string is empty');
t.ok(is.empty([]), 'empty array is empty');
t.ok(is.empty({}), 'empty object is empty');
(function () { t.ok(is.empty(arguments), 'empty arguments is empty'); }());
t.end();

@@ -62,12 +63,12 @@ });

test('is.equal', function (t) {
t.true(is.equal([1, 2, 3], [1, 2, 3]), 'arrays are shallowly equal');
t.true(is.equal([1, 2, [3, 4]], [1, 2, [3, 4]]), 'arrays are deep equal');
t.true(is.equal({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 }), 'objects are shallowly equal');
t.true(is.equal({ a: { b: 1 } }, { a: { b: 1 } }), 'objects are deep equal');
var now = Date.now();
t.true(is.equal(new Date(now), new Date(now)), 'two equal date objects are equal');
t.ok(is.equal([1, 2, 3], [1, 2, 3]), 'arrays are shallowly equal');
t.ok(is.equal([1, 2, [3, 4]], [1, 2, [3, 4]]), 'arrays are deep equal');
t.ok(is.equal({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 }), 'objects are shallowly equal');
t.ok(is.equal({ a: { b: 1 } }, { a: { b: 1 } }), 'objects are deep equal');
var nowTS = now();
t.ok(is.equal(new Date(nowTS), new Date(nowTS)), 'two equal date objects are equal');
var F = function () {};
F.prototype = {};
t.true(is.equal(new F(), new F()), 'two object instances are equal when the prototype is the same');
t.ok(is.equal(new F(), new F()), 'two object instances are equal when the prototype is the same');
t.end();

@@ -77,11 +78,11 @@ });

test('is.hosted', function (t) {
t.true(is.hosted('a', { a: {} }), 'object is hosted');
t.true(is.hosted('a', { a: [] }), 'array is hosted');
t.true(is.hosted('a', { a: function () {} }), 'function is hosted');
t.false(is.hosted('a', { a: true }), 'boolean value is not hosted');
t.false(is.hosted('a', { a: false }), 'boolean value is not hosted');
t.false(is.hosted('a', { a: 3 }), 'number value is not hosted');
t.false(is.hosted('a', { a: undefined }), 'undefined value is not hosted');
t.false(is.hosted('a', { a: 'abc' }), 'string value is not hosted');
t.false(is.hosted('a', { a: null }), 'null value is not hosted');
t.ok(is.hosted('a', { a: {} }), 'object is hosted');
t.ok(is.hosted('a', { a: [] }), 'array is hosted');
t.ok(is.hosted('a', { a: function () {} }), 'function is hosted');
t.notOk(is.hosted('a', { a: true }), 'boolean value is not hosted');
t.notOk(is.hosted('a', { a: false }), 'boolean value is not hosted');
t.notOk(is.hosted('a', { a: 3 }), 'number value is not hosted');
t.notOk(is.hosted('a', { a: undefined }), 'undefined value is not hosted');
t.notOk(is.hosted('a', { a: 'abc' }), 'string value is not hosted');
t.notOk(is.hosted('a', { a: null }), 'null value is not hosted');
t.end();

@@ -91,5 +92,5 @@ });

test('is.instance', function (t) {
t.true(is.instance(new Date(), Date), 'new Date is instanceof Date');
t.ok(is.instance(new Date(), Date), 'new Date is instanceof Date');
var F = function () {};
t.true(is.instance(new F(), F), 'new constructor is instanceof constructor');
t.ok(is.instance(new F(), F), 'new constructor is instanceof constructor');
t.end();

@@ -100,5 +101,5 @@ });

var isNull = is['null'];
t.true(isNull(null), 'null is null');
t.false(isNull(undefined), 'undefined is not null');
t.false(isNull({}), 'object is not null');
t.ok(isNull(null), 'null is null');
t.notOk(isNull(undefined), 'undefined is not null');
t.notOk(isNull({}), 'object is not null');
t.end();

@@ -108,5 +109,5 @@ });

test('is.arguments', function (t) {
t.false(is.arguments([]), 'array is not arguments');
(function () { t.true(is.arguments(arguments), 'arguments is arguments'); }());
(function () { t.false(is.arguments(Array.prototype.slice.call(arguments)), 'sliced arguments is not arguments'); }());
t.notOk(is.arguments([]), 'array is not arguments');
(function () { t.ok(is.arguments(arguments), 'arguments is arguments'); }());
(function () { t.notOk(is.arguments(Array.prototype.slice.call(arguments)), 'sliced arguments is not arguments'); }());
t.end();

@@ -116,4 +117,4 @@ });

test('is.array', function (t) {
t.true(is.array([]), 'array is array');
(function () { t.true(is.array(Array.prototype.slice.call(arguments)), 'sliced arguments is array'); }());
t.ok(is.array([]), 'array is array');
(function () { t.ok(is.array(Array.prototype.slice.call(arguments)), 'sliced arguments is array'); }());
t.end();

@@ -123,5 +124,5 @@ });

test('is.array.empty', function (t) {
t.true(is.array.empty([]), 'empty array is empty array');
(function () { t.false(is.array.empty(arguments), 'empty arguments is not empty array'); }());
(function () { t.true(is.array.empty(Array.prototype.slice.call(arguments)), 'empty sliced arguments is empty array'); }());
t.ok(is.array.empty([]), 'empty array is empty array');
(function () { t.notOk(is.array.empty(arguments), 'empty arguments is not empty array'); }());
(function () { t.ok(is.array.empty(Array.prototype.slice.call(arguments)), 'empty sliced arguments is empty array'); }());
t.end();

@@ -131,5 +132,5 @@ });

test('is.arguments.empty', function (t) {
t.false(is.arguments.empty([]), 'empty array is not empty arguments');
(function () { t.true(is.arguments.empty(arguments), 'empty arguments is empty arguments'); }());
(function () { t.false(is.arguments.empty(Array.prototype.slice.call(arguments)), 'empty sliced arguments is not empty arguments'); }());
t.notOk(is.arguments.empty([]), 'empty array is not empty arguments');
(function () { t.ok(is.arguments.empty(arguments), 'empty arguments is empty arguments'); }());
(function () { t.notOk(is.arguments.empty(Array.prototype.slice.call(arguments)), 'empty sliced arguments is not empty arguments'); }());
t.end();

@@ -139,15 +140,15 @@ });

test('is.isarraylike', function (t) {
t.false(is.arraylike(), 'undefined is not array-like');
t.false(is.arraylike(null), 'null is not array-like');
t.false(is.arraylike(false), 'false is not array-like');
t.false(is.arraylike(true), 'true is not array-like');
t.true(is.arraylike({ length: 0 }), 'object with zero length is array-like');
t.true(is.arraylike({ length: 1 }), 'object with positive length is array-like');
t.false(is.arraylike({ length: -1 }), 'object with negative length is not array-like');
t.false(is.arraylike({ length: NaN }), 'object with NaN length is not array-like');
t.false(is.arraylike({ length: 'foo' }), 'object with string length is not array-like');
t.false(is.arraylike({ length: '' }), 'object with empty string length is not array-like');
t.true(is.arraylike([]), 'array is array-like');
(function () { t.true(is.arraylike(arguments), 'empty arguments is array-like'); }());
(function () { t.true(is.arraylike(arguments), 'nonempty arguments is array-like'); }(1, 2, 3));
t.notOk(is.arraylike(), 'undefined is not array-like');
t.notOk(is.arraylike(null), 'null is not array-like');
t.notOk(is.arraylike(false), 'false is not array-like');
t.notOk(is.arraylike(true), 'true is not array-like');
t.ok(is.arraylike({ length: 0 }), 'object with zero length is array-like');
t.ok(is.arraylike({ length: 1 }), 'object with positive length is array-like');
t.notOk(is.arraylike({ length: -1 }), 'object with negative length is not array-like');
t.notOk(is.arraylike({ length: NaN }), 'object with NaN length is not array-like');
t.notOk(is.arraylike({ length: 'foo' }), 'object with string length is not array-like');
t.notOk(is.arraylike({ length: '' }), 'object with empty string length is not array-like');
t.ok(is.arraylike([]), 'array is array-like');
(function () { t.ok(is.arraylike(arguments), 'empty arguments is array-like'); }());
(function () { t.ok(is.arraylike(arguments), 'nonempty arguments is array-like'); }(1, 2, 3));
t.end();

@@ -157,8 +158,8 @@ });

test('is.boolean', function (t) {
t.true(is.boolean(true), 'literal true is a boolean');
t.true(is.boolean(false), 'literal false is a boolean');
t.true(is.boolean(new Boolean(true)), 'object true is a boolean');
t.true(is.boolean(new Boolean(false)), 'object false is a boolean');
t.false(is.boolean(), 'undefined is not a boolean');
t.false(is.boolean(null), 'null is not a boolean');
t.ok(is.boolean(true), 'literal true is a boolean');
t.ok(is.boolean(false), 'literal false is a boolean');
t.ok(is.boolean(new Boolean(true)), 'object true is a boolean');
t.ok(is.boolean(new Boolean(false)), 'object false is a boolean');
t.notOk(is.boolean(), 'undefined is not a boolean');
t.notOk(is.boolean(null), 'null is not a boolean');
t.end();

@@ -169,8 +170,8 @@ });

var isFalse = is['false'];
t.true(isFalse(false), 'false is false');
t.true(isFalse(new Boolean(false)), 'object false is false');
t.false(isFalse(true), 'true is not false');
t.false(isFalse(), 'undefined is not false');
t.false(isFalse(null), 'null is not false');
t.false(isFalse(''), 'empty string is not false');
t.ok(isFalse(false), 'false is false');
t.ok(isFalse(new Boolean(false)), 'object false is false');
t.notOk(isFalse(true), 'true is not false');
t.notOk(isFalse(), 'undefined is not false');
t.notOk(isFalse(null), 'null is not false');
t.notOk(isFalse(''), 'empty string is not false');
t.end();

@@ -181,8 +182,8 @@ });

var isTrue = is['true'];
t.true(isTrue(true), 'true is true');
t.true(isTrue(new Boolean(true)), 'object true is true');
t.false(isTrue(false), 'false is not true');
t.false(isTrue(), 'undefined is not true');
t.false(isTrue(null), 'null is not true');
t.false(isTrue(''), 'empty string is not true');
t.ok(isTrue(true), 'true is true');
t.ok(isTrue(new Boolean(true)), 'object true is true');
t.notOk(isTrue(false), 'false is not true');
t.notOk(isTrue(), 'undefined is not true');
t.notOk(isTrue(null), 'null is not true');
t.notOk(isTrue(''), 'empty string is not true');
t.end();

@@ -192,10 +193,10 @@ });

test('is.date', function (t) {
t.true(is.date(new Date()), 'new Date is date');
t.false(is.date(), 'undefined is not date');
t.false(is.date(null), 'null is not date');
t.false(is.date(''), 'empty string is not date');
t.false(is.date(Date.now()), 'timestamp is not date');
t.ok(is.date(new Date()), 'new Date is date');
t.notOk(is.date(), 'undefined is not date');
t.notOk(is.date(null), 'null is not date');
t.notOk(is.date(''), 'empty string is not date');
t.notOk(is.date(now()), 'timestamp is not date');
var F = function () {};
F.prototype = new Date();
t.false(is.date(new F()), 'Date subtype is not date');
t.notOk(is.date(new F()), 'Date subtype is not date');
t.end();

@@ -207,6 +208,6 @@ });

var element = document.createElement('div');
t.true(is.element(element), 'HTMLElement is element');
t.false(is.element({ nodeType: 1 }), 'object with nodeType is not element');
t.ok(is.element(element), 'HTMLElement is element');
t.notOk(is.element({ nodeType: 1 }), 'object with nodeType is not element');
} else {
t.true(true, 'Skipping is.element test in a non-browser environment');
t.ok(true, 'Skipping is.element test in a non-browser environment');
}

@@ -218,5 +219,5 @@ t.end();

var err = new Error('foo');
t.true(is.error(err), 'Error is error');
t.false(is.error({}), 'object is not error');
t.false(is.error({ toString: function () { return '[object Error]'; } }), 'object with error\'s toString is not error');
t.ok(is.error(err), 'Error is error');
t.notOk(is.error({}), 'object is not error');
t.notOk(is.error({ toString: function () { return '[object Error]'; } }), 'object with error\'s toString is not error');
t.end();

@@ -227,10 +228,10 @@ });

t.equal(is['function'], is.fn, 'alias works');
t.true(is.fn(function () {}), 'function is function');
t.true(is.fn(console.log), 'console.log is function');
t.ok(is.fn(function () {}), 'function is function');
t.ok(is.fn(console.log), 'console.log is function');
if (typeof window !== 'undefined') {
// in IE7/8, typeof alert === 'object'
t.true(is.fn(window.alert), 'window.alert is function');
t.ok(is.fn(window.alert), 'window.alert is function');
}
t.false(is.fn({}), 'object is not function');
t.false(is.fn(null), 'null is not function');
t.notOk(is.fn({}), 'object is not function');
t.notOk(is.fn(null), 'null is not function');
t.end();

@@ -240,12 +241,12 @@ });

test('is.number', function (t) {
t.true(is.number(0), 'positive zero is number');
t.true(is.number(0 / -1), 'negative zero is number');
t.true(is.number(3), 'three is number');
t.true(is.number(NaN), 'NaN is number');
t.true(is.number(Infinity), 'infinity is number');
t.true(is.number(-Infinity), 'negative infinity is number');
t.true(is.number(new Number(42)), 'object number is number');
t.false(is.number(), 'undefined is not number');
t.false(is.number(null), 'null is not number');
t.false(is.number(true), 'true is not number');
t.ok(is.number(0), 'positive zero is number');
t.ok(is.number(0 / -1), 'negative zero is number');
t.ok(is.number(3), 'three is number');
t.ok(is.number(NaN), 'NaN is number');
t.ok(is.number(Infinity), 'infinity is number');
t.ok(is.number(-Infinity), 'negative infinity is number');
t.ok(is.number(new Number(42)), 'object number is number');
t.notOk(is.number(), 'undefined is not number');
t.notOk(is.number(null), 'null is not number');
t.notOk(is.number(true), 'true is not number');
t.end();

@@ -255,6 +256,6 @@ });

test('is.infinite', function (t) {
t.true(is.infinite(Infinity), 'positive infinity is infinite');
t.true(is.infinite(-Infinity), 'negative infinity is infinite');
t.false(is.infinite(NaN), 'NaN is not infinite');
t.false(is.infinite(0), 'a number is not infinite');
t.ok(is.infinite(Infinity), 'positive infinity is infinite');
t.ok(is.infinite(-Infinity), 'negative infinity is infinite');
t.notOk(is.infinite(NaN), 'NaN is not infinite');
t.notOk(is.infinite(0), 'a number is not infinite');
t.end();

@@ -264,6 +265,6 @@ });

test('is.decimal', function (t) {
t.true(is.decimal(1.1), 'decimal is decimal');
t.false(is.decimal(0), 'zero is not decimal');
t.false(is.decimal(1), 'integer is not decimal');
t.false(is.decimal(NaN), 'NaN is not decimal');
t.ok(is.decimal(1.1), 'decimal is decimal');
t.notOk(is.decimal(0), 'zero is not decimal');
t.notOk(is.decimal(1), 'integer is not decimal');
t.notOk(is.decimal(NaN), 'NaN is not decimal');
t.end();

@@ -273,13 +274,13 @@ });

test('is.divisibleBy', function (t) {
t.true(is.divisibleBy(4, 2), '4 is divisible by 2');
t.true(is.divisibleBy(4, 2), '4 is divisible by 2');
t.true(is.divisibleBy(0, 1), '0 is divisible by 1');
t.true(is.divisibleBy(Infinity, 1), 'infinity is divisible by anything');
t.true(is.divisibleBy(1, Infinity), 'anything is divisible by infinity');
t.true(is.divisibleBy(Infinity, Infinity), 'infinity is divisible by infinity');
t.false(is.divisibleBy(1, 0), '1 is not divisible by 0');
t.false(is.divisibleBy(NaN, 1), 'NaN is not divisible by 1');
t.false(is.divisibleBy(1, NaN), '1 is not divisible by NaN');
t.false(is.divisibleBy(NaN, NaN), 'NaN is not divisible by NaN');
t.false(is.divisibleBy(1, 3), '1 is not divisible by 3');
t.ok(is.divisibleBy(4, 2), '4 is divisible by 2');
t.ok(is.divisibleBy(4, 2), '4 is divisible by 2');
t.ok(is.divisibleBy(0, 1), '0 is divisible by 1');
t.ok(is.divisibleBy(Infinity, 1), 'infinity is divisible by anything');
t.ok(is.divisibleBy(1, Infinity), 'anything is divisible by infinity');
t.ok(is.divisibleBy(Infinity, Infinity), 'infinity is divisible by infinity');
t.notOk(is.divisibleBy(1, 0), '1 is not divisible by 0');
t.notOk(is.divisibleBy(NaN, 1), 'NaN is not divisible by 1');
t.notOk(is.divisibleBy(1, NaN), '1 is not divisible by NaN');
t.notOk(is.divisibleBy(NaN, NaN), 'NaN is not divisible by NaN');
t.notOk(is.divisibleBy(1, 3), '1 is not divisible by 3');
t.end();

@@ -289,9 +290,9 @@ });

test('is.int', function (t) {
t.true(is.int(0), '0 is integer');
t.true(is.int(3), '3 is integer');
t.false(is.int(1.1), '1.1 is not integer');
t.false(is.int(NaN), 'NaN is not integer');
t.false(is.int(Infinity), 'infinity is not integer');
t.false(is.int(null), 'null is not integer');
t.false(is.int(), 'undefined is not integer');
t.ok(is.int(0), '0 is integer');
t.ok(is.int(3), '3 is integer');
t.notOk(is.int(1.1), '1.1 is not integer');
t.notOk(is.int(NaN), 'NaN is not integer');
t.notOk(is.int(Infinity), 'infinity is not integer');
t.notOk(is.int(null), 'null is not integer');
t.notOk(is.int(), 'undefined is not integer');
t.end();

@@ -301,7 +302,7 @@ });

test('is.maximum', function (t) {
t.true(is.maximum(3, [3, 2, 1]), '3 is maximum of [3,2,1]');
t.true(is.maximum(3, [1, 2, 3]), '3 is maximum of [1,2,3]');
t.true(is.maximum(4, [1, 2, 3]), '4 is maximum of [1,2,3]');
t.true(is.maximum('c', ['a', 'b', 'c']), 'c is maximum of [a,b,c]');
t.false(is.maximum(2, [1, 2, 3]), '2 is not maximum of [1,2,3]');
t.ok(is.maximum(3, [3, 2, 1]), '3 is maximum of [3,2,1]');
t.ok(is.maximum(3, [1, 2, 3]), '3 is maximum of [1,2,3]');
t.ok(is.maximum(4, [1, 2, 3]), '4 is maximum of [1,2,3]');
t.ok(is.maximum('c', ['a', 'b', 'c']), 'c is maximum of [a,b,c]');
t.notOk(is.maximum(2, [1, 2, 3]), '2 is not maximum of [1,2,3]');
var error = new TypeError('second argument must be array-like');

@@ -314,6 +315,6 @@ t.throws(function () { return is.maximum(2, null); }, error, 'throws when second value is not array-like');

test('is.minimum', function (t) {
t.true(is.minimum(1, [1, 2, 3]), '1 is minimum of [1,2,3]');
t.true(is.minimum(0, [1, 2, 3]), '0 is minimum of [1,2,3]');
t.true(is.minimum('a', ['a', 'b', 'c']), 'a is minimum of [a,b,c]');
t.false(is.minimum(2, [1, 2, 3]), '2 is not minimum of [1,2,3]');
t.ok(is.minimum(1, [1, 2, 3]), '1 is minimum of [1,2,3]');
t.ok(is.minimum(0, [1, 2, 3]), '0 is minimum of [1,2,3]');
t.ok(is.minimum('a', ['a', 'b', 'c']), 'a is minimum of [a,b,c]');
t.notOk(is.minimum(2, [1, 2, 3]), '2 is not minimum of [1,2,3]');
var error = new TypeError('second argument must be array-like');

@@ -326,12 +327,12 @@ t.throws(function () { return is.minimum(2, null); }, error, 'throws when second value is not array-like');

test('is.nan', function (t) {
t.true(is.nan(NaN), 'NaN is not a number');
t.true(is.nan('abc'), 'string is not a number');
t.true(is.nan(true), 'boolean is not a number');
t.true(is.nan({}), 'object is not a number');
t.true(is.nan([]), 'array is not a number');
t.true(is.nan(function () {}), 'function is not a number');
t.false(is.nan(0), 'zero is a number');
t.false(is.nan(3), 'three is a number');
t.false(is.nan(1.1), '1.1 is a number');
t.false(is.nan(Infinity), 'infinity is a number');
t.ok(is.nan(NaN), 'NaN is not a number');
t.ok(is.nan('abc'), 'string is not a number');
t.ok(is.nan(true), 'boolean is not a number');
t.ok(is.nan({}), 'object is not a number');
t.ok(is.nan([]), 'array is not a number');
t.ok(is.nan(function () {}), 'function is not a number');
t.notOk(is.nan(0), 'zero is a number');
t.notOk(is.nan(3), 'three is a number');
t.notOk(is.nan(1.1), '1.1 is a number');
t.notOk(is.nan(Infinity), 'infinity is a number');
t.end();

@@ -341,9 +342,9 @@ });

test('is.even', function (t) {
t.true(is.even(0), 'zero is even');
t.true(is.even(2), 'two is even');
t.true(is.even(Infinity), 'infinity is even');
t.false(is.even(1), '1 is not even');
t.false(is.even(), 'undefined is not even');
t.false(is.even(null), 'null is not even');
t.false(is.even(NaN), 'NaN is not even');
t.ok(is.even(0), 'zero is even');
t.ok(is.even(2), 'two is even');
t.ok(is.even(Infinity), 'infinity is even');
t.notOk(is.even(1), '1 is not even');
t.notOk(is.even(), 'undefined is not even');
t.notOk(is.even(null), 'null is not even');
t.notOk(is.even(NaN), 'NaN is not even');
t.end();

@@ -353,10 +354,10 @@ });

test('is.odd', function (t) {
t.true(is.odd(1), 'zero is odd');
t.true(is.odd(3), 'two is odd');
t.true(is.odd(Infinity), 'infinity is odd');
t.false(is.odd(0), '0 is not odd');
t.false(is.odd(2), '2 is not odd');
t.false(is.odd(), 'undefined is not odd');
t.false(is.odd(null), 'null is not odd');
t.false(is.odd(NaN), 'NaN is not odd');
t.ok(is.odd(1), 'zero is odd');
t.ok(is.odd(3), 'two is odd');
t.ok(is.odd(Infinity), 'infinity is odd');
t.notOk(is.odd(0), '0 is not odd');
t.notOk(is.odd(2), '2 is not odd');
t.notOk(is.odd(), 'undefined is not odd');
t.notOk(is.odd(null), 'null is not odd');
t.notOk(is.odd(NaN), 'NaN is not odd');
t.end();

@@ -366,10 +367,10 @@ });

test('is.ge', function (t) {
t.true(is.ge(3, 2), '3 is greater than 2');
t.false(is.ge(2, 3), '2 is not greater than 3');
t.true(is.ge(3, 3), '3 is greater than or equal to 3');
t.true(is.ge('abc', 'a'), 'abc is greater than a');
t.true(is.ge('abc', 'abc'), 'abc is greater than or equal to abc');
t.false(is.ge('a', 'abc'), 'a is not greater than abc');
t.false(is.ge(Infinity, 0), 'infinity is not greater than anything');
t.false(is.ge(0, Infinity), 'anything is not greater than infinity');
t.ok(is.ge(3, 2), '3 is greater than 2');
t.notOk(is.ge(2, 3), '2 is not greater than 3');
t.ok(is.ge(3, 3), '3 is greater than or equal to 3');
t.ok(is.ge('abc', 'a'), 'abc is greater than a');
t.ok(is.ge('abc', 'abc'), 'abc is greater than or equal to abc');
t.notOk(is.ge('a', 'abc'), 'a is not greater than abc');
t.notOk(is.ge(Infinity, 0), 'infinity is not greater than anything');
t.notOk(is.ge(0, Infinity), 'anything is not greater than infinity');
var error = new TypeError('NaN is not a valid value');

@@ -382,10 +383,10 @@ t.throws(function () { return is.ge(NaN, 2); }, error, 'throws when first value is NaN');

test('is.gt', function (t) {
t.true(is.gt(3, 2), '3 is greater than 2');
t.false(is.gt(2, 3), '2 is not greater than 3');
t.false(is.gt(3, 3), '3 is not greater than 3');
t.true(is.gt('abc', 'a'), 'abc is greater than a');
t.false(is.gt('abc', 'abc'), 'abc is not greater than abc');
t.false(is.gt('a', 'abc'), 'a is not greater than abc');
t.false(is.gt(Infinity, 0), 'infinity is not greater than anything');
t.false(is.gt(0, Infinity), 'anything is not greater than infinity');
t.ok(is.gt(3, 2), '3 is greater than 2');
t.notOk(is.gt(2, 3), '2 is not greater than 3');
t.notOk(is.gt(3, 3), '3 is not greater than 3');
t.ok(is.gt('abc', 'a'), 'abc is greater than a');
t.notOk(is.gt('abc', 'abc'), 'abc is not greater than abc');
t.notOk(is.gt('a', 'abc'), 'a is not greater than abc');
t.notOk(is.gt(Infinity, 0), 'infinity is not greater than anything');
t.notOk(is.gt(0, Infinity), 'anything is not greater than infinity');
var error = new TypeError('NaN is not a valid value');

@@ -398,10 +399,10 @@ t.throws(function () { return is.gt(NaN, 2); }, error, 'throws when first value is NaN');

test('is.le', function (t) {
t.true(is.le(2, 3), '2 is lesser than or equal to 3');
t.false(is.le(3, 2), '3 is not lesser than or equal to 2');
t.true(is.le(3, 3), '3 is lesser than or equal to 3');
t.true(is.le('a', 'abc'), 'a is lesser than or equal to abc');
t.true(is.le('abc', 'abc'), 'abc is lesser than or equal to abc');
t.false(is.le('abc', 'a'), 'abc is not lesser than or equal to a');
t.false(is.le(Infinity, 0), 'infinity is not lesser than or equal to anything');
t.false(is.le(0, Infinity), 'anything is not lesser than or equal to infinity');
t.ok(is.le(2, 3), '2 is lesser than or equal to 3');
t.notOk(is.le(3, 2), '3 is not lesser than or equal to 2');
t.ok(is.le(3, 3), '3 is lesser than or equal to 3');
t.ok(is.le('a', 'abc'), 'a is lesser than or equal to abc');
t.ok(is.le('abc', 'abc'), 'abc is lesser than or equal to abc');
t.notOk(is.le('abc', 'a'), 'abc is not lesser than or equal to a');
t.notOk(is.le(Infinity, 0), 'infinity is not lesser than or equal to anything');
t.notOk(is.le(0, Infinity), 'anything is not lesser than or equal to infinity');
var error = new TypeError('NaN is not a valid value');

@@ -414,10 +415,10 @@ t.throws(function () { return is.le(NaN, 2); }, error, 'throws when first value is NaN');

test('is.lt', function (t) {
t.true(is.lt(2, 3), '2 is lesser than 3');
t.false(is.lt(3, 2), '3 is not lesser than 2');
t.false(is.lt(3, 3), '3 is not lesser than 3');
t.true(is.lt('a', 'abc'), 'a is lesser than abc');
t.false(is.lt('abc', 'abc'), 'abc is not lesser than abc');
t.false(is.lt('abc', 'a'), 'abc is not lesser than a');
t.false(is.lt(Infinity, 0), 'infinity is not lesser than anything');
t.false(is.lt(0, Infinity), 'anything is not lesser than infinity');
t.ok(is.lt(2, 3), '2 is lesser than 3');
t.notOk(is.lt(3, 2), '3 is not lesser than 2');
t.notOk(is.lt(3, 3), '3 is not lesser than 3');
t.ok(is.lt('a', 'abc'), 'a is lesser than abc');
t.notOk(is.lt('abc', 'abc'), 'abc is not lesser than abc');
t.notOk(is.lt('abc', 'a'), 'abc is not lesser than a');
t.notOk(is.lt(Infinity, 0), 'infinity is not lesser than anything');
t.notOk(is.lt(0, Infinity), 'anything is not lesser than infinity');
var error = new TypeError('NaN is not a valid value');

@@ -430,29 +431,27 @@ t.throws(function () { return is.lt(NaN, 2); }, error, 'throws when first value is NaN');

test('is.within', function (t) {
t.test('argument checking', function (st) {
var nanError = new TypeError('NaN is not a valid value');
st.throws(function () { return is.within(NaN, 0, 0); }, nanError, 'throws when first value is NaN');
st.throws(function () { return is.within(0, NaN, 0); }, nanError, 'throws when second value is NaN');
st.throws(function () { return is.within(0, 0, NaN); }, nanError, 'throws when third value is NaN');
var nanError = new TypeError('NaN is not a valid value');
t.throws(function () { return is.within(NaN, 0, 0); }, nanError, 'throws when first value is NaN');
t.throws(function () { return is.within(0, NaN, 0); }, nanError, 'throws when second value is NaN');
t.throws(function () { return is.within(0, 0, NaN); }, nanError, 'throws when third value is NaN');
var error = new TypeError('all arguments must be numbers');
st.throws(function () { return is.within('', 0, 0); }, error, 'throws when first value is string');
st.throws(function () { return is.within(0, '', 0); }, error, 'throws when second value is string');
st.throws(function () { return is.within(0, 0, ''); }, error, 'throws when third value is string');
st.throws(function () { return is.within({}, 0, 0); }, error, 'throws when first value is object');
st.throws(function () { return is.within(0, {}, 0); }, error, 'throws when second value is object');
st.throws(function () { return is.within(0, 0, {}); }, error, 'throws when third value is object');
st.throws(function () { return is.within(null, 0, 0); }, error, 'throws when first value is null');
st.throws(function () { return is.within(0, null, 0); }, error, 'throws when second value is null');
st.throws(function () { return is.within(0, 0, null); }, error, 'throws when third value is null');
st.throws(function () { return is.within(undefined, 0, 0); }, error, 'throws when first value is undefined');
st.throws(function () { return is.within(0, undefined, 0); }, error, 'throws when second value is undefined');
st.throws(function () { return is.within(0, 0, undefined); }, error, 'throws when third value is undefined');
st.end();
});
t.true(is.within(2, 1, 3), '2 is between 1 and 3');
t.true(is.within(0, -1, 1), '0 is between -1 and 1');
t.true(is.within(2, 0, Infinity), 'infinity always returns true');
t.true(is.within(2, Infinity, 2), 'infinity always returns true');
t.true(is.within(Infinity, 0, 1), 'infinity always returns true');
t.false(is.within(2, -1, -1), '2 is not between -1 and 1');
var error = new TypeError('all arguments must be numbers');
t.throws(function () { return is.within('', 0, 0); }, error, 'throws when first value is string');
t.throws(function () { return is.within(0, '', 0); }, error, 'throws when second value is string');
t.throws(function () { return is.within(0, 0, ''); }, error, 'throws when third value is string');
t.throws(function () { return is.within({}, 0, 0); }, error, 'throws when first value is object');
t.throws(function () { return is.within(0, {}, 0); }, error, 'throws when second value is object');
t.throws(function () { return is.within(0, 0, {}); }, error, 'throws when third value is object');
t.throws(function () { return is.within(null, 0, 0); }, error, 'throws when first value is null');
t.throws(function () { return is.within(0, null, 0); }, error, 'throws when second value is null');
t.throws(function () { return is.within(0, 0, null); }, error, 'throws when third value is null');
t.throws(function () { return is.within(undefined, 0, 0); }, error, 'throws when first value is undefined');
t.throws(function () { return is.within(0, undefined, 0); }, error, 'throws when second value is undefined');
t.throws(function () { return is.within(0, 0, undefined); }, error, 'throws when third value is undefined');
t.ok(is.within(2, 1, 3), '2 is between 1 and 3');
t.ok(is.within(0, -1, 1), '0 is between -1 and 1');
t.ok(is.within(2, 0, Infinity), 'infinity always returns true');
t.ok(is.within(2, Infinity, 2), 'infinity always returns true');
t.ok(is.within(Infinity, 0, 1), 'infinity always returns true');
t.notOk(is.within(2, -1, -1), '2 is not between -1 and 1');
t.end();

@@ -462,10 +461,10 @@ });

test('is.object', function (t) {
t.true(is.object({}), 'object literal is object');
t.false(is.object(), 'undefined is not an object');
t.false(is.object(null), 'null is not an object');
t.false(is.object(true), 'true is not an object');
t.false(is.object(''), 'string is not an object');
t.false(is.object(NaN), 'NaN is not an object');
t.false(is.object(Object), 'object constructor is not an object');
t.false(is.object(function () {}), 'function is not an object');
t.ok(is.object({}), 'object literal is object');
t.notOk(is.object(), 'undefined is not an object');
t.notOk(is.object(null), 'null is not an object');
t.notOk(is.object(true), 'true is not an object');
t.notOk(is.object(''), 'string is not an object');
t.notOk(is.object(NaN), 'NaN is not an object');
t.notOk(is.object(Object), 'object constructor is not an object');
t.notOk(is.object(function () {}), 'function is not an object');
t.end();

@@ -475,16 +474,25 @@ });

test('is.hash', function (t) {
t.true(is.hash({}), 'empty object literal is hash');
t.true(is.hash({1: 2, a: "b"}), 'object literal with props is hash');
t.false(is.hash(), 'undefined is not hash');
t.false(is.hash(new Date()), 'date is not hash');
t.false(is.hash(new String()), 'string obj is not hash');
t.false(is.hash(new Number()), 'number obj is not hash');
t.false(is.hash(new Boolean()), 'boolean obj is not hash');
t.false(is.hash(''), 'string literal is not hash');
t.false(is.hash(false), 'literal false is not hash');
t.false(is.hash(true), 'literal true is not hash');
t.false(is.hash(1), 'literal number is not hash');
t.ok(is.hash({}), 'empty object literal is hash');
t.ok(is.hash({ 1: 2, a: "b" }), 'object literal is hash');
t.notOk(is.hash(), 'undefined is not a hash');
t.notOk(is.hash(null), 'null is not a hash');
t.notOk(is.hash(new Date()), 'date is not a hash');
t.notOk(is.hash(new String()), 'string object is not a hash');
t.notOk(is.hash(''), 'string literal is not a hash');
t.notOk(is.hash(new Number()), 'number object is not a hash');
t.notOk(is.hash(1), 'number literal is not a hash');
t.notOk(is.hash(true), 'true is not a hash');
t.notOk(is.hash(false), 'false is not a hash');
t.notOk(is.hash(new Boolean()), 'boolean obj is not hash');
t.notOk(is.hash(false), 'literal false is not hash');
t.notOk(is.hash(true), 'literal true is not hash');
if (typeof module !== 'undefined') {
t.ok(is.hash(module.exports), 'module.exports is a hash');
}
if (typeof window !== 'undefined') {
t.false(is.hash(window), 'window is not hash');
t.false(is.hash(document.createElement('div')), 'div is not hash');
t.notOk(is.hash(window), 'window is not a hash');
t.notOk(is.hash(document.createElement('div')), 'element is not a hash');
} else if (typeof process !== 'undefined') {
t.notOk(is.hash(global), 'global is not a hash');
t.notOk(is.hash(process), 'process is not a hash');
}

@@ -495,7 +503,7 @@ t.end();

test('is.regexp', function (t) {
t.true(is.regexp(/a/g), 'regex literal is regex');
t.true(is.regexp(new RegExp('a', 'g')), 'regex object is regex');
t.false(is.regexp(), 'undefined is not regex');
t.false(is.regexp(function () {}), 'function is not regex');
t.false(is.regexp('/a/g'), 'string regex is not regex');
t.ok(is.regexp(/a/g), 'regex literal is regex');
t.ok(is.regexp(new RegExp('a', 'g')), 'regex object is regex');
t.notOk(is.regexp(), 'undefined is not regex');
t.notOk(is.regexp(function () {}), 'function is not regex');
t.notOk(is.regexp('/a/g'), 'string regex is not regex');
t.end();

@@ -505,36 +513,11 @@ });

test('is.string', function (t) {
t.true(is.string('foo'), 'string literal is string');
t.true(is.string(new String('foo')), 'string literal is string');
t.false(is.string(), 'undefined is not string');
t.false(is.string(String), 'string constructor is not string');
t.ok(is.string('foo'), 'string literal is string');
t.ok(is.string(new String('foo')), 'string literal is string');
t.notOk(is.string(), 'undefined is not string');
t.notOk(is.string(String), 'string constructor is not string');
var F = function () {};
F.prototype = new String();
t.false(is.string(F), 'string subtype is not string');
t.notOk(is.string(F), 'string subtype is not string');
t.end();
});
test('is.hash', function (t) {
t.true(is.hash({}), 'empty object literal is hash');
t.true(is.hash({ 1: 2, a: "b" }), 'object literal is hash');
t.false(is.hash(), 'undefined is not a hash');
t.false(is.hash(null), 'null is not a hash');
t.false(is.hash(new Date()), 'date is not a hash');
t.false(is.hash(new String()), 'string object is not a hash');
t.false(is.hash(''), 'string literal is not a hash');
t.false(is.hash(new Number()), 'number object is not a hash');
t.false(is.hash(1), 'number literal is not a hash');
t.false(is.hash(true), 'true is not a hash');
t.false(is.hash(false), 'false is not a hash');
if (typeof module !== 'undefined') {
t.true(is.hash(module.exports), 'module.exports is a hash');
}
if (typeof window !== 'undefined') {
t.false(is.hash(window), 'window is not a hash');
t.false(is.hash(document.createElement('div')), 'element is not a hash');
} else if (typeof process !== 'undefined') {
t.false(is.hash(global), 'global is not a hash');
t.false(is.hash(process), 'process is not a hash');
}
t.end();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc