diff --git a/is-js/is-js-tests.ts b/is-js/is-js-tests.ts new file mode 100644 index 0000000000..44940bee1d --- /dev/null +++ b/is-js/is-js-tests.ts @@ -0,0 +1,655 @@ +/// + +//#region Type checks + +var getArguments = function () { + return arguments; +}; +var arguments = getArguments(); +is.arguments(arguments); +is.not.arguments({ foo: 'bar' }); +is.all.arguments(arguments, 'bar'); +is.any.arguments(['foo'], arguments); +is.all.arguments([arguments, 'foo', 'bar']); + +is.array(['foo', 'bar', 'baz']); +is.not.array({ foo: 'bar' }); +is.all.array(['foo'], 'bar'); +is.any.array(['foo'], 'bar'); +is.all.array([[1, 2], 'foo', 'bar']); + +is.boolean(true); +is.not.boolean({ foo: 'bar' }); +is.all.boolean(true, 'bar'); +is.any.boolean(true, 'bar'); +is.all.boolean([true, 'foo', 'bar']); + +is.date(new Date()); +is.not.date({ foo: 'bar' }); +is.all.date(new Date(), 'bar'); +is.any.date(new Date(), 'bar'); +is.all.date([new Date(), 'foo', 'bar']); + +is.error(new Error()); +is.not.error({ foo: 'bar' }); +is.all.error(new Error(), 'bar'); +is.any.error(new Error(), 'bar'); +is.all.error([new Error(), 'foo', 'bar']); + +is.function(toString); +is.not.function({ foo: 'bar' }); +is.all.function(toString, 'bar'); +is.any.function(toString, 'bar'); +is.all.function([toString, 'foo', 'bar']); + +is.nan(NaN); +is.not.nan(42); +is.all.nan(NaN, 1); +is.any.nan(NaN, 2); +is.all.nan([NaN, 'foo', 1]); + +is.null(null); +is.not.null(42); +is.all.null(null, 1); +is.any.null(null, 2); +is.all.null([null, 'foo', 1]); + +is.number(42); +is.not.number('42'); +is.all.number('foo', 1); +is.any.number({}, 2); +is.all.number([42, 'foo', 1]); + +is.object({ foo: 'bar' }); +is.object(toString); +is.not.object('foo'); +is.all.object({}, 1); +is.any.object({}, 2); +is.all.object([{}, new Object()]); + +is.json({ foo: 'bar' }); +is.json(toString); +is.not.json([]); +is.all.json({}, 1); +is.any.json({}, 2); +is.all.json([{}, { foo: 'bar' }]); + +is.regexp(/test/); +is.not.regexp(['foo']); +is.all.regexp(/test/, 1); +is.any.regexp(new RegExp('ab+c'), 2); +is.all.regexp([{}, /test/]); + +is.string('foo'); +is.not.string(['foo']); +is.all.string('foo', 1); +is.any.string('foo', 2); +is.all.string([{}, 'foo']); + +is.char('f'); +is.not.char(['foo']); +is.all.char('f', 1); +is.any.char('f', 2); +is.all.char(['f', 'o', 'o']); + +is.undefined(undefined); +is.not.undefined(null); +is.all.undefined(undefined, 1); +is.any.undefined(undefined, 2); +is.all.undefined([{}, undefined]); + +is.sameType(42, 7); +is.sameType(42, '7'); +is.not.sameType(42, 7); + +//#endregion + +//#region Presence checks + +is.empty({}); +is.empty([]); +is.empty(''); +is.not.empty(['foo']); +is.all.empty('', {}, ['foo']); +is.any.empty([], 42); +is.all.empty([{}, 'foo']); + +is.existy({}); +is.existy(null); +is.not.existy(undefined); +is.all.existy(null, ['foo']); +is.any.existy(undefined, 42); +is.all.existy([{}, 'foo']); + +is.truthy(true); +is.truthy(null); +is.not.truthy(false); +is.all.truthy(null, true); +is.any.truthy(undefined, true); +is.all.truthy([{}, true]); + +is.falsy(false); +is.falsy(null); +is.not.falsy(true); +is.all.falsy(null, false); +is.any.falsy(undefined, true); +is.all.falsy([false, true, undefined]); + +is.space(' '); +is.space('foo'); +is.not.space(true); +is.all.space(' ', 'foo'); +is.any.space(' ', true); +is.all.space([' ', 'foo', undefined]); + +//#endregion + +//#region RegExp checks + +is.url('http://www.test.com'); +is.url('foo'); +is.not.url(true); +is.all.url('http://www.test.com', 'foo'); +is.any.url('http://www.test.com', true); +is.all.url(['http://www.test.com', 'foo', undefined]); + +is.email('test@test.com'); +is.email('foo'); +is.not.email('foo'); +is.all.email('test@test.com', 'foo'); +is.any.email('test@test.com', 'foo'); +is.all.email(['test@test.com', 'foo', undefined]); + +is.creditCard(378282246310005); +is.creditCard(123); +is.not.creditCard(123); +is.all.creditCard(378282246310005, 123); +is.any.creditCard(378282246310005, 123); +is.all.creditCard([378282246310005, 123, undefined]); + +is.alphaNumeric('alphaNu3er1k'); +is.alphaNumeric('*?'); +is.not.alphaNumeric('*?'); +is.all.alphaNumeric('alphaNu3er1k', '*?'); +is.any.alphaNumeric('alphaNu3er1k', '*?'); +is.all.alphaNumeric(['alphaNu3er1k', '*?']); + +is.timeString('13:45:30'); +is.timeString('90:90:90'); +is.not.timeString('90:90:90'); +is.all.timeString('13:45:30', '90:90:90'); +is.any.timeString('13:45:30', '90:90:90'); +is.all.timeString(['13:45:30', '90:90:90']); + +is.dateString('11/11/2011'); +is.dateString('90/11/2011'); +is.not.dateString('90/11/2011'); +is.all.dateString('11/11/2011', '90/11/2011'); +is.any.dateString('11/11/2011', '90/11/2011'); +is.all.dateString(['11/11/2011', '90/11/2011']); + +is.usZipCode('02201-1020'); +is.usZipCode('123'); +is.not.usZipCode('123'); +is.all.usZipCode('02201-1020', '123'); +is.any.usZipCode('02201-1020', '123'); +is.all.usZipCode(['02201-1020', '123']); + +is.caPostalCode('L8V3Y1'); +is.caPostalCode('L8V 3Y1'); +is.caPostalCode('123'); +is.not.caPostalCode('123'); +is.all.caPostalCode('L8V3Y1', '123'); +is.any.caPostalCode('L8V3Y1', '123'); +is.all.caPostalCode(['L8V3Y1', '123']); + +is.ukPostCode('B184BJ'); +is.ukPostCode('123'); +is.not.ukPostCode('123'); +is.all.ukPostCode('B184BJ', '123'); +is.any.ukPostCode('B184BJ', '123'); +is.all.ukPostCode(['B184BJ', '123']); + +is.nanpPhone('609-555-0175'); +is.nanpPhone('123'); +is.not.nanpPhone('123'); +is.all.nanpPhone('609-555-0175', '123'); +is.any.nanpPhone('609-555-0175', '123'); +is.all.nanpPhone(['609-555-0175', '123']); + +is.eppPhone('+90.2322456789'); +is.eppPhone('123'); +is.not.eppPhone('123'); +is.all.eppPhone('+90.2322456789', '123'); +is.any.eppPhone('+90.2322456789', '123'); +is.all.eppPhone(['+90.2322456789', '123']); + +is.socialSecurityNumber('017-90-7890'); +is.socialSecurityNumber('123'); +is.not.socialSecurityNumber('123'); +is.all.socialSecurityNumber('017-90-7890', '123'); +is.any.socialSecurityNumber('017-90-7890', '123'); +is.all.socialSecurityNumber(['017-90-7890', '123']); + +is.affirmative('yes'); +is.affirmative('no'); +is.not.affirmative('no'); +is.all.affirmative('yes', 'no'); +is.any.affirmative('yes', 'no'); +is.all.affirmative(['yes', 'y', 'true', 't', 'ok', 'okay']); + +is.hexadecimal('f0f0f0'); +is.hexadecimal(2.5); +is.not.hexadecimal('string'); +is.all.hexadecimal('ff', 'f50'); +is.any.hexadecimal('ff5500', true); +is.all.hexadecimal(['fff', '333', 'f50']); + +is.hexColor('#333'); +is.hexColor('#3333'); +is.not.hexColor(0.5); +is.all.hexColor('fff', 'f50'); +is.any.hexColor('ff5500', 0.5); +is.all.hexColor(['fff', '333', 'f50']); + +is.ip('198.156.23.5'); +is.ip('1.2..5'); +is.not.ip('8:::::::7'); +is.all.ip('0:1::4:ff5:54:987:C', '123.123.123.123'); +is.any.ip('123.8.4.3', '0.0.0.0'); +is.all.ip(['123.123.23.12', 'A:B:C:D:E:F:0:0']); + +is.ipv4('198.12.3.142'); +is.ipv4('1.2..5'); +is.not.ipv4('8:::::::7'); +is.all.ipv4('198.12.3.142', '123.123.123.123'); +is.any.ipv4('255.255.255.255', '850..1.4'); +is.all.ipv4(['198.12.3.142', '1.2.3']); + +is.ipv6('2001:DB8:0:0:1::1'); +is.ipv6('985.12.3.4'); +is.not.ipv6('8:::::::7'); +is.all.ipv6('2001:DB8:0:0:1::1', '1:50:198:2::1:2:8'); +is.any.ipv6('255.255.255.255', '2001:DB8:0:0:1::1'); +is.all.ipv6(['2001:DB8:0:0:1::1', '1.2.3']); + +//#endregion + +//#region String checks + +is.include('Some text goes here', 'text'); +is.include('test', 'text'); +is.not.include('test', 'text'); + +is.upperCase('YEAP'); +is.upperCase('nope'); +is.not.upperCase('Nope'); +is.all.upperCase('YEAP', 'nope'); +is.any.upperCase('YEAP', 'nope'); +is.all.upperCase(['YEAP', 'ALL UPPERCASE']); + +is.lowerCase('yeap'); +is.lowerCase('NOPE'); +is.not.lowerCase('Nope'); +is.all.lowerCase('yeap', 'NOPE'); +is.any.lowerCase('yeap', 'NOPE'); +is.all.lowerCase(['yeap', 'all lowercase']); + +is.startWith('yeap', 'ye'); +is.startWith('nope', 'ye'); +is.not.startWith('nope not that', 'not'); + +is.endWith('yeap', 'ap'); +is.endWith('nope', 'no'); +is.not.endWith('nope not that', 'not'); +is.endWith('yeap that one', 'one'); + +is.capitalized('Yeap'); +is.capitalized('nope'); +is.not.capitalized('nope not capitalized'); +is.not.capitalized('nope Capitalized'); +is.all.capitalized('Yeap', 'All', 'Capitalized'); +is.any.capitalized('Yeap', 'some', 'Capitalized'); +is.all.capitalized(['Nope', 'not']); + +is.palindrome('testset'); +is.palindrome('nope'); +is.not.palindrome('nope not palindrome'); +is.not.palindrome('tt'); +is.all.palindrome('testset', 'tt'); +is.any.palindrome('Yeap', 'some', 'testset'); +is.all.palindrome(['Nope', 'testset']); + +//#endregion + +//#region Arithmetic checks + +is.equal(42, 40 + 2); +is.equal('yeap', 'yeap'); +is.equal(true, true); +is.not.equal('yeap', 'nope'); + +is.even(42); +is.not.even(41); +is.all.even(40, 42, 44); +is.any.even(39, 42, 43); +is.all.even([40, 42, 43]); + +is.odd(41); +is.not.odd(42); +is.all.odd(39, 41, 43); +is.any.odd(39, 42, 44); +is.all.odd([40, 42, 43]); + +is.positive(41); +is.not.positive(-42); +is.all.positive(39, 41, 43); +is.any.positive(-39, 42, -44); +is.all.positive([40, 42, -43]); + +is.negative(-41); +is.not.negative(42); +is.all.negative(-39, -41, -43); +is.any.negative(-39, 42, 44); +is.all.negative([40, 42, -43]); + +is.above(41, 30); +is.not.above(42, 50); + +is.under(30, 35); +is.not.under(42, 30); + +is.within(30, 20, 40); +is.not.within(40, 30, 35); + +is.decimal(41.5); +is.not.decimal(42); +is.all.decimal(39.5, 41.5, -43.5); +is.any.decimal(-39, 42.5, 44); +is.all.decimal([40, 42.5, -43]); + +is.integer(41); +is.not.integer(42.5); +is.all.integer(39, 41, -43); +is.any.integer(-39, 42.5, 44); +is.all.integer([40, 42.5, -43]); + +is.finite(41); +is.not.finite(42 / 0); +is.all.finite(39, 41, -43); +is.any.finite(-39, Infinity, 44); +is.all.finite([Infinity, -Infinity, 42.5]); + +is.infinite(Infinity); +is.not.infinite(42); +is.all.infinite(Infinity, -Infinity, -43 / 0); +is.any.infinite(-39, Infinity, 44); +is.all.infinite([Infinity, -Infinity, 42.5]); + +//#endregion + +//#region Object checks + +is.propertyCount({ this: 'is', 'sample': {} }, 2); +is.propertyCount({ this: 'is', 'sample': {} }, 3); +is.not.propertyCount({}, 2); + +is.propertyDefined({ yeap: 'yeap' }, 'yeap'); +is.propertyDefined({ yeap: 'yeap' }, 'nope'); +is.not.propertyDefined({}, 'nope'); + +is.windowObject(window); +is.windowObject({ nope: 'nope' }); +is.not.windowObject({}); + +is.all.windowObject(window, { nope: 'nope' }); +is.any.windowObject(window, { nope: 'nope' }); +is.all.windowObject([window, { nope: 'nope' }]); + +var obj = document.createElement('div'); +is.domNode(obj); +is.domNode({ nope: 'nope' }); +is.not.domNode({}); +is.all.domNode(obj, obj); +is.any.domNode(obj, { nope: 'nope' }); +is.all.domNode([obj, { nope: 'nope' }]); + +//#endregion + +//#region Array checks + +is.inArray(2, [1, 2, 3]); +is.inArray(4, [1, 2, 3]); +is.not.inArray(4, [1, 2, 3]); + +is.sorted([1, 2, 3]); +is.sorted([1, 2, 4, 3]); +is.not.sorted([5, 4, 3]); +is.all.sorted([1, 2], [3, 4]); +is.any.sorted([1, 2], [5, 4]); +is.all.sorted([[1, 2], [5, 4]]); + +//#endregion + +//#region Environment checks + +is.ie(); +is.ie(6); +is.not.ie(); + +is.chrome(); +is.not.chrome(); + +is.firefox(); +is.not.firefox(); + +is.opera(); +is.not.opera(); + +is.safari(); +is.not.safari(); + +is.ios(); +is.not.ios(); + +is.iphone(); +is.not.iphone(); + +is.ipad(); +is.not.ipad(); + +is.ipod(); +is.not.ipod(); + +is.android(); +is.not.android(); + +is.androidPhone(); +is.not.androidPhone(); + +is.androidTablet(); +is.not.androidTablet(); + +is.blackberry(); + +is.not.blackberry(); + +is.windowsPhone(); +is.not.windowsPhone(); + +is.windowsTablet(); +is.not.windowsTablet(); + +is.windows(); +is.not.windows(); + +is.mac(); +is.not.mac(); + +is.linux(); +is.not.linux(); + +is.desktop(); +is.not.desktop(); + +is.mobile(); +is.not.mobile(); + +is.tablet(); +is.not.tablet(); + +is.online(); +is.not.online(); + +is.offline(); +is.not.offline(); + +//#endregion + +//#region Time checks + +var today = new Date(); +var yesterday = new Date(new Date().setDate(new Date().getDate() - 1)); +var tomorrow = new Date(new Date().setDate(new Date().getDate() + 1)); +var monday = new Date('01/26/2015'); +var sunday = new Date('01/25/2015'); +var saturday = new Date('01/24/2015'); + +is.today(today); +is.today(yesterday) +is.not.today(yesterday); +is.all.today(today, today); +is.any.today(today, yesterday); +is.all.today([today, yesterday]); + +is.yesterday(today); +is.yesterday(yesterday); +is.not.yesterday(today); +is.all.yesterday(yesterday, today); +is.any.yesterday(today, yesterday); +is.all.yesterday([today, yesterday]); + +is.tomorrow(today); +is.tomorrow(tomorrow); +is.not.tomorrow(today); +is.all.tomorrow(tomorrow, today); +is.any.tomorrow(today, tomorrow); +is.all.tomorrow([today, tomorrow]); + +is.past(yesterday); +is.past(tomorrow); +is.not.past(tomorrow); +is.all.past(tomorrow, yesterday); +is.any.past(yesterday, tomorrow); +is.all.past([yesterday, tomorrow]); + +is.future(yesterday); +is.future(tomorrow); +is.not.future(yesterday); +is.all.future(tomorrow, yesterday); +is.any.future(yesterday, tomorrow); +is.all.future([yesterday, tomorrow]); + +var mondayObj = new Date('01/26/2015'); +var tuesdayObj = new Date('01/27/2015'); +is.day(mondayObj, 'monday'); +is.day(mondayObj, 'tuesday'); +is.not.day(mondayObj, 'tuesday'); + +var januaryObj = new Date('01/26/2015'); +var februaryObj = new Date('02/26/2015'); +is.month(januaryObj, 'january'); +is.month(februaryObj, 'january'); +is.not.month(februaryObj, 'january'); + +var year2015 = new Date('01/26/2015'); +var year2016 = new Date('01/26/2016'); +is.year(year2015, 2015); +is.year(year2016, 2015); +is.not.year(year2016, 2015); + +is.leapYear(2016); +is.leapYear(2015); +is.not.leapYear(2015); +is.all.leapYear(2015, 2016); +is.any.leapYear(2015, 2016); +is.all.leapYear([2016, 2080]); + +is.weekend(sunday); +is.weekend(monday); +is.not.weekend(monday); +is.all.weekend(sunday, saturday); +is.any.weekend(sunday, saturday, monday); +is.all.weekend([sunday, saturday, monday]); + +is.weekday(monday); +is.weekday(sunday); +is.not.weekday(sunday); +is.all.weekday(monday, saturday); +is.any.weekday(sunday, saturday, monday); +is.all.weekday([sunday, saturday, monday]); + +is.inDateRange(sunday, saturday, monday); +is.inDateRange(saturday, sunday, monday); +is.not.inDateRange(saturday, sunday, monday); + +var twoDaysAgo = new Date(new Date().setDate(new Date().getDate() - 2)); +var nineDaysAgo = new Date(new Date().setDate(new Date().getDate() - 9)); +is.inLastWeek(twoDaysAgo); +is.inLastWeek(nineDaysAgo); +is.not.inLastWeek(nineDaysAgo); + +var tenDaysAgo = new Date(new Date().setDate(new Date().getDate() - 10)); +var fortyDaysAgo = new Date(new Date().setDate(new Date().getDate() - 40)); +is.inLastMonth(tenDaysAgo); +is.inLastMonth(fortyDaysAgo); +is.not.inLastMonth(fortyDaysAgo); + +var twoMonthsAgo = new Date(new Date().setMonth(new Date().getMonth() - 2)); +var thirteenMonthsAgo = new Date(new Date().setMonth(new Date().getMonth() - 13)); +is.inLastYear(twoMonthsAgo); +is.inLastYear(thirteenMonthsAgo); +is.not.inLastYear(thirteenMonthsAgo); + +var twoDaysLater = new Date(new Date().setDate(new Date().getDate() + 2)); +var nineDaysLater = new Date(new Date().setDate(new Date().getDate() + 9)); +is.inNextWeek(twoDaysLater); +is.inNextWeek(nineDaysLater); +is.not.inNextWeek(nineDaysLater); + +var tenDaysLater = new Date(new Date().setDate(new Date().getDate() + 10)); +var fortyDaysLater = new Date(new Date().setDate(new Date().getDate() + 40)); +is.inNextMonth(tenDaysLater); +is.inNextMonth(fortyDaysLater); +is.not.inNextMonth(fortyDaysLater); + +var twoMonthsLater = new Date(new Date().setMonth(new Date().getMonth() + 2)); +var thirteenMonthsLater = new Date(new Date().setMonth(new Date().getMonth() + 13)); +is.inNextYear(twoMonthsLater); +is.inNextYear(thirteenMonthsLater); +is.not.inNextYear(thirteenMonthsLater); + +var firstQuarter = new Date('01/26/2015'); +var secondQuarter = new Date('05/26/2015'); +is.quarterOfYear(firstQuarter, 1); +is.quarterOfYear(secondQuarter, 1); +is.not.quarterOfYear(secondQuarter, 1); + +var january1 = new Date('01/01/2015'); +var june1 = new Date('06/01/2015'); +is.dayLightSavingTime(june1); +is.dayLightSavingTime(january1); +is.not.dayLightSavingTime(january1); + +//#endregion + +//#region Configuration methods + +is.url('https://www.duckduckgo.com'); +is.setRegexp(/quack/, 'url'); +is.url('quack'); + +var customName = is.setNamespace(); +customName.odd(3); + +//#endregion \ No newline at end of file diff --git a/is-js/is-js.d.ts b/is-js/is-js.d.ts new file mode 100644 index 0000000000..aff47a7c59 --- /dev/null +++ b/is-js/is-js.d.ts @@ -0,0 +1,1323 @@ +// Type definitions for is.js +// Project: http://arasatasaygin.github.io/is.js/ +// Definitions by: Rodrigo Cabral +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface IsStatic { + + //#region Type checks + + /** + * Checks if the given value type is arguments. + */ + arguments(value: any): boolean; + + /** + * Checks if the given value type is array. + */ + array(value: any): boolean; + + /** + * Checks if the given value type is boolean. + */ + boolean(value: any): boolean; + + /** + * Checks if the given value type is date. + */ + date(value: any): boolean; + + /** + * Checks if the given value type is error. + */ + error(value: any): boolean; + + /** + * Checks if the given value type is function. + */ + function(value: any): boolean; + + /** + * Checks if the given value type is NaN. + */ + nan(value: any): boolean; + + /** + * Checks if the given value type is null. + */ + null(value: any): boolean; + + /** + * Checks if the given value type is number. + */ + number(value: any): boolean; + + /** + * Checks if the given value type is object. + */ + object(value: any): boolean; + + /** + * Checks if the given value type is pure json object. + */ + json(value: any): boolean; + + /** + * Checks if the given value type is RegExp. + */ + regexp(value: any): boolean; + + /** + * Checks if the given value type is string. + */ + string(value: any): boolean; + + /** + * Checks if the given value type is char. + */ + char(value: any): boolean; + + /** + * Checks if the given value type is undefined. + */ + undefined(value: any): boolean; + + /** + * Checks if the given value types are same type. + */ + sameType(value1: any, value2: any): boolean; + + //#endregion + + //#region Presence checks + + /** + * Checks if the given value is empty. + */ + empty(value: any): boolean; + + /** + * Checks if the given value is existy. (not null or undefined) + */ + existy(value: any): boolean; + + /** + * Checks if the given value is truthy. (existy and not false) + */ + truthy(value: any): boolean; + + /** + * Checks if the given value is falsy. + */ + falsy(value: any): boolean; + + /** + * Checks if the given value is space. + */ + space(value: any): boolean; + + //#endregion + + //#region RegExp checks + + /** + * Checks if the given value matches url regexp. + */ + url(value: any): boolean; + + /** + * Checks if the given value matches email regexp. + */ + email(value: any): boolean; + + /** + * Checks if the given value matches credit card regexp. + */ + creditCard(value: any): boolean; + + /** + * Checks if the given value matches alpha numeric regexp. + */ + alphaNumeric(value: any): boolean; + + /** + * Checks if the given value matches time string regexp. + */ + timeString(value: any): boolean; + + /** + * Checks if the given value matches date string regexp. + */ + dateString(value: any): boolean; + + /** + * Checks if the given value matches US zip code regexp. + */ + usZipCode(value: any): boolean; + + /** + * Checks if the given value matches Canada postal code regexp. + */ + caPostalCode(value: any): boolean; + + /** + * Checks if the given value matches UK post code regexp. + */ + ukPostCode(value: any): boolean; + + /** + * Checks if the given value matches North American numbering plan phone regexp. + */ + nanpPhone(value: any): boolean; + + /** + * Checks if the given value matches extensible provisioning protocol phone regexp. + */ + eppPhone(value: any): boolean; + + /** + * Checks if the given value matches social security number regexp. + */ + socialSecurityNumber(value: any): boolean; + + /** + * Checks if the given value matches affirmative regexp. + */ + affirmative(value: any): boolean; + + /** + * Checks if the given value matches hexadecimal regexp. + */ + hexadecimal(value: any): boolean; + + /** + * Checks if the given value matches hexcolor regexp. + */ + hexColor(value: any): boolean; + + /** + * Checks if the given value matches ip regexp. + */ + ip(value: any): boolean; + + /** + * Checks if the given value matches ipv4 regexp + */ + ipv4(value: any): boolean; + + /** + * Checks if the given value matches ipv6 regexp + */ + ipv6(value: any): boolean; + + //#endregion + + //#region String checks + + /** + * Checks if the given string contains a substring. + */ + include(value1: string, value2: string): boolean; + + /** + * Checks if the given string is UPPERCASE. + */ + upperCase(value: string): boolean; + + /** + * Checks if the given string is lowercase. + */ + lowerCase(value: string): boolean; + + /** + * Checks if the given string starts with substring. + */ + startWith(value1: string, value2: string): boolean; + + /** + * Checks if the given string ends with substring. + */ + endWith(value1: string, value2: string): boolean; + + /** + * Checks if the given string is capitalized. + */ + capitalized(value: string): boolean; + + /** + * Checks if the given string is palindrome. + */ + palindrome(value: string): boolean; + + //#endregion + + //#region Arithmetic checks + + /** + * Checks if the given values are equal. + */ + equal(value1: any, value2: any): boolean; + + /** + * Checks if the given value is even. + */ + even(value: number): boolean; + + /** + * Checks if the given value is odd. + */ + odd(value: number): boolean; + + /** + * Checks if the given value is positive. + */ + positive(value: number): boolean; + + /** + * Checks if the given value is negative. + */ + negative(value: number): boolean; + + /** + * Checks if the given value is above minimum value. + */ + above(value: number, min: number): boolean; + + /** + * Checks if the given value is under maximum value. + */ + under(value: number, max: number): boolean; + + /** + * Checks if the given value is within minimum and maximum values. + */ + within(value: number, min: number, max: number): boolean; + + /** + * Checks if the given value is decimal. + */ + decimal(value: number): boolean; + + /** + * Checks if the given value is integer. + */ + integer(value: number): boolean; + + /** + * Checks if the given value is finite. + */ + finite(value: number): boolean; + + /** + * Checks if the given value is infinite. + */ + infinite(value: number): boolean; + + //#endregion + + //#region Object checks + + /** + * Checks if objects' property count is equal to given count. + */ + propertyCount(value: any, count: number): boolean; + + /** + * Checks if the given property is defined on object. + */ + propertyDefined(value: any, property: string): boolean; + + /** + * Checks if the given object is window object. + */ + windowObject(value: any): boolean; + + /** + * Checks if the given object is a dom node. + */ + domNode(value: any): boolean; + + //#endregion + + //#region Array checks + + /** + * Checks if the given item is in array. + */ + inArray(value: T, array: T[]): boolean; + + /** + * Checks if the given array is sorted. + */ + sorted(value: any[]): boolean; + + //#endregion + + //#region Environment checks + + /** + * Checks if current browser is ie + * @parm value Optional version number of browser + */ + ie(value?: number): boolean; + + /** + * Checks if current browser is chrome. + */ + chrome(): boolean; + + /** + * Checks if current browser is firefox. + */ + firefox(): boolean; + + /** + * Checks if current browser is opera. + */ + opera(): boolean; + + /** + * Checks if current browser is safari. + */ + safari(): boolean; + + /** + * Checks if current device has ios. + */ + ios(): boolean; + + /** + * Checks if current device is iPhone. + */ + iphone(): boolean; + + /** + * Checks if current device is iPad. + */ + ipad(): boolean; + + /** + * Checks if current device is iPod. + */ + ipod(): boolean; + + /** + * Checks if current device has Android. + */ + android(): boolean; + + /** + * Checks if current device is Android phone. + */ + androidPhone(): boolean; + + /** + * Checks if current device is Android tablet. + */ + androidTablet(): boolean; + + /** + * Checks if current device is Blackberry. + */ + blackberry(): boolean; + + /** + * Checks if current device is Windows phone. + */ + windowsPhone(): boolean; + + /** + * Checks if current device is Windows tablet. + */ + windowsTablet(): boolean; + + /** + * Checks if current OS is Windows. + */ + windows(): boolean; + + /** + * Checks if current OS is Mac OS X. + */ + mac(): boolean; + + /** + * Checks if current OS is linux. + */ + linux(): boolean; + + /** + * Checks if current device is desktop. + */ + desktop(): boolean; + + /** + * Checks if current device is mobile. + */ + mobile(): boolean; + + /** + * Checks if current device is tablet. + */ + tablet(): boolean; + + /** + * Checks if current device is online. + */ + online(): boolean; + + /** + * Checks if current device is offline. + */ + offline(): boolean; + + //#endregion + + //#region Time checks + + /** + * Checks if the given date object indicate today. + */ + today(value: Date): boolean; + + /** + * Checks if the given date object indicate yesterday. + */ + yesterday(value: Date): boolean; + + /** + * Checks if the given date object indicate tomorrow. + */ + tomorrow(value: Date): boolean; + + /** + * Checks if the given date object indicate past. + */ + past(value: Date): boolean; + + /** + * Checks if the given date object indicate future. + */ + future(value: Date): boolean; + + /** + * Checks if the given date objects' day equal given dayString parameter. + */ + day(value: Date, dayString: string): boolean; + + /** + * Checks if the given date objects' month equal given monthString parameter. + */ + month(value: Date, monthString: string): boolean; + + /** + * Checks if the given date objects' year equal given yearNumber parameter. + */ + year(value: Date, yearNumber: number): boolean; + + /** + * Checks if the given year number is a leap year + */ + leapYear(value: number): boolean; + + /** + * Checks if the given date objects' day is weekend. + */ + weekend(value: Date): boolean; + + /** + * Checks if the given date objects' day is weekday. + */ + weekday(value: Date): boolean; + + /** + * Checks if date is within given range. + */ + inDateRange(value: Date, start: Date, end: Date): boolean; + + /** + * Checks if the given date is between now and 7 days ago. + */ + inLastWeek(value: Date): boolean; + + /** + * Checks if the given date is between now and a month ago. + */ + inLastMonth(value: Date): boolean; + + /** + * Checks if the given date is between now and a year ago. + */ + inLastYear(value: Date): boolean; + + /** + * Checks if the given date is between now and 7 days later. + */ + inNextWeek(value: Date): boolean; + + /** + * Checks if the given date is between now and a month later. + */ + inNextMonth(value: Date): boolean; + + /** + * Checks if the given date is between now and a year later. + */ + inNextYear(value: Date): boolean; + + /** + * Checks if the given date is in the parameter quarter. + */ + quarterOfYear(value: Date, quarter: number): boolean; + + /** + * Checks if the given date is in daylight saving time. + */ + dayLightSavingTime(value: Date): boolean; + + //#endregion + +} + +interface IsStaticApi { + + //#region Type checks + + /** + * Checks if the given value type is arguments. + */ + arguments(...value: any[]): boolean; + + /** + * Checks if the given value type is arguments. + */ + arguments(value: any[]): boolean; + + /** + * Checks if the given value type is array. + */ + array(...value: any[]): boolean; + + /** + * Checks if the given value type is array. + */ + array(value: any[]): boolean; + + /** + * Checks if the given value type is boolean. + */ + boolean(...value: any[]): boolean; + + /** + * Checks if the given value type is boolean. + */ + boolean(value: any[]): boolean; + + /** + * Checks if the given value type is date. + */ + date(...value: any[]): boolean; + + /** + * Checks if the given value type is date. + */ + date(value: any[]): boolean; + + /** + * Checks if the given value type is error. + */ + error(...value: any[]): boolean; + + /** + * Checks if the given value type is error. + */ + error(value: any[]): boolean; + + /** + * Checks if the given value type is function. + */ + function(...value: any[]): boolean; + + /** + * Checks if the given value type is function. + */ + function(value: any[]): boolean; + + /** + * Checks if the given value type is NaN. + */ + nan(...value: any[]): boolean; + + /** + * Checks if the given value type is NaN. + */ + nan(value: any[]): boolean; + + /** + * Checks if the given value type is null. + */ + null(...value: any[]): boolean; + + /** + * Checks if the given value type is null. + */ + null(value: any[]): boolean; + + /** + * Checks if the given value type is number. + */ + number(...value: any[]): boolean; + + /** + * Checks if the given value type is number. + */ + number(value: any[]): boolean; + + /** + * Checks if the given value type is object. + */ + object(...value: any[]): boolean; + + /** + * Checks if the given value type is object. + */ + object(value: any[]): boolean; + + /** + * Checks if the given value type is pure json object. + */ + json(...value: any[]): boolean; + + /** + * Checks if the given value type is pure json object. + */ + json(value: any[]): boolean; + + /** + * Checks if the given value type is RegExp. + */ + regexp(...value: any[]): boolean; + + /** + * Checks if the given value type is RegExp. + */ + regexp(value: any[]): boolean; + + /** + * Checks if the given value type is string. + */ + string(...value: any[]): boolean; + + /** + * Checks if the given value type is string. + */ + string(value: any[]): boolean; + + /** + * Checks if the given value type is char. + */ + char(...value: any[]): boolean; + + /** + * Checks if the given value type is char. + */ + char(value: any[]): boolean; + + /** + * Checks if the given value type is undefined. + */ + undefined(...value: any[]): boolean; + + /** + * Checks if the given value type is undefined. + */ + undefined(value: any[]): boolean; + + //#endregion + + //#region Presence checks + + /** + * Checks if the given value is empty. + */ + empty(...value: any[]): boolean; + + /** + * Checks if the given value is empty. + */ + empty(value: any[]): boolean; + + /** + * Checks if the given value is existy. (not null or undefined) + */ + existy(...value: any[]): boolean; + + /** + * Checks if the given value is existy. (not null or undefined) + */ + existy(value: any[]): boolean; + + /** + * Checks if the given value is truthy. (existy and not false) + */ + truthy(...value: any[]): boolean; + + /** + * Checks if the given value is truthy. (existy and not false) + */ + truthy(value: any[]): boolean; + + /** + * Checks if the given value is falsy. + */ + falsy(...value: any[]): boolean; + + /** + * Checks if the given value is falsy. + */ + falsy(value: any[]): boolean; + + /** + * Checks if the given value is space. + */ + space(...value: any[]): boolean; + + /** + * Checks if the given value is space. + */ + space(value: any[]): boolean; + + //#endregion + + //#region RegExp checks + + /** + * Checks if the given value matches url regexp. + */ + url(...value: any[]): boolean; + + /** + * Checks if the given value matches url regexp. + */ + url(value: any[]): boolean; + + /** + * Checks if the given value matches email regexp. + */ + email(...value: any[]): boolean; + + /** + * Checks if the given value matches email regexp. + */ + email(value: any[]): boolean; + + /** + * Checks if the given value matches credit card regexp. + */ + creditCard(...value: any[]): boolean; + + /** + * Checks if the given value matches credit card regexp. + */ + creditCard(value: any[]): boolean; + + /** + * Checks if the given value matches alpha numeric regexp. + */ + alphaNumeric(...value: any[]): boolean; + + /** + * Checks if the given value matches alpha numeric regexp. + */ + alphaNumeric(value: any[]): boolean; + + /** + * Checks if the given value matches time string regexp. + */ + timeString(...value: any[]): boolean; + + /** + * Checks if the given value matches time string regexp. + */ + timeString(value: any[]): boolean; + + /** + * Checks if the given value matches date string regexp. + */ + dateString(...value: any[]): boolean; + + /** + * Checks if the given value matches date string regexp. + */ + dateString(value: any[]): boolean; + + /** + * Checks if the given value matches US zip code regexp. + */ + usZipCode(...value: any[]): boolean; + + /** + * Checks if the given value matches US zip code regexp. + */ + usZipCode(value: any[]): boolean; + + /** + * Checks if the given value matches Canada postal code regexp. + */ + caPostalCode(...value: any[]): boolean; + + /** + * Checks if the given value matches Canada postal code regexp. + */ + caPostalCode(value: any[]): boolean; + + /** + * Checks if the given value matches UK post code regexp. + */ + ukPostCode(...value: any[]): boolean; + + /** + * Checks if the given value matches UK post code regexp. + */ + ukPostCode(value: any[]): boolean; + + /** + * Checks if the given value matches North American numbering plan phone regexp. + */ + nanpPhone(...value: any[]): boolean; + + /** + * Checks if the given value matches North American numbering plan phone regexp. + */ + nanpPhone(value: any[]): boolean; + + /** + * Checks if the given value matches extensible provisioning protocol phone regexp. + */ + eppPhone(...value: any[]): boolean; + + /** + * Checks if the given value matches extensible provisioning protocol phone regexp. + */ + eppPhone(value: any[]): boolean; + + /** + * Checks if the given value matches social security number regexp. + */ + socialSecurityNumber(...value: any[]): boolean; + + /** + * Checks if the given value matches social security number regexp. + */ + socialSecurityNumber(value: any[]): boolean; + + /** + * Checks if the given value matches affirmative regexp. + */ + affirmative(...value: any[]): boolean; + + /** + * Checks if the given value matches affirmative regexp. + */ + affirmative(value: any[]): boolean; + + /** + * Checks if the given value matches hexadecimal regexp. + */ + hexadecimal(...value: any[]): boolean; + + /** + * Checks if the given value matches hexadecimal regexp. + */ + hexadecimal(value: any[]): boolean; + + /** + * Checks if the given value matches hexcolor regexp. + */ + hexColor(...value: any[]): boolean; + + /** + * Checks if the given value matches hexcolor regexp. + */ + hexColor(value: any[]): boolean; + + /** + * Checks if the given value matches ip regexp. + */ + ip(...value: any[]): boolean; + + /** + * Checks if the given value matches ip regexp. + */ + ip(value: any[]): boolean; + + /** + * Checks if the given value matches ipv4 regexp. + */ + ipv4(...value: any[]): boolean; + + /** + * Checks if the given value matches ipv4 regexp. + */ + ipv4(value: any[]): boolean; + + /** + * Checks if the given value matches ipv6 regexp. + */ + ipv6(...value: any[]): boolean; + + /** + * Checks if the given value matches ipv6 regexp. + */ + ipv6(value: any[]): boolean; + + //#endregion + + //#region String checks + + /** + * Checks if the given string is UPPERCASE. + */ + upperCase(...value: string[]): boolean; + + /** + * Checks if the given string is UPPERCASE. + */ + upperCase(value: string[]): boolean; + + /** + * Checks if the given string is lowercase. + */ + lowerCase(...value: string[]): boolean; + + /** + * Checks if the given string is lowercase. + */ + lowerCase(value: string[]): boolean; + + /** + * Checks if the given string is capitalized. + */ + capitalized(...value: string[]): boolean; + + /** + * Checks if the given string is capitalized. + */ + capitalized(value: string[]): boolean; + + /** + * Checks if the given string is palindrome + */ + palindrome(...value: string[]): boolean; + + /** + * Checks if the given string is palindrome + */ + palindrome(value: string[]): boolean; + + //#endregion + + //#region Arithmetic checks + + /** + * Checks if the given value is even. + */ + even(...value: number[]): boolean; + + /** + * Checks if the given value is even. + */ + even(value: number[]): boolean; + + /** + * Checks if the given value is odd. + */ + odd(...value: number[]): boolean; + + /** + * Checks if the given value is odd. + */ + odd(value: number[]): boolean; + + /** + * Checks if the given value is positive. + */ + positive(...value: number[]): boolean; + + /** + * Checks if the given value is positive. + */ + positive(value: number[]): boolean; + + /** + * Checks if the given value is negative. + */ + negative(...value: number[]): boolean; + + /** + * Checks if the given value is negative. + */ + negative(value: number[]): boolean; + + /** + * Checks if the given value is decimal. + */ + decimal(...value: number[]): boolean; + + /** + * Checks if the given value is decimal. + */ + decimal(value: number[]): boolean; + + /** + * Checks if the given value is integer. + */ + integer(...value: number[]): boolean; + + /** + * Checks if the given value is integer. + */ + integer(value: number[]): boolean; + + /** + * Checks if the given value is finite. + */ + finite(...value: number[]): boolean; + + /** + * Checks if the given value is finite. + */ + finite(value: number[]): boolean; + + /** + * Checks if the given value is infinite. + */ + infinite(...value: number[]): boolean; + + /** + * Checks if the given value is infinite. + */ + infinite(value: number[]): boolean; + + //#endregion + + //#region Object checks + + /** + * Checks if the given object is window object. + */ + windowObject(...value: any[]): boolean; + + /** + * Checks if the given object is window object. + */ + windowObject(value: any[]): boolean; + + /** + * Checks if the given object is a dom node. + */ + domNode(...value: any[]): boolean; + + /** + * Checks if the given object is a dom node. + */ + domNode(value: any[]): boolean; + + //#endregion + + //#region Array checks + + /** + * Checks if the given array is sorted. + */ + sorted(...value: number[][]): boolean; + + /** + * Checks if the given array is sorted. + */ + sorted(value: number[][]): boolean; + + //#endregion + + //#region Time checks + + /** + * Checks if the given date object indicate today. + */ + today(...value: Date[]): boolean; + + /** + * Checks if the given date object indicate today. + */ + today(value: Date[]): boolean; + + /** + * Checks if the given date object indicate yesterday. + */ + yesterday(...value: Date[]): boolean; + + /** + * Checks if the given date object indicate yesterday. + */ + yesterday(value: Date[]): boolean; + + /** + * Checks if the given date object indicate tomorrow. + */ + tomorrow(...value: Date[]): boolean; + + /** + * Checks if the given date object indicate tomorrow. + */ + tomorrow(value: Date[]): boolean; + + /** + * Checks if the given date object indicate past. + */ + past(...value: Date[]): boolean; + + /** + * Checks if the given date object indicate past. + */ + past(value: Date[]): boolean; + + /** + * Checks if the given date object indicate future. + */ + future(...value: Date[]): boolean; + + /** + * Checks if the given date object indicate future. + */ + future(value: Date[]): boolean; + + /** + * Checks if the given year number is a leap year + */ + leapYear(...value: number[]): boolean; + + /** + * Checks if the given year number is a leap year + */ + leapYear(value: number[]): boolean; + + /** + * Checks if the given date objects' day is weekend. + */ + weekend(...value: Date[]): boolean; + + /** + * Checks if the given date objects' day is weekend. + */ + weekend(value: Date[]): boolean; + + /** + * Checks if the given date objects' day is weekday. + */ + weekday(...value: Date[]): boolean; + + /** + * Checks if the given date objects' day is weekday. + */ + weekday(value: Date[]): boolean; + + //#endregion +} + +interface Is extends IsStatic { + + not: IsStatic; + any: IsStaticApi; + all: IsStaticApi; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'url'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'email'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'creditCard'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'alphaNumeric'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'timeString'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'dateString'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'usZipCode'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'caPostalCode'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'nanpPhone'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'eppPhone'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'affirmative'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'hexadecimal'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'hexColor'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'ip'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: 'ipv6'): boolean; + + /** + * Override RegExps if you think they suck. + */ + setRegexp(value: RegExp, regexp: string): boolean; + + /** + * Change namespace of library to prevent name collisions. + */ + setNamespace(): Is; +} + +declare var is: Is; + +declare module 'is' { + export = is; +} \ No newline at end of file