is.js
This is a general-purpose check library.
- No dependencies
- AMD, Node & browser ready
Usage:
Node.js:
npm install is_js
Bower:
bower install is_js
Build:
npm run build
Test:
npm test
Contributing:
Thanks for considering to contribute. Check here
Contributors:
Many thanks to our contributors: https://github.com/arasatasaygin/is.js/graphs/contributors
Type checks
is.arguments(value:any)
Checks if the given value type is arguments.
interfaces: not, all, any
var { return arguments;};var arguments = ; isargumentsarguments; true isnotargumentsfoo: 'bar'; true isallargumentsarguments 'bar'; false isanyarguments'foo' arguments; true // 'all' and 'any' interfaces can also take array parameterisallargumentsarguments 'foo' 'bar'; false
is.array(value:any)
Checks if the given value type is array.
interfaces: not, all, any
is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.boolean(value:any)
Checks if the given value type is boolean.
interfaces: not, all, any
is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.date(value:any)
Checks if the given value type is date.
interfaces: not, all, any
is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.domNode(value:any)
Checks if the given object is a dom node.
interfaces: not, all, any
var obj = document;is; true is; false isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.error(value:any)
Checks if the given value type is error.
interfaces: not, all, any
is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.function(value:any)
Checks if the given value type is function.
interfaces: not, all, any
is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.nan(value:any)
Checks if the given value type is NaN.
interfaces: not, all, any
is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.null(value:any)
Checks if the given value type is null.
interfaces: not, all, any
is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.number(value:any)
Checks if the given value type is number.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.object(value:any)
Checks if the given value type is object.
interfaces: not, all, any
isobjectfoo: 'bar'; true // functions are also returning as trueisobjecttoString; true isnotobject'foo'; true isallobject{} 1; false isanyobject{} 2; true // 'all' and 'any' interfaces can also take array parameterisallobject{} ; true
is.json(value:any)
Checks if the given value type is pure json object.
interfaces: not, all, any
is; true // functions are returning as falseis; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; true
is.regexp(value:any)
Checks if the given value type is RegExp.
interfaces: not, all, any
is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.string(value:any)
Checks if the given value type is string.
interfaces: not, all, any
is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.char(value:any)
Checks if the given value type is char.
interfaces: not, all, any
is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; true
is.undefined(value:any)
Checks if the given value type is undefined.
interfaces: not, all, any
isundefinedundefined; true isnotundefinednull; true isallundefinedundefined 1; false isanyundefinedundefined 2; true // 'all' and 'any' interfaces can also take array parameterisallundefined{} undefined; false
is.sameType(value:any, other:any)
Checks if the given value types are same type.
interface: not
is; true is; false isnot; false
is.windowObject(value:any)
Checks if the given object is window object.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
Presence checks
is.empty(value:array|object|string)
Checks if the given value is empty.
interfaces: not, all, any
is; true is; true is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.existy(value:any)
Checks if the given value is existy. (not null or undefined)
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; true
is.truthy(value:any)
Checks if the given value is truthy. (existy and not false)
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; true
is.falsy(value:any)
Checks if the given value is falsy.
interfaces: not, all, any
is; true is; true isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.space(value:any)
Checks if the given value is space.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
RegExp checks
is.url(value:any)
Checks if the given value matches url regexp.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.email(value:any)
Checks if the given value matches email regexp.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.creditCard(value:any)
Checks if the given value matches credit card regexp.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.alphaNumeric(value:any)
Checks if the given value matches alpha numeric regexp.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.timeString(value:any)
Checks if the given value matches time string regexp.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.dateString(value:any)
Checks if the given value matches date string regexp.
interfaces: not, all, any
is; true is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.usZipCode(value:any)
Checks if the given value matches US zip code regexp.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.caPostalCode(value:any)
Checks if the given value matches Canada postal code regexp.
interfaces: not, all, any
is; true is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.ukPostCode(value:any)
Checks if the given value matches UK post code regexp.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.nanpPhone(value:any)
Checks if the given value matches North American numbering plan phone regexp.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.eppPhone(value:any)
Checks if the given value matches extensible provisioning protocol phone regexp.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.socialSecurityNumber(value:any)
Checks if the given value matches social security number regexp.
interfaces: not, all, any
is; true is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.affirmative(value:any)
Checks if the given value matches affirmative regexp.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; true
is.hexadecimal(value:any)
Checks if the given value matches hexadecimal regexp.
interfaces: not, all, any
is; true is; true is; false isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; true
is.hexColor(value:any)
Checks if the given value matches hexcolor regexp.
interfaces: not, all, any
is; true is; false isnot; true isall; true isany; false // 'all' and 'any' interfaces can also take array parameterisall; true
is.ip(value:any)
Checks if the given value matches ip regexp
interfaces: not, all, any
is; true is; false isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; true
is.ipv4(value:any)
Checks if the given value matches ipv4 regexp
interfaces: not, all, any
is; true is; false isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.ipv6(value:any)
Checks if the given value matches ipv6 regexp
interfaces: not, all, any
is; true is; true isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
String checks
is.include(value:string, target:string)
Checks if the given string contains a substring.
interface: not
is; true is; false isnot; true
is.upperCase(value:string)
Checks if the given string is UPPERCASE.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; true
is.lowerCase(value:string)
Checks if the given string is lowercase.
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; true
is.startWith(value:string, target:string)
Checks if the given string starts with substring.
interface: not
is; true is; false isnot; true
is.endWith(value:string, target:string)
Checks if the given string ends with substring.
interfaces: not
is; true is; false isnot; true is; true
is.capitalized(value:string)
Checks if the given string is capitalized.
interfaces: not, all, any
is; true is; false isnot; true isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.palindrome(value:string)
Checks if the given string is palindrome.
interfaces: not, all, any
is; true is; true is; false isnot; true isnot; false isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
Arithmetic checks
is.equal(value:any, other:any)
Checks if the given values are equal.
interfaces: not
is; true is; true is; true isnot; true
is.even(value:number)
Checks if the given value is even.
interfaces: not, all, any
is; true isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.odd(value:number)
Checks if the given value is odd.
interfaces: not, all, any
is; true isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.positive(value:number)
Checks if the given value is positive.
interfaces: not, all, any
is; true isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.negative(value:number)
Checks if the given value is negative.
interfaces: not, all, any
is; true isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.above(value:number, min:number)
Checks if the given value is above minimum value.
interface: not
isabove41 30; true isnotabove42 50; true
is.under(value:number, max:number)
Checks if the given value is under maximum value.
interface: not
is; true isnot; true
is.within(value:number, min:number, max:number)
Checks if the given value is within minimum and maximum values.
interface: not
is; true isnot; true
is.decimal(value:number)
Checks if the given value is decimal.
interfaces: not, all, any
is; true isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.integer(value:number)
Checks if the given value is integer.
interfaces: not, all, any
is; true isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.finite(value:number)
Checks if the given value is finite.
interfaces: not, all, any
is; true isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.infinite(value:number)
Checks if the given value is infinite.
interfaces: not, all, any
is; true isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
Object checks
is.propertyCount(value:object, count:number)
Checks if objects' property count is equal to given count.
interface: not
is; true is; false isnot; true
is.propertyDefined(value:object, property:string)
Checks if the given property is defined on object.
interface: not
is; true is; false isnot; true
Array checks
is.inArray(value:any, array)
Checks if the given item is in array?
interface: not
is; true is; false isnot; true
is.sorted(value:array, sign:string)
Checks if the given array is sorted. Sign is optional parameter.
interfaces: not, all, any
is; true is; false is; true is; true is; true is; true is; false isnot; true isnot; false isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
Environment checks
Environment checks are not available as node module.
is.ie(range:number|string)
Checks if current browser is ie. Parameter is optional version range (or number) of browser.
interface: not
is; true if current browser is ie isnot; false if current browser is ie // also supports version numberis; true if current version of ie is 10 is; true if current version of ie is greater than or equal to 10 isnot; true if current version of ie is not less than 9
is.chrome(range:number|string)
Checks if current browser is chrome. Parameter is optional version range (or number) of browser.
interface: not
is; true if current browser is chrome isnot; false if current browser is chrome // also supports version numberis; true if current version of chrome is 50 is; true if current version of chrome is greater than or equal to 40 isnot; true if current version of chrome is not less than 30
is.firefox(range:number|string)
Checks if current browser is firefox. Parameter is optional version range (or number) of browser.
interface: not
is; true if current browser is firefox isnot; false if current browser is firefox // also supports version numberis; true if current version of firefox is 41 is; true if current version of firefox is greater than or equal to 40 isnot; true if current version of firefox is not less than 30
is.edge(range:number|string)
Checks if current browser is edge. Parameter is optional version range (or number) of browser.
interface: not
is; true if current browser is edge isnot; false if current browser is edge // also supports version numberis; true if current version of edge is 13 is; true if current version of edge is greater than or equal to 12 isnot; true if current version of edge is not less than 13
is.opera(range:number|string)
Checks if current browser is opera. Parameter is optional version range (or number) of browser.
interface: not
is; true if current browser is opera isnot; false if current browser is opera // also supports version numberis; true if current version of opera is 36 is; true if current version of opera is greater than or equal to 35 isnot; true if current version of opera is not less than 20
is.safari(range:number|string)
Checks if current browser is safari. Parameter is optional version range (or number) of browser.
interface: not
is; true if current browser is safari isnot; false if current browser is safari // also supports version numberis; true if current version of safari is 9 is; true if current version of safari is greater than or equal to 8 isnot; true if current version of safari is not less than 7
is.phantom(range:number|string)
Checks if current browser is phantomjs. Parameter is optional version range (or number) of browser.
interface: not
is; true if current browser is phantomjs isnot; false if current browser is phantomjs // also supports version numberis; true if current version of phantom is 2 is; true if current version of phantomjs is greater than or equal to 1 isnot; true if current version of phantomjs is not less than 2
is.ios()
Checks if current device has ios.
interface: not
is; true if current device is iPhone iPad or iPod isnot; true if current device is not iPhone iPad or iPod
is.iphone(range:number|string)
Checks if current device is iPhone. Parameter is optional version range (or number) of browser.
interface: not
is; true if current device is iPhone isnot; true if current device is not iPhone // also supports version numberis; true if current version of iPhone is 9 is; true if current version of iPhone is greater than or equal to 7 isnot; true if current version of iPhone is not less than 8
is.ipad(range:number|string)
Checks if current device is iPad.
interface: not
is; true if current device is iPad isnot; true if current device is not iPad // also supports version numberis; true if current version of iPad is 9 is; true if current version of iPad is greater than or equal to 7 isnot; true if current version of iPad is not less than 8
is.ipod(range:number|string)
Checks if current device is iPod.
interface: not
is; true if current device is iPod isnot; true if current device is not iPod // also supports version numberis; true if current version of iPod is 7 is; true if current version of iPod is greater than or equal to 5 isnot; true if current version of iPod is not less than 5
is.android()
Checks if current device has Android.
interface: not
is; true if current device has Android OS isnot; true if current device has not Android OS
is.androidPhone()
Checks if current device is Android phone.
interface: not
is; true if current device is Android phone isnot; true if current device is not Android phone
is.androidTablet()
Checks if current device is Android tablet.
interface: not
is; true if current device is Android tablet isnot; true if current device is not Android tablet
is.blackberry()
Checks if current device is Blackberry.
interface: not
is; true if current device is Blackberry isnot; true if current device is not Blackberry
is.windowsPhone()
Checks if current device is Windows phone.
interface: not
is; true if current device is Windows phone isnot; true if current device is not Windows Phone
is.windowsTablet()
Checks if current device is Windows tablet.
interface: not
is; true if current device is Windows tablet isnot; true if current device is not Windows tablet
is.windows()
Checks if current OS is Windows.
interface: not
is; true if current OS is Windows isnot; true if current OS is not Windows
is.mac()
Checks if current OS is Mac OS X.
interface: not
is; true if current OS is Mac OS X isnot; true if current OS is not Mac OS X
is.linux()
Checks if current OS is linux.
interface: not
is; true if current OS is linux isnot; true if current OS is not linux
is.desktop()
Checks if current device is desktop.
interface: not
is; true if current device is desktop isnot; true if current device is not desktop
is.mobile()
Checks if current device is mobile.
interface: not iPhone, iPod, Android Phone, Windows Phone, Blackberry.
is; true if current device is mobile isnot; true if current device is not mobile
is.tablet()
Checks if current device is tablet.
interface: not iPad, Android Tablet, Windows Tablet
is; true if current device is tablet isnot; true if current device is not tablet
is.online()
Checks if current device is online.
interface: not
is; true if current device is online isnot; true if current device is not online
is.offline()
Checks if current device is offline.
interface: not
is; true if current device is offline isnot; true if current device is not offline
is.touchDevice()
Checks if current device supports touch.
interface: not
is; true if current device supports touch isnot; true if current device does not support touch
Time checks
is.today(value:date)
Checks if the given date object indicate today.
interfaces: not, all, any
var today = ;is; true var yesterday = ;is; false isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.yesterday(value:date)
Checks if the given date object indicate yesterday.
interfaces: not, all, any
var today = ;is; false var yesterday = ;is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.tomorrow(value:date)
Checks if the given date object indicate tomorrow.
interfaces: not, all, any
var today = ;is; false var tomorrow = ;is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.past(value:date)
Checks if the given date object indicate past.
interfaces: not, all, any
var yesterday = ;var tomorrow = ; is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.future(value:date)
Checks if the given date object indicate future.
interfaces: not, all, any
var yesterday = ;var tomorrow = ; is; false is; true isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.day(value:date, day:string)
Checks if the given date objects' day equal given dayString parameter.
interface: not
var mondayObj = '01/26/2015';var tuesdayObj = '01/27/2015';is; true is; false isnot; true
is.month(value:date, month:string)
Checks if the given date objects' month equal given monthString parameter.
interface: not
var januaryObj = '01/26/2015';var februaryObj = '02/26/2015';is; true is; false isnot; true
is.year(value:date, year:number)
Checks if the given date objects' year equal given yearNumber parameter.
interface: not
var year2015 = '01/26/2015';var year2016 = '01/26/2016';is; true is; false isnot; true
is.leapYear(value:number)
Checks if the given year number is a leap year
interfaces: not, all, any
is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; true
is.weekend(value:date)
Checks if the given date objects' day is weekend.
interfaces: not, all, any
var monday = '01/26/2015';var sunday = '01/25/2015';var saturday = '01/24/2015';is; true is; false isnot; true isall; true isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.weekday(value:date)
Checks if the given date objects' day is weekday.
interfaces: not, all, any
var monday = '01/26/2015';var sunday = '01/25/2015';var saturday = '01/24/2015';is; true is; false isnot; true isall; false isany; true // 'all' and 'any' interfaces can also take array parameterisall; false
is.inDateRange(value:date, start:date, end:date)
Checks if date is within given range.
interface: not
var saturday = '01/24/2015';var sunday = '01/25/2015';var monday = '01/26/2015';is; true is; false isnot; true
is.inLastWeek(value:date)
Checks if the given date is between now and 7 days ago.
interface: not
var twoDaysAgo = ;var nineDaysAgo = ;is; true is; false isnot; true
is.inLastMonth(value:date)
Checks if the given date is between now and a month ago.
interface: not
var tenDaysAgo = ;var fortyDaysAgo = ;is; true is; false isnot; true
is.inLastYear(value:date)
Checks if the given date is between now and a year ago.
interface: not
var twoMonthsAgo = ;var thirteenMonthsAgo = ;is; true is; false isnot; true
is.inNextWeek(value:date)
Checks if the given date is between now and 7 days later.
interface: not
var twoDaysLater = ;var nineDaysLater = ;is; true is; false isnot; true
is.inNextMonth(value:date)
Checks if the given date is between now and a month later.
interface: not
var tenDaysLater = ;var fortyDaysLater = ;is; true is; false isnot; true
is.inNextYear(value:date)
Checks if the given date is between now and a year later.
interface: not
var twoMonthsLater = ;var thirteenMonthsLater = ;is; true is; false isnot; true
is.quarterOfYear(value:date, quarter:number)
Checks if the given date is in the parameter quarter.
interface: not
var firstQuarter = '01/26/2015';var secondQuarter = '05/26/2015';is; true is; false isnot; true
is.dayLightSavingTime(value:date)
Checks if the given date is in daylight saving time.
interface: not
// For Turkey Time Zonevar january1 = '01/01/2015';var june1 = '06/01/2015'; is; true is; false isnot; true
Configuration methods
is.setNamespace()
Change namespace of library to prevent name collisions.
var customName = is;customName; true
is.setRegexp(value:regexp, name:string)
Override RegExps if you think they suck.
is; true is;is; true