Skip to content

Instantly share code, notes, and snippets.

@lorenzoongithub
Last active August 29, 2015 14:17
Show Gist options
  • Save lorenzoongithub/8921e746065297ae5dbe to your computer and use it in GitHub Desktop.
Save lorenzoongithub/8921e746065297ae5dbe to your computer and use it in GitHub Desktop.
// first cut.
// see: http://arasatasaygin.github.io/is.js/
//
load('http://arasatasaygin.github.io/is.js/scripts/is.js');
var getArguments = function() {
return arguments;
};
var arguments = getArguments();
x = is.arguments(arguments);
if (x==false) throw '';
x = is.not.arguments({foo: 'bar'});
if (x==false) throw '';
x = is.all.arguments(arguments, 'bar');
if (x) throw '';
x = is.any.arguments(['foo'], arguments);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.arguments([arguments, 'foo', 'bar']);
if (x) throw '';
// Checks if the given value type is array.
x = is.array(['foo', 'bar', 'baz']);
if (x==false) throw '';
x = is.not.array({foo: 'bar'});
if (x==false) throw '';
x = is.all.array(['foo'], 'bar');
if (x) throw '';
x = is.any.array(['foo'], 'bar');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.array([[1, 2], 'foo', 'bar']);
if (x) throw '';
// Checks if the given value type is boolean.
x = is.boolean(true);
if (x==false) throw '';
x = is.not.boolean({foo: 'bar'});
if (x==false) throw '';
x = is.all.boolean(true, 'bar');
if (x) throw '';
x = is.any.boolean(true, 'bar');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.boolean([true, 'foo', 'bar']);
if (x) throw '';
// Checks if the given value type is date.
x = is.date(new Date());
if (x==false) throw '';
x = is.not.date({foo: 'bar'});
if (x==false) throw '';
x = is.all.date(new Date(), 'bar');
if (x) throw '';
x = is.any.date(new Date(), 'bar');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.date([new Date(), 'foo', 'bar']);
if (x) throw '';
// Checks if the given value type is error.
x = is.error(new Error());
if (x==false) throw '';
x = is.not.error({foo: 'bar'});
if (x==false) throw '';
x = is.all.error(new Error(), 'bar');
if (x) throw '';
x = is.any.error(new Error(), 'bar');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.error([new Error(), 'foo', 'bar']);
if (x) throw '';
// Checks if the given value type is function.
x = is.function(toString);
if (x==false) throw '';
x = is.not.function({foo: 'bar'});
if (x==false) throw '';
x = is.all.function(toString, 'bar');
if (x) throw '';
x = is.any.function(toString, 'bar');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.function([toString, 'foo', 'bar']);
if (x) throw '';
// Checks if the given value type is NaN.
x = is.nan(NaN);
if (x==false) throw '';
x = is.not.nan(42);
if (x==false) throw '';
x = is.all.nan(NaN, 1);
if (x) throw '';
x = is.any.nan(NaN, 2);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.nan([NaN, 'foo', 1]);
if (x) throw '';
// Checks if the given value type is null.
x = is.null(null);
if (x==false) throw '';
x = is.not.null(42);
if (x==false) throw '';
x = is.all.null(null, 1);
if (x) throw '';
x = is.any.null(null, 2);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.null([null, 'foo', 1]);
if (x) throw '';
// Checks if the given value type is number.
x = is.number(42);
if (x==false) throw '';
x = is.number(NaN);
if (x) throw '';
x = is.not.number('42');
if (x==false) throw '';
x = is.all.number('foo', 1);
if (x) throw '';
x = is.any.number({}, 2);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.number([42, 'foo', 1]);
if (x) throw '';
// Checks if the given value type is object.
x = is.object({foo: 'bar'});
if (x==false) throw '';
// functions are also returnin as true
x = is.object(toString);
if (x==false) throw '';
x = is.not.object('foo');
if (x==false) throw '';
x = is.all.object({}, 1);
if (x) throw '';
x = is.any.object({}, 2);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.object([{}, new Object()]);
if (x==false) throw '';
// Checks if the given value type is pure json object.
x = is.json({foo: 'bar'});
if (x==false) throw '';
// functions are returning as false
x = is.json(toString);
if (x) throw '';
x = is.not.json([]);
if (x==false) throw '';
x = is.all.json({}, 1);
if (x) throw '';
x = is.any.json({}, 2);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.json([{}, {foo: 'bar'}]);
if (x==false) throw '';
// Checks if the given value type is RegExp.
x = is.regexp(/test/);
if (x==false) throw '';
x = is.not.regexp(['foo']);
if (x==false) throw '';
x = is.all.regexp(/test/, 1);
if (x) throw '';
x = is.any.regexp(new RegExp('ab+c'), 2);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.regexp([{}, /test/]);
if (x) throw '';
// Checks if the given value type is string.
x = is.string('foo');
if (x==false) throw '';
x = is.not.string(['foo']);
if (x==false) throw '';
x = is.all.string('foo', 1);
if (x) throw '';
x = is.any.string('foo', 2);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.string([{}, 'foo']);
if (x) throw '';
// Checks if the given value type is char.
x = is.char('f');
if (x==false) throw '';
x = is.not.char(['foo']);
if (x==false) throw '';
x = is.all.char('f', 1);
if (x) throw '';
x = is.any.char('f', 2);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.char(['f', 'o', 'o']);
if (x==false) throw '';
// Checks if the given value type is undefined.
x = is.undefined(undefined);
if (x==false) throw '';
x = is.not.undefined(null);
if (x==false) throw '';
x = is.all.undefined(undefined, 1);
if (x) throw '';
x = is.any.undefined(undefined, 2);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.undefined([{}, undefined]);
if (x) throw '';
// Checks if the given value types are same.
x = is.sameType(42, 7);
if (x==false) throw '';
x = is.sameType(42, '7');
if (x) throw '';
x = is.not.sameType(42, 7);
if (x) throw '';
// Checks if the given value is empty.
x = is.empty({});
if (x==false) throw '';
x = is.empty([]);
if (x==false) throw '';
x = is.empty('');
if (x==false) throw '';
x = is.not.empty(['foo']);
if (x==false) throw '';
x = is.all.empty('', {}, ['foo']);
if (x) throw '';
x = is.any.empty([], 42);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.empty([{}, 'foo']);
if (x) throw '';
// Checks if the given value is existy. (not null or undefined)
x = is.existy({});
if (x==false) throw '';
x = is.existy(null);
if (x) throw '';
x = is.not.existy(undefined);
if (x==false) throw '';
x = is.all.existy(null, ['foo']);
if (x) throw '';
x = is.any.existy(undefined, 42);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.existy([{}, 'foo']);
if (x==false) throw '';
// Checks if the given value is truthy. (existy and not false)
x = is.truthy(true);
if (x==false) throw '';
x = is.truthy(null);
if (x) throw '';
x = is.not.truthy(false);
if (x==false) throw '';
x = is.all.truthy(null, true);
if (x) throw '';
x = is.any.truthy(undefined, true);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.truthy([{}, true]);
if (x==false) throw '';
// Checks if the given value is falsy.
x = is.falsy(false);
if (x==false) throw '';
x = is.falsy(null);
if (x==false) throw '';
x = is.not.falsy(true);
if (x==false) throw '';
x = is.all.falsy(null, false);
if (x==false) throw '';
x = is.any.falsy(undefined, true);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.falsy([false, true, undefined]);
if (x) throw '';
// Checks if the given value is space.
x = is.space(' ');
if (x==false) throw '';
x = is.space('foo');
if (x) throw '';
x = is.not.space(true);
if (x==false) throw '';
x = is.all.space(' ', 'foo');
if (x) throw '';
x = is.any.space(' ', true);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.space([' ', 'foo', undefined]);
if (x) throw '';
// Checks if the given value matches url regexp.
x = is.url('http://www.test.com');
if (x==false) throw '';
x = is.url('foo');
if (x) throw '';
x = is.not.url(true);
if (x==false) throw '';
x = is.all.url('http://www.test.com', 'foo');
if (x) throw '';
x = is.any.url('http://www.test.com', true);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.url(['http://www.test.com', 'foo', undefined]);
if (x) throw '';
// Checks if the given value matches email regexp.
x = is.email('test@test.com');
if (x==false) throw '';
x = is.email('foo');
if (x) throw '';
x = is.not.email('foo');
if (x==false) throw '';
x = is.all.email('test@test.com', 'foo');
if (x) throw '';
x = is.any.email('test@test.com', 'foo');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.email(['test@test.com', 'foo', undefined]);
if (x) throw '';
// Checks if the given value matches credit card regexp.
x = is.creditCard(378282246310005);
if (x==false) throw '';
x = is.creditCard(123);
if (x) throw '';
x = is.not.creditCard(123);
if (x==false) throw '';
x = is.all.creditCard(378282246310005, 123);
if (x) throw '';
x = is.any.creditCard(378282246310005, 123);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.creditCard([378282246310005, 123, undefined]);
if (x) throw '';
// Checks if the given value matches alpha numeric regexp.
x = is.alphaNumeric('alphaNu3er1k');
if (x==false) throw '';
x = is.alphaNumeric('*?');
if (x) throw '';
x = is.not.alphaNumeric('*?');
if (x==false) throw '';
x = is.all.alphaNumeric('alphaNu3er1k', '*?');
if (x) throw '';
x = is.any.alphaNumeric('alphaNu3er1k', '*?');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.alphaNumeric(['alphaNu3er1k', '*?']);
if (x) throw '';
// Checks if the given value matches time string regexp.
x = is.timeString('13:45:30');
if (x==false) throw '';
x = is.timeString('90:90:90');
if (x) throw '';
x = is.not.timeString('90:90:90');
if (x==false) throw '';
x = is.all.timeString('13:45:30', '90:90:90');
if (x) throw '';
x = is.any.timeString('13:45:30', '90:90:90');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.timeString(['13:45:30', '90:90:90']);
if (x) throw '';
// Checks if the given value matches date string regexp.
x = is.dateString('11/11/2011');
if (x==false) throw '';
x = is.dateString('90/11/2011');
if (x) throw '';
x = is.not.dateString('90/11/2011');
if (x==false) throw '';
x = is.all.dateString('11/11/2011', '90/11/2011');
if (x) throw '';
x = is.any.dateString('11/11/2011', '90/11/2011');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.dateString(['11/11/2011', '90/11/2011']);
if (x) throw '';
// Checks if the given value matches US zip code regexp.
x = is.usZipCode('02201-1020');
if (x==false) throw '';
x = is.usZipCode('123');
if (x) throw '';
x = is.not.usZipCode('123');
if (x==false) throw '';
x = is.all.usZipCode('02201-1020', '123');
if (x) throw '';
x = is.any.usZipCode('02201-1020', '123');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.usZipCode(['02201-1020', '123']);
if (x) throw '';
// Checks if the given value matches Canada postal code regexp.
x = is.caPostalCode('L8V3Y1');
if (x==false) throw '';
x = is.caPostalCode('123');
if (x) throw '';
x = is.not.caPostalCode('123');
if (x==false) throw '';
x = is.all.caPostalCode('L8V3Y1', '123');
if (x) throw '';
x = is.any.caPostalCode('L8V3Y1', '123');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.caPostalCode(['L8V3Y1', '123']);
if (x) throw '';
// Checks if the given value matches UK post code regexp.
x = is.ukPostCode('B184BJ');
if (x==false) throw '';
x = is.ukPostCode('123');
if (x) throw '';
x = is.not.ukPostCode('123');
if (x==false) throw '';
x = is.all.ukPostCode('B184BJ', '123');
if (x) throw '';
x = is.any.ukPostCode('B184BJ', '123');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.ukPostCode(['B184BJ', '123']);
if (x) throw '';
// Checks if the given value matches North American numbering plan phone regexp.
x = is.nanpPhone('609-555-0175');
if (x==false) throw '';
x = is.nanpPhone('123');
if (x) throw '';
x = is.not.nanpPhone('123');
if (x==false) throw '';
x = is.all.nanpPhone('609-555-0175', '123');
if (x) throw '';
x = is.any.nanpPhone('609-555-0175', '123');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.nanpPhone(['609-555-0175', '123']);
if (x) throw '';
// Checks if the given value matches extensible provisioning protocol phone regexp.
x = is.eppPhone('+90.2322456789');
if (x==false) throw '';
x = is.eppPhone('123');
if (x) throw '';
x = is.not.eppPhone('123');
if (x==false) throw '';
x = is.all.eppPhone('+90.2322456789', '123');
if (x) throw '';
x = is.any.eppPhone('+90.2322456789', '123');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.eppPhone(['+90.2322456789', '123']);
if (x) throw '';
// Checks if the given value matches social security number regexp.
x = is.socialSecurityNumber('017-90-7890');
if (x==false) throw '';
x = is.socialSecurityNumber('123');
if (x) throw '';
x = is.not.socialSecurityNumber('123');
if (x==false) throw '';
x = is.all.socialSecurityNumber('017-90-7890', '123');
if (x) throw '';
x = is.any.socialSecurityNumber('017-90-7890', '123');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.socialSecurityNumber(['017-90-7890', '123']);
if (x) throw '';
// Checks if the given value matches affirmative regexp.
x = is.affirmative('yes');
if (x==false) throw '';
x = is.affirmative('no');
if (x) throw '';
x = is.not.affirmative('no');
if (x==false) throw '';
x = is.all.affirmative('yes', 'no');
if (x) throw '';
x = is.any.affirmative('yes', 'no');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.affirmative(['yes', 'y', 'true', 't', 'ok', 'okay']);
if (x==false) throw '';
// Checks if the given value matches hexadecimal regexp.
x = is.hexadecimal('f0f0f0');
if (x==false) throw '';
x = is.hexadecimal(2.5);
if (x) throw '';
x = is.not.hexadecimal('string');
if (x==false) throw '';
x = is.all.hexadecimal('ff', 'f50');
if (x==false) throw '';
x = is.any.hexadecimal('ff5500', true);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.hexadecimal(['fff', '333', 'f50']);
if (x==false) throw '';
// Checks if the given value matches hexColor regexp.
x = is.hexColor('#333');
if (x==false) throw '';
x = is.hexColor('#3333');
if (x) throw '';
x = is.not.hexColor(0.5);
if (x==false) throw '';
x = is.all.hexColor('fff', 'f50');
if (x==false) throw '';
//x = is.any.hexColor('ff5500', 0.5);
//if (x) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.hexColor(['fff', '333', 'f50']);
if (x==false) throw '';
// Checks if the given value matches ip regexp.
x = is.ip('198.156.23.5');
if (x==false) throw '';
x = is.ip('1.2..5');
if (x) throw '';
x = is.not.ip('8:::::::7');
if (x==false) throw '';
x = is.all.ip('0:1::4:ff5:54:987:C', '123.123.123.123');
if (x==false) throw '';
x = is.any.ip('123.8.4.3', '0.0.0.0');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.ip(['123.123.23.12', 'A:B:C:D:E:F:0:0']);
if (x==false) throw '';
// Checks if the given value matches ipv4 regexp.
x = is.ipv4('198.12.3.142');
if (x==false) throw '';
x = is.ipv4('1.2..5');
if (x) throw '';
x = is.not.ipv4('8:::::::7');
if (x==false) throw '';
x = is.all.ipv4('198.12.3.142', '123.123.123.123');
if (x==false) throw '';
x = is.any.ipv4('255.255.255.255', '850..1.4');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.ipv4(['198.12.3.142', '1.2.3']);
if (x) throw '';
// Checks if the given value matches ipv6 regexp.
x = is.ipv6('2001:DB8:0:0:1::1');
if (x==false) throw '';
x = is.ipv6('985.12.3.4');
if (x==false) throw '';
x = is.not.ipv6('8:::::::7');
if (x==false) throw '';
x = is.all.ipv6('2001:DB8:0:0:1::1', '1:50:198:2::1:2:8');
if (x==false) throw '';
x = is.any.ipv6('255.255.255.255', '2001:DB8:0:0:1::1');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.ipv6(['2001:DB8:0:0:1::1', '1.2.3']);
if (x) throw '';
// Checks if the given string contains a substring.
x = is.include('Some text goes here', 'text');
if (x==false) throw '';
x = is.include('test', 'text');
if (x) throw '';
x = is.not.include('test', 'text');
if (x==false) throw '';
// Checks if the given string is UPPERCASE.
x = is.upperCase('YEAP');
if (x==false) throw '';
x = is.upperCase('nope');
if (x) throw '';
x = is.not.upperCase('Nope');
if (x==false) throw '';
x = is.all.upperCase('YEAP', 'nope');
if (x) throw '';
x = is.any.upperCase('YEAP', 'nope');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.upperCase(['YEAP', 'ALL UPPERCASE']);
if (x==false) throw '';
// Checks if the given string is lowercase.
x = is.lowerCase('yeap');
if (x==false) throw '';
x = is.lowerCase('NOPE');
if (x) throw '';
x = is.not.lowerCase('Nope');
if (x==false) throw '';
x = is.all.lowerCase('yeap', 'NOPE');
if (x) throw '';
x = is.any.lowerCase('yeap', 'NOPE');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.lowerCase(['yeap', 'all lowercase']);
if (x==false) throw '';
// Checks if the given string starts with substring.
x = is.startWith('yeap', 'ye');
if (x==false) throw '';
x = is.startWith('nope', 'ye');
if (x) throw '';
x = is.not.startWith('nope not that', 'not');
if (x==false) throw '';
// Checks if the given string ends with substring.
x = is.endWith('yeap', 'ap');
if (x==false) throw '';
x = is.endWith('nope', 'no');
if (x) throw '';
x = is.not.endWith('nope not that', 'not');
if (x==false) throw '';
x = is.endWith('yeap that one', 'one');
if (x==false) throw '';
// Checks if the given string is capitalized.
x = is.capitalized('Yeap');
if (x==false) throw '';
x = is.capitalized('nope');
if (x) throw '';
x = is.not.capitalized('nope not capitalized');
if (x==false) throw '';
x = is.capitalized('Yeap Capitalized');
if (x==false) throw '';
x = is.all.capitalized('Yeap', 'All', 'Capitalized');
if (x==false) throw '';
x = is.any.capitalized('Yeap', 'some', 'Capitalized');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.capitalized(['Nope', 'not']);
if (x) throw '';
// Checks if the given string is palindrome.
x = is.palindrome('testset');
if (x==false) throw '';
x = is.palindrome('nope');
if (x) throw '';
x = is.not.palindrome('nope not palindrome');
if (x==false) throw '';
x = is.not.palindrome('tt');
if (x) throw '';
x = is.all.palindrome('testset', 'tt');
if (x==false) throw '';
x = is.any.palindrome('Yeap', 'some', 'testset');
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.palindrome(['Nope', 'testset']);
if (x) throw '';
// Checks if the given values are equal.
x = is.equal(42, 40 + 2);
if (x==false) throw '';
x = is.equal('yeap', 'yeap');
if (x==false) throw '';
x = is.equal(true, true);
if (x==false) throw '';
x = is.not.equal('yeap', 'nope');
if (x==false) throw '';
// Checks if the given value is even.
x = is.even(42);
if (x==false) throw '';
x = is.not.even(41);
if (x==false) throw '';
x = is.all.even(40, 42, 44);
if (x==false) throw '';
x = is.any.even(39, 42, 43);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.even([40, 42, 43]);
if (x) throw '';
// Checks if the given value is odd.
x = is.odd(41);
if (x==false) throw '';
x = is.not.odd(42);
if (x==false) throw '';
x = is.all.odd(39, 41, 43);
if (x==false) throw '';
x = is.any.odd(39, 42, 44);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.odd([40, 42, 43]);
if (x) throw '';
// Checks if the given value is positive.
x = is.positive(41);
if (x==false) throw '';
x = is.not.positive(-42);
if (x==false) throw '';
x = is.all.positive(39, 41, 43);
if (x==false) throw '';
x = is.any.positive(-39, 42, -44);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.positive([40, 42, -43]);
if (x) throw '';
// Checks if the given value is negative.
x = is.negative(-41);
if (x==false) throw '';
x = is.not.negative(42);
if (x==false) throw '';
x = is.all.negative(-39, -41, -43);
if (x==false) throw '';
x = is.any.negative(-39, 42, 44);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.negative([40, 42, -43]);
if (x) throw '';
// Checks if the given value is above minimum value.
x = is.above(41, 30);
if (x==false) throw '';
x = is.not.above(42, 50);
if (x==false) throw '';
// Checks if the given value is under maximum value.
x = is.under(30, 35);
if (x==false) throw '';
x = is.not.under(42, 30);
if (x==false) throw '';
// Checks if the given value is within minimum and maximum values.
x = is.within(30, 20, 40);
if (x==false) throw '';
x = is.not.within(40, 30, 35);
if (x==false) throw '';
// Checks if the given value is decimal.
x = is.decimal(41.5);
if (x==false) throw '';
x = is.not.decimal(42);
if (x==false) throw '';
x = is.all.decimal(39.5, 41.5, -43.5);
if (x==false) throw '';
x = is.any.decimal(-39, 42.5, 44);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.decimal([40, 42.5, -43]);
if (x) throw '';
// Checks if the given value is integer.
x = is.integer(41);
if (x==false) throw '';
x = is.not.integer(42.5);
if (x==false) throw '';
x = is.all.integer(39, 41, -43);
if (x==false) throw '';
x = is.any.integer(-39, 42.5, 44);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.integer([40, 42.5, -43]);
if (x) throw '';
// Checks if the given value is finite.
x = is.finite(41);
if (x==false) throw '';
x = is.not.finite(42 / 0);
if (x==false) throw '';
x = is.all.finite(39, 41, -43);
if (x==false) throw '';
x = is.any.finite(-39, Infinity, 44);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.finite([Infinity, -Infinity, 42.5]);
if (x) throw '';
// Checks if the given value is infinite.
x = is.infinite(Infinity);
if (x==false) throw '';
x = is.not.infinite(42);
if (x==false) throw '';
x = is.all.infinite(Infinity, -Infinity, -43 / 0);
if (x==false) throw '';
x = is.any.infinite(-39, Infinity, 44);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.infinite([Infinity, -Infinity, 42.5]);
if (x) throw '';
// Checks if the objects' property count is equal to given count.
x = is.propertyCount({this: 'is', 'sample': object}, 2);
if (x==false) throw '';
x = is.propertyCount({this: 'is', 'sample': object}, 3);
if (x) throw '';
x = is.not.propertyCount({}, 2);
if (x==false) throw '';
// Checks if the given property is defined on object.
x = is.propertyDefined({yeap: 'yeap'}, 'yeap');
if (x==false) throw '';
x = is.propertyDefined({yeap: 'yeap'}, 'nope');
if (x) throw '';
x = is.not.propertyDefined({}, 'nope');
if (x==false) throw '';
// Checks if the given object is window object.
x = is.windowObject(window);
if (x==false) throw '';
x = is.windowObject({nope: 'nope'});
if (x) throw '';
x = is.not.windowObject({});
if (x==false) throw '';
x = is.all.windowObject(window, {nope: 'nope'});
if (x) throw '';
x = is.any.windowObject(window, {nope: 'nope'});
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.windowObject([window, {nope: 'nope'}]);
if (x) throw '';
// Checks if the given object is a dom node.
var obj = document.createElement('div');
x = is.domNode(obj);
if (x==false) throw '';
x = is.domNode({nope: 'nope'});
if (x) throw '';
x = is.not.domNode({});
if (x==false) throw '';
x = is.all.domNode(obj, obj);
if (x==false) throw '';
x = is.any.domNode(obj, {nope: 'nope'});
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.domNode([obj, {nope: 'nope'}]);
if (x) throw '';
// Checks if the given item is in array.
x = is.inArray(2, [1, 2, 3]);
if (x==false) throw '';
x = is.inArray(4, [1, 2, 3]);
if (x) throw '';
x = is.not.inArray(4, [1, 2, 3]);
if (x==false) throw '';
// Checks if the given array is sorted.
x = is.sorted([1, 2, 3]);
if (x==false) throw '';
x = is.sorted([1, 2, 4, 3]);
if (x) throw '';
x = is.not.sorted([5, 4, 3]);
if (x==false) throw '';
x = is.all.sorted([1, 2], [3, 4]);
if (x==false) throw '';
x = is.any.sorted([1, 2], [5, 4]);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.sorted([[1, 2], [5, 4]]);
if (x) throw '';
// Checks if the given date object indicate today.
var today = new Date();
x = is.today(today);
if (x==false) throw '';
var yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
x = is.today(yesterday);
if (x) throw '';
x = is.not.today(yesterday);
if (x==false) throw '';
x = is.all.today(today, today);
if (x==false) throw '';
x = is.any.today(today, yesterday);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.today([today, yesterday]);
if (x) throw '';
// Checks if the given date object indicate yesterday.
var today = new Date();
x = is.yesterday(today);
if (x) throw '';
var yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
x = is.yesterday(yesterday);
if (x==false) throw '';
x = is.not.yesterday(today);
if (x==false) throw '';
x = is.all.yesterday(yesterday, today);
if (x) throw '';
x = is.any.yesterday(today, yesterday);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.yesterday([today, yesterday]);
if (x) throw '';
// Checks if the given date object indicate tomorrow.
var today = new Date();
x = is.tomorrow(today);
if (x) throw '';
var tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));
x = is.tomorrow(tomorrow);
if (x==false) throw '';
x = is.not.tomorrow(today);
if (x==false) throw '';
x = is.all.tomorrow(tomorrow, today);
if (x) throw '';
x = is.any.tomorrow(today, tomorrow);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.tomorrow([today, tomorrow]);
if (x) throw '';
// Checks if the given date object indicate past.
var yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
var tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));
x = is.past(yesterday);
if (x==false) throw '';
x = is.past(tomorrow);
if (x) throw '';
x = is.not.past(tomorrow);
if (x==false) throw '';
x = is.all.past(tomorrow, yesterday);
if (x) throw '';
x = is.any.past(yesterday, tomorrow);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.past([yesterday, tomorrow]);
if (x) throw '';
// Checks if the given date object indicate future.
var yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
var tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));
x = is.future(yesterday);
if (x) throw '';
x = is.future(tomorrow);
if (x==false) throw '';
x = is.not.future(yesterday);
if (x==false) throw '';
x = is.all.future(tomorrow, yesterday);
if (x) throw '';
x = is.any.future(yesterday, tomorrow);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.future([yesterday, tomorrow]);
if (x) throw '';
// Checks if the given date objects' day equal given dayString parameter.
var mondayObj = new Date('01/26/2015');
var tuesdayObj = new Date('01/27/2015');
x = is.day(mondayObj, 'monday');
if (x==false) throw '';
x = is.day(mondayObj, 'tuesday');
if (x) throw '';
x = is.not.day(mondayObj, 'tuesday');
if (x==false) throw '';
// Checks if the given date objects' month equal given monthString parameter.
var januaryObj = new Date('01/26/2015');
var februaryObj = new Date('02/26/2015');
x = is.month(januaryObj, 'january');
if (x==false) throw '';
x = is.month(februaryObj, 'january');
if (x) throw '';
x = is.not.month(februaryObj, 'january');
if (x==false) throw '';
// Checks if the given date objects' year equal given yearNumber parameter.
var year2015 = new Date('01/26/2015');
var year2016 = new Date('01/26/2016');
x = is.year(year2015, 2015);
if (x==false) throw '';
x = is.year(year2016, 2015);
if (x) throw '';
x = is.not.year(year2016, 2015);
if (x==false) throw '';
// Checks if the given year number is leapYear.
x = is.leapYear(2016);
if (x==false) throw '';
x = is.leapYear(2015);
if (x) throw '';
x = is.not.leapYear(2015);
if (x==false) throw '';
x = is.all.leapYear(2015, 2016);
if (x) throw '';
x = is.any.leapYear(2015, 2016);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.leapYear([2016, 2080]);
if (x==false) throw '';
// Checks if the given date objects' day is weekend.
var monday = new Date('01/26/2015');
var sunday = new Date('01/25/2015');
var saturday = new Date('01/24/2015');
x = is.weekend(sunday);
if (x==false) throw '';
x = is.weekend(monday);
if (x) throw '';
x = is.not.weekend(monday);
if (x==false) throw '';
x = is.all.weekend(sunday, saturday);
if (x==false) throw '';
x = is.any.weekend(sunday, saturday, monday);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.weekend([sunday, saturday, monday]);
if (x) throw '';
// Checks if the given date objects' day is weekday.
var monday = new Date('01/26/2015');
var sunday = new Date('01/25/2015');
var saturday = new Date('01/24/2015');
x = is.weekday(monday);
if (x==false) throw '';
x = is.weekday(sunday);
if (x) throw '';
x = is.not.weekday(sunday);
if (x==false) throw '';
x = is.all.weekday(monday, saturday);
if (x) throw '';
x = is.any.weekday(sunday, saturday, monday);
if (x==false) throw '';
// 'all' and 'any' interfaces can also take array parameter
x = is.all.weekday([sunday, saturday, monday]);
if (x) throw '';
// Checks if the date is within given range.
var saturday = new Date('01/24/2015');
var sunday = new Date('01/25/2015');
var monday = new Date('01/26/2015');
x = is.inDateRange(sunday, saturday, monday);
if (x==false) throw '';
x = is.inDateRange(saturday, sunday, monday);
if (x) throw '';
x = is.not.inDateRange(saturday, sunday, monday);
if (x==false) throw '';
// Checks if the given date is between now and 7 days ago.
var twoDaysAgo = new Date(new Date().setDate(new Date().getDate() - 2));
var nineDaysAgo = new Date(new Date().setDate(new Date().getDate() - 9));
x = is.inLastWeek(twoDaysAgo);
if (x==false) throw '';
x = is.inLastWeek(nineDaysAgo);
if (x) throw '';
x = is.not.inLastWeek(nineDaysAgo);
if (x==false) throw '';
// Checks if the given date is between now and a month ago.
var tenDaysAgo = new Date(new Date().setDate(new Date().getDate() - 10));
var fortyDaysAgo = new Date(new Date().setDate(new Date().getDate() - 40));
x = is.inLastMonth(tenDaysAgo);
if (x==false) throw '';
x = is.inLastMonth(fortyDaysAgo);
if (x) throw '';
x = is.not.inLastMonth(fortyDaysAgo);
if (x==false) throw '';
// Checks if the given date is between now and a year ago.
var twoMonthsAgo = new Date(new Date().setMonth(new Date().getMonth() - 2));
var thirteenMonthsAgo = new Date(new Date().setMonth(new Date().getMonth() - 13));
x = is.inLastYear(twoMonthsAgo);
if (x==false) throw '';
x = is.inLastYear(thirteenMonthsAgo);
if (x) throw '';
x = is.not.inLastYear(thirteenMonthsAgo);
if (x==false) throw '';
// Checks if the given date is between now and 7 days later.
var twoDaysLater = new Date(new Date().setDate(new Date().getDate() + 2));
var nineDaysLater = new Date(new Date().setDate(new Date().getDate() + 9));
x = is.inNextWeek(twoDaysLater);
if (x==false) throw '';
x = is.inNextWeek(nineDaysLater);
if (x) throw '';
x = is.not.inNextWeek(nineDaysLater);
if (x==false) throw '';
// Checks if the given date is between now and a month later.
var tenDaysLater = new Date(new Date().setDate(new Date().getDate() + 10));
var fortyDaysLater = new Date(new Date().setDate(new Date().getDate() + 40));
x = is.inNextMonth(tenDaysLater);
if (x==false) throw '';
x = is.inNextMonth(fortyDaysLater);
if (x) throw '';
x = is.not.inNextMonth(fortyDaysLater);
if (x==false) throw '';
// Checks if the given date is between now and a year later.
var twoMonthsLater = new Date(new Date().setMonth(new Date().getMonth() + 2));
var thirteenMonthsLater = new Date(new Date().setMonth(new Date().getMonth() + 13));
x = is.inNextYear(twoMonthsLater);
if (x==false) throw '';
x = is.inNextYear(thirteenMonthsLater);
if (x) throw '';
x = is.not.inNextYear(thirteenMonthsLater);
if (x==false) throw '';
// Checks if the given date is in the parameter quarter.
var firstQuarter = new Date('01/26/2015');
var secondQuarter = new Date('05/26/2015');
x = is.quarterOfYear(firstQuarter, 1);
if (x==false) throw '';
x = is.quarterOfYear(secondQuarter, 1);
if (x) throw '';
x = is.not.quarterOfYear(secondQuarter, 1);
if (x==false) throw '';
// Checks if the given date is in daylight saving time.
// For Turkey Time Zone
var january1 = new Date('01/01/2015');
var june1 = new Date('06/01/2015');
x = is.dayLightSavingTime(june1);
if (x==false) throw '';
x = is.dayLightSavingTime(january1);
if (x) throw '';
x = is.not.dayLightSavingTime(january1);
if (x==false) throw '';
// Override RegExps if you think they suck.
x = is.url('https://www.duckduckgo.com');
if (x==false) throw '';
x = is.setRegexp(/quack/, 'url');
x = is.url('quack');
if (x==false) throw '';
// Change namespace of library to prevent name collisions.
var customName = x = is.setNamespace();
customName.odd(3);
// if (x==false) throw '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment