Repository: arasatasaygin/is.js
Branch: master
Commit: 45d1c9fe37bb
Files: 15
Total size: 131.9 KB
Directory structure:
gitextract_38eizkuu/
├── .editorconfig
├── .eslintignore
├── .eslintrc.js
├── .gitattributes
├── .gitignore
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── bower.json
├── is.js
├── package.json
└── test/
├── .eslintrc.js
├── index.html
└── test.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .editorconfig
================================================
# EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs.
# See http://editorconfig.org for details.
# This is the top-most .editorconfig file; do not search in parent directories.
root = true
# All files.
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
# Markdown.
[*.md]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2
# Configuration.
[*.{json,yml}]
indent_style = space
indent_size = 2
================================================
FILE: .eslintignore
================================================
is.min.js
================================================
FILE: .eslintrc.js
================================================
module.exports = {
extends: 'eslint:recommended',
env: {
browser: true,
node: true,
amd: true
},
globals: {
DocumentTouch: false
},
rules: {
indent: ['error', 4]
}
};
================================================
FILE: .gitattributes
================================================
* text=auto
================================================
FILE: .gitignore
================================================
.DS_Store
*.log
bower_components
node_modules
================================================
FILE: .travis.yml
================================================
language: node_js
sudo: false
node_js:
- "4"
- "6"
cache:
directories:
- $HOME/.npm
git:
depth: 10
branches:
only:
- master
before_install:
- "nvm use $TRAVIS_NODE_VERSION"
- "npm set loglevel error"
- "npm set progress false"
- "npm i -g npm@\"^2.0.0\""
================================================
FILE: CONTRIBUTING.md
================================================
# Contributing to is.js
## General Guidelines
Thanks for considering to contribute is.js
- Please don’t re-build minified library on your pull request.
- Be sure you’ve added tests if you are sending a new feature.
- I’ll take care of the documentation and github page.
Cheers.
## Feature Requests
Feature requests should be submitted in the
[issue tracker](https://github.com/arasatasaygin/is.js/issues), with a description of
the expected behavior & use case, where they’ll remain closed until sufficient interest,
[e.g. :+1: reactions](https://help.github.com/articles/about-discussions-in-issues-and-pull-requests/),
has been [shown by the community](https://github.com/arasatasaygin/is.js/issues?q=label%3A%22votes+needed%22+sort%3Areactions-%2B1-desc).
Before submitting a request, please search for similar ones in the
[closed issues](https://github.com/arasatasaygin/is.js/issues?q=is%3Aissue+is%3Aclosed+label%3Aenhancement).
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2014-2016 Aras Atasaygin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
is.js
=====
[](http://js.org)
#### 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](CONTRIBUTING.md)
#### 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
```javascript
var getArguments = function() {
return arguments;
};
var arguments = getArguments();
is.arguments(arguments);
=> true
is.not.arguments({foo: 'bar'});
=> true
is.all.arguments(arguments, 'bar');
=> false
is.any.arguments(['foo'], arguments);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.arguments([arguments, 'foo', 'bar']);
=> false
```
is.array(value:any)
-------------------
#### Checks if the given value type is array.
interfaces: not, all, any
```javascript
is.array(['foo', 'bar', 'baz']);
=> true
is.not.array({foo: 'bar'});
=> true
is.all.array(['foo'], 'bar');
=> false
is.any.array(['foo'], 'bar');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.array([[1, 2], 'foo', 'bar']);
=> false
```
is.boolean(value:any)
---------------------
#### Checks if the given value type is boolean.
interfaces: not, all, any
```javascript
is.boolean(true);
=> true
is.not.boolean({foo: 'bar'});
=> true
is.all.boolean(true, 'bar');
=> false
is.any.boolean(true, 'bar');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.boolean([true, 'foo', 'bar']);
=> false
```
is.date(value:any)
------------------
#### Checks if the given value type is date.
interfaces: not, all, any
```javascript
is.date(new Date());
=> true
is.not.date({foo: 'bar'});
=> true
is.all.date(new Date(), 'bar');
=> false
is.any.date(new Date(), 'bar');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.date([new Date(), 'foo', 'bar']);
=> false
```
is.domNode(value:any)
-----------------------------
#### Checks if the given object is a dom node.
interfaces: not, all, any
```javascript
var obj = document.createElement('div');
is.domNode(obj);
=> true
is.domNode({nope: 'nope'});
=> false
is.not.domNode({});
=> true
is.all.domNode(obj, obj);
=> true
is.any.domNode(obj, {nope: 'nope'});
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.domNode([obj, {nope: 'nope'}]);
=> false
```
is.error(value:any)
-------------------
#### Checks if the given value type is error.
interfaces: not, all, any
```javascript
is.error(new Error());
=> true
is.not.error({foo: 'bar'});
=> true
is.all.error(new Error(), 'bar');
=> false
is.any.error(new Error(), 'bar');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.error([new Error(), 'foo', 'bar']);
=> false
```
is.function(value:any)
----------------------
#### Checks if the given value type is function.
interfaces: not, all, any
```javascript
is.function(toString);
=> true
is.not.function({foo: 'bar'});
=> true
is.all.function(toString, 'bar');
=> false
is.any.function(toString, 'bar');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.function([toString, 'foo', 'bar']);
=> false
```
is.nan(value:any)
-----------------
#### Checks if the given value type is NaN.
interfaces: not, all, any
```javascript
is.nan(NaN);
=> true
is.not.nan(42);
=> true
is.all.nan(NaN, 1);
=> false
is.any.nan(NaN, 2);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.nan([NaN, 'foo', 1]);
=> false
```
is.null(value:any)
------------------
#### Checks if the given value type is null.
interfaces: not, all, any
```javascript
is.null(null);
=> true
is.not.null(42);
=> true
is.all.null(null, 1);
=> false
is.any.null(null, 2);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.null([null, 'foo', 1]);
=> false
```
is.number(value:any)
--------------------
#### Checks if the given value type is number.
interfaces: not, all, any
```javascript
is.number(42);
=> true
is.number(NaN);
=> false
is.not.number('42');
=> true
is.all.number('foo', 1);
=> false
is.any.number({}, 2);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.number([42, 'foo', 1]);
=> false
```
is.object(value:any)
--------------------
#### Checks if the given value type is object.
interfaces: not, all, any
```javascript
is.object({foo: 'bar'});
=> true
// functions are also returning as true
is.object(toString);
=> true
is.not.object('foo');
=> true
is.all.object({}, 1);
=> false
is.any.object({}, 2);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.object([{}, new Object()]);
=> true
```
is.json(value:any)
--------------------
#### Checks if the given value type is pure json object.
interfaces: not, all, any
```javascript
is.json({foo: 'bar'});
=> true
// functions are returning as false
is.json(toString);
=> false
is.not.json([]);
=> true
is.all.json({}, 1);
=> false
is.any.json({}, 2);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.json([{}, {foo: 'bar'}]);
=> true
```
is.regexp(value:any)
--------------------
#### Checks if the given value type is RegExp.
interfaces: not, all, any
```javascript
is.regexp(/test/);
=> true
is.not.regexp(['foo']);
=> true
is.all.regexp(/test/, 1);
=> false
is.any.regexp(new RegExp('ab+c'), 2);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.regexp([{}, /test/]);
=> false
```
is.string(value:any)
--------------------
#### Checks if the given value type is string.
interfaces: not, all, any
```javascript
is.string('foo');
=> true
is.not.string(['foo']);
=> true
is.all.string('foo', 1);
=> false
is.any.string('foo', 2);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.string([{}, 'foo']);
=> false
```
is.char(value:any)
--------------------
#### Checks if the given value type is char.
interfaces: not, all, any
```javascript
is.char('f');
=> true
is.not.char(['foo']);
=> true
is.all.char('f', 1);
=> false
is.any.char('f', 2);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.char(['f', 'o', 'o']);
=> true
```
is.undefined(value:any)
-----------------------
#### Checks if the given value type is undefined.
interfaces: not, all, any
```javascript
is.undefined(undefined);
=> true
is.not.undefined(null);
=> true
is.all.undefined(undefined, 1);
=> false
is.any.undefined(undefined, 2);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.undefined([{}, undefined]);
=> false
```
is.sameType(value:any, other:any)
---------------------------------
#### Checks if the given value types are same type.
interface: not
```javascript
is.sameType(42, 7);
=> true
is.sameType(42, '7');
=> false
is.not.sameType(42, 7);
=> false
```
is.windowObject(value:any)
-----------------------------
#### Checks if the given object is window object.
interfaces: not, all, any
```javascript
is.windowObject(window);
=> true
is.windowObject({nope: 'nope'});
=> false
is.not.windowObject({});
=> true
is.all.windowObject(window, {nope: 'nope'});
=> false
is.any.windowObject(window, {nope: 'nope'});
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.windowObject([window, {nope: 'nope'}]);
=> false
```
Presence checks
===============
is.empty(value:array|object|string)
-----------------------------------
#### Checks if the given value is empty.
interfaces: not, all, any
```javascript
is.empty({});
=> true
is.empty([]);
=> true
is.empty('');
=> true
is.not.empty(['foo']);
=> true
is.all.empty('', {}, ['foo']);
=> false
is.any.empty([], 42);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.empty([{}, 'foo']);
=> false
```
is.existy(value:any)
--------------------
#### Checks if the given value is existy. (not null or undefined)
interfaces: not, all, any
```javascript
is.existy({});
=> true
is.existy(null);
=> false
is.not.existy(undefined);
=> true
is.all.existy(null, ['foo']);
=> false
is.any.existy(undefined, 42);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.existy([{}, 'foo']);
=> true
```
is.truthy(value:any)
--------------------
#### Checks if the given value is truthy. (existy and not false)
interfaces: not, all, any
```javascript
is.truthy(true);
=> true
is.truthy(null);
=> false
is.not.truthy(false);
=> true
is.all.truthy(null, true);
=> false
is.any.truthy(undefined, true);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.truthy([{}, true]);
=> true
```
is.falsy(value:any)
-------------------
#### Checks if the given value is falsy.
interfaces: not, all, any
```javascript
is.falsy(false);
=> true
is.falsy(null);
=> true
is.not.falsy(true);
=> true
is.all.falsy(null, false);
=> true
is.any.falsy(undefined, true);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.falsy([false, true, undefined]);
=> false
```
is.space(value:any)
----------------------
#### Checks if the given value is space.
interfaces: not, all, any
```javascript
is.space(' ');
=> true
is.space('foo');
=> false
is.not.space(true);
=> true
is.all.space(' ', 'foo');
=> false
is.any.space(' ', true);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.space([' ', 'foo', undefined]);
=> false
```
RegExp checks
=============
is.url(value:any)
-----------------
#### Checks if the given value matches url regexp.
interfaces: not, all, any
```javascript
is.url('http://www.test.com');
=> true
is.url('foo');
=> false
is.not.url(true);
=> true
is.all.url('http://www.test.com', 'foo');
=> false
is.any.url('http://www.test.com', true);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.url(['http://www.test.com', 'foo', undefined]);
=> false
```
is.email(value:any)
-------------------
#### Checks if the given value matches email regexp.
interfaces: not, all, any
```javascript
is.email('test@test.com');
=> true
is.email('foo');
=> false
is.not.email('foo');
=> true
is.all.email('test@test.com', 'foo');
=> false
is.any.email('test@test.com', 'foo');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.email(['test@test.com', 'foo', undefined]);
=> false
```
is.creditCard(value:any)
------------------------
#### Checks if the given value matches credit card regexp.
interfaces: not, all, any
```javascript
is.creditCard(378282246310005);
=> true
is.creditCard(123);
=> false
is.not.creditCard(123);
=> true
is.all.creditCard(378282246310005, 123);
=> false
is.any.creditCard(378282246310005, 123);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.creditCard([378282246310005, 123, undefined]);
=> false
```
is.alphaNumeric(value:any)
--------------------------
#### Checks if the given value matches alpha numeric regexp.
interfaces: not, all, any
```javascript
is.alphaNumeric('alphaNu3er1k');
=> true
is.alphaNumeric('*?');
=> false
is.not.alphaNumeric('*?');
=> true
is.all.alphaNumeric('alphaNu3er1k', '*?');
=> false
is.any.alphaNumeric('alphaNu3er1k', '*?');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.alphaNumeric(['alphaNu3er1k', '*?']);
=> false
```
is.timeString(value:any)
------------------------
#### Checks if the given value matches time string regexp.
interfaces: not, all, any
```javascript
is.timeString('13:45:30');
=> true
is.timeString('90:90:90');
=> false
is.not.timeString('90:90:90');
=> true
is.all.timeString('13:45:30', '90:90:90');
=> false
is.any.timeString('13:45:30', '90:90:90');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.timeString(['13:45:30', '90:90:90']);
=> false
```
is.dateString(value:any)
------------------------
#### Checks if the given value matches date string regexp.
interfaces: not, all, any
```javascript
is.dateString('11/11/2011');
=> true
is.dateString('10-21-2012');
=> true
is.dateString('90/11/2011');
=> false
is.not.dateString('90/11/2011');
=> true
is.all.dateString('11/11/2011', '90/11/2011');
=> false
is.any.dateString('11-11-2011', '90/11/2011');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.dateString(['11/11/2011', '90/11/2011']);
=> false
```
is.usZipCode(value:any)
-----------------------
#### Checks if the given value matches US zip code regexp.
interfaces: not, all, any
```javascript
is.usZipCode('02201-1020');
=> true
is.usZipCode('123');
=> false
is.not.usZipCode('123');
=> true
is.all.usZipCode('02201-1020', '123');
=> false
is.any.usZipCode('02201-1020', '123');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.usZipCode(['02201-1020', '123']);
=> false
```
is.caPostalCode(value:any)
--------------------------
#### Checks if the given value matches Canada postal code regexp.
interfaces: not, all, any
```javascript
is.caPostalCode('L8V3Y1');
=> true
is.caPostalCode('L8V 3Y1');
=> true
is.caPostalCode('123');
=> false
is.not.caPostalCode('123');
=> true
is.all.caPostalCode('L8V3Y1', '123');
=> false
is.any.caPostalCode('L8V3Y1', '123');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.caPostalCode(['L8V3Y1', '123']);
=> false
```
is.ukPostCode(value:any)
------------------------
#### Checks if the given value matches UK post code regexp.
interfaces: not, all, any
```javascript
is.ukPostCode('B184BJ');
=> true
is.ukPostCode('123');
=> false
is.not.ukPostCode('123');
=> true
is.all.ukPostCode('B184BJ', '123');
=> false
is.any.ukPostCode('B184BJ', '123');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.ukPostCode(['B184BJ', '123']);
=> false
```
is.nanpPhone(value:any)
-----------------------
#### Checks if the given value matches North American numbering plan phone regexp.
interfaces: not, all, any
```javascript
is.nanpPhone('609-555-0175');
=> true
is.nanpPhone('123');
=> false
is.not.nanpPhone('123');
=> true
is.all.nanpPhone('609-555-0175', '123');
=> false
is.any.nanpPhone('609-555-0175', '123');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.nanpPhone(['609-555-0175', '123']);
=> false
```
is.eppPhone(value:any)
----------------------
#### Checks if the given value matches extensible provisioning protocol phone regexp.
interfaces: not, all, any
```javascript
is.eppPhone('+90.2322456789');
=> true
is.eppPhone('123');
=> false
is.not.eppPhone('123');
=> true
is.all.eppPhone('+90.2322456789', '123');
=> false
is.any.eppPhone('+90.2322456789', '123');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.eppPhone(['+90.2322456789', '123']);
=> false
```
is.socialSecurityNumber(value:any)
----------------------------------
#### Checks if the given value matches social security number regexp.
interfaces: not, all, any
```javascript
is.socialSecurityNumber('017-90-7890');
=> true
is.socialSecurityNumber('017907890');
=> true
is.socialSecurityNumber('123');
=> false
is.not.socialSecurityNumber('123');
=> true
is.all.socialSecurityNumber('017-90-7890', '123');
=> false
is.any.socialSecurityNumber('017907890', '123');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.socialSecurityNumber(['017-90-7890', '123']);
=> false
```
is.affirmative(value:any)
-------------------------
#### Checks if the given value matches affirmative regexp.
interfaces: not, all, any
```javascript
is.affirmative('yes');
=> true
is.affirmative('no');
=> false
is.not.affirmative('no');
=> true
is.all.affirmative('yes', 'no');
=> false
is.any.affirmative('yes', 'no');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.affirmative(['yes', 'y', 'true', 't', 'ok', 'okay']);
=> true
```
is.hexadecimal(value:any)
-------------------------
#### Checks if the given value matches hexadecimal regexp.
interfaces: not, all, any
```javascript
is.hexadecimal('f0f0f0');
=> true
is.hexadecimal('0xf0f0f0');
=> true
is.hexadecimal(2.5);
=> false
is.not.hexadecimal('string');
=> true
is.all.hexadecimal('ff', 'f50');
=> true
is.any.hexadecimal('0xff5500', true);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.hexadecimal(['fff', '333', 'f50']);
=> true
```
is.hexColor(value:any)
-------------------------
#### Checks if the given value matches hexcolor regexp.
interfaces: not, all, any
```javascript
is.hexColor('#333');
=> true
is.hexColor('#3333');
=> false
is.not.hexColor(0.5);
=> true
is.all.hexColor('fff', 'f50');
=> true
is.any.hexColor('ff5500', 0.5);
=> false
// 'all' and 'any' interfaces can also take array parameter
is.all.hexColor(['fff', '333', 'f50']);
=> true
```
is.ip(value:any)
-------------------------
#### Checks if the given value matches ip regexp
interfaces: not, all, any
```javascript
is.ip('198.156.23.5');
=> true
is.ip('1.2..5');
=> false
is.not.ip('8:::::::7');
=> true
is.all.ip('0:1::4:ff5:54:987:C', '123.123.123.123');
=> true
is.any.ip('123.8.4.3', '0.0.0.0');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.ip(['123.123.23.12', 'A:B:C:D:E:F:0:0']);
=> true
```
is.ipv4(value:any)
-------------------------
#### Checks if the given value matches ipv4 regexp
interfaces: not, all, any
```javascript
is.ipv4('198.12.3.142');
=> true
is.ipv4('1.2..5');
=> false
is.not.ipv4('8:::::::7');
=> true
is.all.ipv4('198.12.3.142', '123.123.123.123');
=> true
is.any.ipv4('255.255.255.255', '850..1.4');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.ipv4(['198.12.3.142', '1.2.3']);
=> false
```
is.ipv6(value:any)
-------------------------
#### Checks if the given value matches ipv6 regexp
interfaces: not, all, any
```javascript
is.ipv6('2001:DB8:0:0:1::1');
=> true
is.ipv6('985.12.3.4');
=> true
is.not.ipv6('8:::::::7');
=> true
is.all.ipv6('2001:DB8:0:0:1::1', '1:50:198:2::1:2:8');
=> true
is.any.ipv6('255.255.255.255', '2001:DB8:0:0:1::1');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.ipv6(['2001:DB8:0:0:1::1', '1.2.3']);
=> false
```
String checks
=============
is.include(value:string, target:string)
-----------------------------------------
#### Checks if the given string contains a substring.
interface: not
```javascript
is.include('Some text goes here', 'text');
=> true
is.include('test', 'text');
=> false
is.not.include('test', 'text');
=> true
```
is.upperCase(value:string)
--------------------------
#### Checks if the given string is UPPERCASE.
interfaces: not, all, any
```javascript
is.upperCase('YEAP');
=> true
is.upperCase('nope');
=> false
is.not.upperCase('Nope');
=> true
is.all.upperCase('YEAP', 'nope');
=> false
is.any.upperCase('YEAP', 'nope');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.upperCase(['YEAP', 'ALL UPPERCASE']);
=> true
```
is.lowerCase(value:string)
--------------------------
#### Checks if the given string is lowercase.
interfaces: not, all, any
```javascript
is.lowerCase('yeap');
=> true
is.lowerCase('NOPE');
=> false
is.not.lowerCase('Nope');
=> true
is.all.lowerCase('yeap', 'NOPE');
=> false
is.any.lowerCase('yeap', 'NOPE');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.lowerCase(['yeap', 'all lowercase']);
=> true
```
is.startWith(value:string, target:string)
-------------------------------------------
#### Checks if the given string starts with substring.
interface: not
```javascript
is.startWith('yeap', 'ye');
=> true
is.startWith('nope', 'ye');
=> false
is.not.startWith('nope not that', 'not');
=> true
```
is.endWith(value:string, target:string)
-----------------------------------------
#### Checks if the given string ends with substring.
interfaces: not
```javascript
is.endWith('yeap', 'ap');
=> true
is.endWith('nope', 'no');
=> false
is.not.endWith('nope not that', 'not');
=> true
is.endWith('yeap that one', 'one');
=> true
```
is.capitalized(value:string)
---------------------------------------------
#### Checks if the given string is capitalized.
interfaces: not, all, any
```javascript
is.capitalized('Yeap');
=> true
is.capitalized('nope');
=> false
is.not.capitalized('nope not capitalized');
=> true
is.not.capitalized('nope Capitalized');
=> true
is.all.capitalized('Yeap', 'All', 'Capitalized');
=> true
is.any.capitalized('Yeap', 'some', 'Capitalized');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.capitalized(['Nope', 'not']);
=> false
```
is.palindrome(value:string)
---------------------------------------------
#### Checks if the given string is palindrome.
interfaces: not, all, any
```javascript
is.palindrome('testset');
=> true
is.palindrome('A man, a plan, a canal - Panama!');
=> true
is.palindrome('nope');
=> false
is.not.palindrome('nope not palindrome');
=> true
is.not.palindrome('tt');
=> false
is.all.palindrome('testset', 'tt');
=> true
is.any.palindrome('Yeap', 'some', 'testset');
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.palindrome(['Nope', 'testset']);
=> false
```
Arithmetic checks
=================
is.equal(value:any, other:any)
------------------------------
#### Checks if the given values are equal.
interfaces: not
```javascript
is.equal(42, 40 + 2);
=> true
is.equal('yeap', 'yeap');
=> true
is.equal(true, true);
=> true
is.not.equal('yeap', 'nope');
=> true
```
is.even(value:number)
---------------------
#### Checks if the given value is even.
interfaces: not, all, any
```javascript
is.even(42);
=> true
is.not.even(41);
=> true
is.all.even(40, 42, 44);
=> true
is.any.even(39, 42, 43);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.even([40, 42, 43]);
=> false
```
is.odd(value:number)
--------------------
#### Checks if the given value is odd.
interfaces: not, all, any
```javascript
is.odd(41);
=> true
is.not.odd(42);
=> true
is.all.odd(39, 41, 43);
=> true
is.any.odd(39, 42, 44);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.odd([40, 42, 43]);
=> false
```
is.positive(value:number)
-------------------------
#### Checks if the given value is positive.
interfaces: not, all, any
```javascript
is.positive(41);
=> true
is.not.positive(-42);
=> true
is.all.positive(39, 41, 43);
=> true
is.any.positive(-39, 42, -44);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.positive([40, 42, -43]);
=> false
```
is.negative(value:number)
-------------------------
#### Checks if the given value is negative.
interfaces: not, all, any
```javascript
is.negative(-41);
=> true
is.not.negative(42);
=> true
is.all.negative(-39, -41, -43);
=> true
is.any.negative(-39, 42, 44);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.negative([40, 42, -43]);
=> false
```
is.above(value:number, min:number)
---------------------------
#### Checks if the given value is above minimum value.
interface: not
```javascript
is.above(41, 30);
=> true
is.not.above(42, 50);
=> true
```
is.under(value:number, max:number)
---------------------------
#### Checks if the given value is under maximum value.
interface: not
```javascript
is.under(30, 35);
=> true
is.not.under(42, 30);
=> true
```
is.within(value:number, min:number, max:number)
---------------------------------
#### Checks if the given value is within minimum and maximum values.
interface: not
```javascript
is.within(30, 20, 40);
=> true
is.not.within(40, 30, 35);
=> true
```
is.decimal(value:number)
------------------------
#### Checks if the given value is decimal.
interfaces: not, all, any
```javascript
is.decimal(41.5);
=> true
is.not.decimal(42);
=> true
is.all.decimal(39.5, 41.5, -43.5);
=> true
is.any.decimal(-39, 42.5, 44);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.decimal([40, 42.5, -43]);
=> false
```
is.integer(value:number)
------------------------
#### Checks if the given value is integer.
interfaces: not, all, any
```javascript
is.integer(41);
=> true
is.not.integer(42.5);
=> true
is.all.integer(39, 41, -43);
=> true
is.any.integer(-39, 42.5, 44);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.integer([40, 42.5, -43]);
=> false
```
is.finite(value:number)
-----------------------
#### Checks if the given value is finite.
interfaces: not, all, any
```javascript
is.finite(41);
=> true
is.not.finite(42 / 0);
=> true
is.all.finite(39, 41, -43);
=> true
is.any.finite(-39, Infinity, 44);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.finite([Infinity, -Infinity, 42.5]);
=> false
```
is.infinite(value:number)
-------------------------
#### Checks if the given value is infinite.
interfaces: not, all, any
```javascript
is.infinite(Infinity);
=> true
is.not.infinite(42);
=> true
is.all.infinite(Infinity, -Infinity, -43 / 0);
=> true
is.any.infinite(-39, Infinity, 44);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.infinite([Infinity, -Infinity, 42.5]);
=> false
```
Object checks
=============
is.propertyCount(value:object, count:number)
-------------------------------------
#### Checks if objects' property count is equal to given count.
interface: not
```javascript
is.propertyCount({this: 'is', 'sample': object}, 2);
=> true
is.propertyCount({this: 'is', 'sample': object}, 3);
=> false
is.not.propertyCount({}, 2);
=> true
```
is.propertyDefined(value:object, property:string)
------------------------------------------
#### Checks if the given property is defined on object.
interface: not
```javascript
is.propertyDefined({yeap: 'yeap'}, 'yeap');
=> true
is.propertyDefined({yeap: 'yeap'}, 'nope');
=> false
is.not.propertyDefined({}, 'nope');
=> true
```
Array checks
============
is.inArray(value:any, array)
---------------------
#### Checks if the given item is in array?
interface: not
```javascript
is.inArray(2, [1, 2, 3]);
=> true
is.inArray(4, [1, 2, 3]);
=> false
is.not.inArray(4, [1, 2, 3]);
=> true
```
is.sorted(value:array, sign:string)
----------------------
#### Checks if the given array is sorted. Sign is optional parameter.
interfaces: not, all, any
```javascript
is.sorted([1, 2, 3]);
=> true
is.sorted([1, 2, 4, 3]);
=> false
is.sorted([1, 1, 2, 2], '>=');
=> true
is.sorted([1, 2, 3, 4], '>');
=> true
is.sorted([4, 3, 3, 1], '<=');
=> true
is.sorted([4, 3, 2, 1], '<');
=> true
is.sorted([1, 2, 3, 3], '>');
=> false
is.not.sorted([5, 4, 3]);
=> true
is.not.sorted([5, 4, 3], '<');
=> false
is.all.sorted([1, 2], [3, 4]);
=> true
is.any.sorted([1, 2], [5, 4]);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.sorted([[1, 2], [5, 4]]);
=> 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
```javascript
is.ie();
=> true if current browser is ie
is.not.ie();
=> false if current browser is ie
// also supports version number
is.ie(10);
=> true if current version of ie is 10
is.ie('>=10');
=> true if current version of ie is greater than or equal to 10
is.not.ie('<9');
=> 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
```javascript
is.chrome();
=> true if current browser is chrome
is.not.chrome();
=> false if current browser is chrome
// also supports version number
is.chrome(50);
=> true if current version of chrome is 50
is.chrome('>=40');
=> true if current version of chrome is greater than or equal to 40
is.not.chrome('<30');
=> 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
```javascript
is.firefox();
=> true if current browser is firefox
is.not.firefox();
=> false if current browser is firefox
// also supports version number
is.firefox(41);
=> true if current version of firefox is 41
is.firefox('>=40');
=> true if current version of firefox is greater than or equal to 40
is.not.firefox('<30');
=> 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
```javascript
is.edge();
=> true if current browser is edge
is.not.edge();
=> false if current browser is edge
// also supports version number
is.edge(13);
=> true if current version of edge is 13
is.edge('>=12');
=> true if current version of edge is greater than or equal to 12
is.not.edge('<13');
=> 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
```javascript
is.opera();
=> true if current browser is opera
is.not.opera();
=> false if current browser is opera
// also supports version number
is.opera(36);
=> true if current version of opera is 36
is.opera('>=35');
=> true if current version of opera is greater than or equal to 35
is.not.opera('<20');
=> 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
```javascript
is.safari();
=> true if current browser is safari
is.not.safari();
=> false if current browser is safari
// also supports version number
is.safari(9);
=> true if current version of safari is 9
is.safari('>=8');
=> true if current version of safari is greater than or equal to 8
is.not.safari('<7');
=> 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
```javascript
is.phantom();
=> true if current browser is phantomjs
is.not.phantom();
=> false if current browser is phantomjs
// also supports version number
is.phantom(2);
=> true if current version of phantom is 2
is.phantom('>=1');
=> true if current version of phantomjs is greater than or equal to 1
is.not.phantom('<2');
=> true if current version of phantomjs is not less than 2
```
is.ios()
--------
#### Checks if current device has ios.
interface: not
```javascript
is.ios();
=> true if current device is iPhone, iPad or iPod
is.not.ios();
=> 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
```javascript
is.iphone();
=> true if current device is iPhone
is.not.iphone();
=> true if current device is not iPhone
// also supports version number
is.iphone(9);
=> true if current version of iPhone is 9
is.iphone('>=7');
=> true if current version of iPhone is greater than or equal to 7
is.not.iphone('<8');
=> true if current version of iPhone is not less than 8
```
is.ipad(range:number|string)
---------
#### Checks if current device is iPad.
interface: not
```javascript
is.ipad();
=> true if current device is iPad
is.not.ipad();
=> true if current device is not iPad
// also supports version number
is.ipad(9);
=> true if current version of iPad is 9
is.ipad('>=7');
=> true if current version of iPad is greater than or equal to 7
is.not.ipad('<8');
=> true if current version of iPad is not less than 8
```
is.ipod(range:number|string)
---------
#### Checks if current device is iPod.
interface: not
```javascript
is.ipod();
=> true if current device is iPod
is.not.ipod();
=> true if current device is not iPod
// also supports version number
is.ipod(7);
=> true if current version of iPod is 7
is.ipod('>=5');
=> true if current version of iPod is greater than or equal to 5
is.not.ipod('<5');
=> true if current version of iPod is not less than 5
```
is.android()
------------
#### Checks if current device has Android.
interface: not
```javascript
is.android();
=> true if current device has Android OS
is.not.android();
=> true if current device has not Android OS
```
is.androidPhone()
-----------------
#### Checks if current device is Android phone.
interface: not
```javascript
is.androidPhone();
=> true if current device is Android phone
is.not.androidPhone();
=> true if current device is not Android phone
```
is.androidTablet()
------------------
#### Checks if current device is Android tablet.
interface: not
```javascript
is.androidTablet();
=> true if current device is Android tablet
is.not.androidTablet();
=> true if current device is not Android tablet
```
is.blackberry()
---------------
#### Checks if current device is Blackberry.
interface: not
```javascript
is.blackberry();
=> true if current device is Blackberry
is.not.blackberry();
=> true if current device is not Blackberry
```
is.windowsPhone()
-----------------
#### Checks if current device is Windows phone.
interface: not
```javascript
is.windowsPhone();
=> true if current device is Windows phone
is.not.windowsPhone();
=> true if current device is not Windows Phone
```
is.windowsTablet()
------------------
#### Checks if current device is Windows tablet.
interface: not
```javascript
is.windowsTablet();
=> true if current device is Windows tablet
is.not.windowsTablet();
=> true if current device is not Windows tablet
```
is.windows()
------------
#### Checks if current OS is Windows.
interface: not
```javascript
is.windows();
=> true if current OS is Windows
is.not.windows();
=> true if current OS is not Windows
```
is.mac()
--------
#### Checks if current OS is Mac OS X.
interface: not
```javascript
is.mac();
=> true if current OS is Mac OS X
is.not.mac();
=> true if current OS is not Mac OS X
```
is.linux()
----------
#### Checks if current OS is linux.
interface: not
```javascript
is.linux();
=> true if current OS is linux
is.not.linux();
=> true if current OS is not linux
```
is.desktop()
------------
#### Checks if current device is desktop.
interface: not
```javascript
is.desktop();
=> true if current device is desktop
is.not.desktop();
=> true if current device is not desktop
```
is.mobile()
-----------
#### Checks if current device is mobile.
interface: not
iPhone, iPod, Android Phone, Windows Phone, Blackberry.
```javascript
is.mobile();
=> true if current device is mobile
is.not.mobile();
=> true if current device is not mobile
```
is.tablet()
-----------
#### Checks if current device is tablet.
interface: not
iPad, Android Tablet, Windows Tablet
```javascript
is.tablet();
=> true if current device is tablet
is.not.tablet();
=> true if current device is not tablet
```
is.online()
-----------
#### Checks if current device is online.
interface: not
```javascript
is.online();
=> true if current device is online
is.not.online();
=> true if current device is not online
```
is.offline()
------------
#### Checks if current device is offline.
interface: not
```javascript
is.offline();
=> true if current device is offline
is.not.offline();
=> true if current device is not offline
```
is.touchDevice()
------------
#### Checks if current device supports touch.
interface: not
```javascript
is.touchDevice();
=> true if current device supports touch
is.not.touchDevice();
=> 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
```javascript
var today = new Date();
is.today(today);
=> true
var yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
is.today(yesterday);
=> false
is.not.today(yesterday);
=> true
is.all.today(today, today);
=> true
is.any.today(today, yesterday);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.today([today, yesterday]);
=> false
```
is.yesterday(value:date)
--------------------------
#### Checks if the given date object indicate yesterday.
interfaces: not, all, any
```javascript
var today = new Date();
is.yesterday(today);
=> false
var yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
is.yesterday(yesterday);
=> true
is.not.yesterday(today);
=> true
is.all.yesterday(yesterday, today);
=> false
is.any.yesterday(today, yesterday);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.yesterday([today, yesterday]);
=> false
```
is.tomorrow(value:date)
-------------------------
#### Checks if the given date object indicate tomorrow.
interfaces: not, all, any
```javascript
var today = new Date();
is.tomorrow(today);
=> false
var tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));
is.tomorrow(tomorrow);
=> true
is.not.tomorrow(today);
=> true
is.all.tomorrow(tomorrow, today);
=> false
is.any.tomorrow(today, tomorrow);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.tomorrow([today, tomorrow]);
=> false
```
is.past(value:date)
---------------------
#### Checks if the given date object indicate past.
interfaces: not, all, any
```javascript
var yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
var tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));
is.past(yesterday);
=> true
is.past(tomorrow);
=> false
is.not.past(tomorrow);
=> true
is.all.past(tomorrow, yesterday);
=> false
is.any.past(yesterday, tomorrow);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.past([yesterday, tomorrow]);
=> false
```
is.future(value:date)
-----------------------
#### Checks if the given date object indicate future.
interfaces: not, all, any
```javascript
var yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
var tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));
is.future(yesterday);
=> false
is.future(tomorrow);
=> true
is.not.future(yesterday);
=> true
is.all.future(tomorrow, yesterday);
=> false
is.any.future(yesterday, tomorrow);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.future([yesterday, tomorrow]);
=> false
```
is.day(value:date, day:string)
-------------------------------
#### Checks if the given date objects' day equal given dayString parameter.
interface: not
```javascript
var mondayObj = new Date('01/26/2015');
var tuesdayObj = new Date('01/27/2015');
is.day(mondayObj, 'monday');
=> true
is.day(mondayObj, 'tuesday');
=> false
is.not.day(mondayObj, 'tuesday');
=> true
```
is.month(value:date, month:string)
-----------------------------------
#### Checks if the given date objects' month equal given monthString parameter.
interface: not
```javascript
var januaryObj = new Date('01/26/2015');
var februaryObj = new Date('02/26/2015');
is.month(januaryObj, 'january');
=> true
is.month(februaryObj, 'january');
=> false
is.not.month(februaryObj, 'january');
=> true
```
is.year(value:date, year:number)
---------------------------------
#### Checks if the given date objects' year equal given yearNumber parameter.
interface: not
```javascript
var year2015 = new Date('01/26/2015');
var year2016 = new Date('01/26/2016');
is.year(year2015, 2015);
=> true
is.year(year2016, 2015);
=> false
is.not.year(year2016, 2015);
=> true
```
is.leapYear(value:number)
---------------------------------
#### Checks if the given year number is a leap year
interfaces: not, all, any
```javascript
is.leapYear(2016);
=> true
is.leapYear(2015);
=> false
is.not.leapYear(2015);
=> true
is.all.leapYear(2015, 2016);
=> false
is.any.leapYear(2015, 2016);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.leapYear([2016, 2080]);
=> true
```
is.weekend(value:date)
------------------------
#### Checks if the given date objects' day is weekend.
interfaces: not, all, any
```javascript
var monday = new Date('01/26/2015');
var sunday = new Date('01/25/2015');
var saturday = new Date('01/24/2015');
is.weekend(sunday);
=> true
is.weekend(monday);
=> false
is.not.weekend(monday);
=> true
is.all.weekend(sunday, saturday);
=> true
is.any.weekend(sunday, saturday, monday);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.weekend([sunday, saturday, monday]);
=> false
```
is.weekday(value:date)
------------------------
#### Checks if the given date objects' day is weekday.
interfaces: not, all, any
```javascript
var monday = new Date('01/26/2015');
var sunday = new Date('01/25/2015');
var saturday = new Date('01/24/2015');
is.weekday(monday);
=> true
is.weekday(sunday);
=> false
is.not.weekday(sunday);
=> true
is.all.weekday(monday, saturday);
=> false
is.any.weekday(sunday, saturday, monday);
=> true
// 'all' and 'any' interfaces can also take array parameter
is.all.weekday([sunday, saturday, monday]);
=> false
```
is.inDateRange(value:date, start:date, end:date)
----------------------------------------------------
#### Checks if date is within given range.
interface: not
```javascript
var saturday = new Date('01/24/2015');
var sunday = new Date('01/25/2015');
var monday = new Date('01/26/2015');
is.inDateRange(sunday, saturday, monday);
=> true
is.inDateRange(saturday, sunday, monday);
=> false
is.not.inDateRange(saturday, sunday, monday);
=> true
```
is.inLastWeek(value:date)
---------------------------
#### Checks if the given date is between now and 7 days ago.
interface: not
```javascript
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);
=> true
is.inLastWeek(nineDaysAgo);
=> false
is.not.inLastWeek(nineDaysAgo);
=> true
```
is.inLastMonth(value:date)
----------------------------
#### Checks if the given date is between now and a month ago.
interface: not
```javascript
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);
=> true
is.inLastMonth(fortyDaysAgo);
=> false
is.not.inLastMonth(fortyDaysAgo);
=> true
```
is.inLastYear(value:date)
---------------------------
#### Checks if the given date is between now and a year ago.
interface: not
```javascript
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);
=> true
is.inLastYear(thirteenMonthsAgo);
=> false
is.not.inLastYear(thirteenMonthsAgo);
=> true
```
is.inNextWeek(value:date)
---------------------------
#### Checks if the given date is between now and 7 days later.
interface: not
```javascript
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);
=> true
is.inNextWeek(nineDaysLater);
=> false
is.not.inNextWeek(nineDaysLater);
=> true
```
is.inNextMonth(value:date)
----------------------------
#### Checks if the given date is between now and a month later.
interface: not
```javascript
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);
=> true
is.inNextMonth(fortyDaysLater);
=> false
is.not.inNextMonth(fortyDaysLater);
=> true
```
is.inNextYear(value:date)
---------------------------
#### Checks if the given date is between now and a year later.
interface: not
```javascript
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);
=> true
is.inNextYear(thirteenMonthsLater);
=> false
is.not.inNextYear(thirteenMonthsLater);
=> true
```
is.quarterOfYear(value:date, quarter:number)
---------------------------------------------
#### Checks if the given date is in the parameter quarter.
interface: not
```javascript
var firstQuarter = new Date('01/26/2015');
var secondQuarter = new Date('05/26/2015');
is.quarterOfYear(firstQuarter, 1);
=> true
is.quarterOfYear(secondQuarter, 1);
=> false
is.not.quarterOfYear(secondQuarter, 1);
=> true
```
is.dayLightSavingTime(value:date)
--------------------------------------------------
#### Checks if the given date is in daylight saving time.
interface: not
```javascript
// For Turkey Time Zone
var january1 = new Date('01/01/2015');
var june1 = new Date('06/01/2015');
is.dayLightSavingTime(june1);
=> true
is.dayLightSavingTime(january1);
=> false
is.not.dayLightSavingTime(january1);
=> true
```
Configuration methods
=====================
is.setNamespace()
-----------------
Change namespace of library to prevent name collisions.
```javascript
var customName = is.setNamespace();
customName.odd(3);
=> true
```
is.setRegexp(value:regexp, name:string)
----------------------------------------
Override RegExps if you think they suck.
```javascript
is.url('https://www.duckduckgo.com');
=> true
is.setRegexp(/quack/, 'url');
is.url('quack');
=> true
```
================================================
FILE: bower.json
================================================
{
"name": "is_js",
"main": "is.js",
"ignore": [
"bower_components",
"node_modules",
"test",
"**/.*",
"**/*.md",
"package.json"
]
}
================================================
FILE: is.js
================================================
/*!
* is.js 0.9.0
* Author: Aras Atasaygin
*/
// AMD with global, Node, or global
;(function(root, factory) { // eslint-disable-line no-extra-semi
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(function() {
// Also create a global in case some scripts
// that are loaded still are looking for
// a global even when an AMD loader is in use.
return (root.is = factory());
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is self)
root.is = factory();
}
}(this, function() {
// Baseline
/* -------------------------------------------------------------------------- */
// define 'is' object and current version
var is = {};
is.VERSION = '0.9.0';
// define interfaces
is.not = {};
is.all = {};
is.any = {};
// cache some methods to call later on
var toString = Object.prototype.toString;
var slice = Array.prototype.slice;
var hasOwnProperty = Object.prototype.hasOwnProperty;
// helper function which reverses the sense of predicate result
function not(func) {
return function() {
return !func.apply(null, slice.call(arguments));
};
}
// helper function which call predicate function per parameter and return true if all pass
function all(func) {
return function() {
var params = getParams(arguments);
var length = params.length;
for (var i = 0; i < length; i++) {
if (!func.call(null, params[i])) {
return false;
}
}
return true;
};
}
// helper function which call predicate function per parameter and return true if any pass
function any(func) {
return function() {
var params = getParams(arguments);
var length = params.length;
for (var i = 0; i < length; i++) {
if (func.call(null, params[i])) {
return true;
}
}
return false;
};
}
// build a 'comparator' object for various comparison checks
var comparator = {
'<': function(a, b) { return a < b; },
'<=': function(a, b) { return a <= b; },
'>': function(a, b) { return a > b; },
'>=': function(a, b) { return a >= b; }
};
// helper function which compares a version to a range
function compareVersion(version, range) {
var string = (range + '');
var n = +(string.match(/\d+/) || NaN);
var op = string.match(/^[<>]=?|/)[0];
return comparator[op] ? comparator[op](version, n) : (version == n || n !== n);
}
// helper function which extracts params from arguments
function getParams(args) {
var params = slice.call(args);
var length = params.length;
if (length === 1 && is.array(params[0])) { // support array
params = params[0];
}
return params;
}
// Type checks
/* -------------------------------------------------------------------------- */
// is a given value Arguments?
is.arguments = function(value) { // fallback check is for IE
return toString.call(value) === '[object Arguments]' ||
(value != null && typeof value === 'object' && 'callee' in value);
};
// is a given value Array?
is.array = Array.isArray || function(value) { // check native isArray first
return toString.call(value) === '[object Array]';
};
// is a given value Boolean?
is.boolean = function(value) {
return value === true || value === false || toString.call(value) === '[object Boolean]';
};
// is a given value Char?
is.char = function(value) {
return is.string(value) && value.length === 1;
};
// is a given value Date Object?
is.date = function(value) {
return toString.call(value) === '[object Date]';
};
// is a given object a DOM node?
is.domNode = function(object) {
return is.object(object) && object.nodeType > 0;
};
// is a given value Error object?
is.error = function(value) {
return toString.call(value) === '[object Error]';
};
// is a given value function?
is['function'] = function(value) { // fallback check is for IE
return toString.call(value) === '[object Function]' || typeof value === 'function';
};
// is given value a pure JSON object?
is.json = function(value) {
return toString.call(value) === '[object Object]';
};
// is a given value NaN?
is.nan = function(value) {
return Number.isNaN(value);
};
// is a given value null?
is['null'] = function(value) {
return value === null;
};
// is a given value number?
is.number = function(value) {
return Number.isFinite(value);
};
// is a given value object?
is.object = function(value) {
return Object(value) === value;
};
// is a given value RegExp?
is.regexp = function(value) {
return toString.call(value) === '[object RegExp]';
};
// are given values same type?
// prevent NaN, Number same type check
is.sameType = function(value, other) {
var tag = toString.call(value);
if (tag !== toString.call(other)) {
return false;
}
if (tag === '[object Number]') {
return !is.any.nan(value, other) || is.all.nan(value, other);
}
return true;
};
// sameType method does not support 'all' and 'any' interfaces
is.sameType.api = ['not'];
// is a given value String?
is.string = function(value) {
return toString.call(value) === '[object String]';
};
// is a given value undefined?
is.undefined = function(value) {
return value === void 0;
};
// is a given value window?
// setInterval method is only available for window object
is.windowObject = function(value) {
return value != null && typeof value === 'object' && 'setInterval' in value;
};
// Presence checks
/* -------------------------------------------------------------------------- */
//is a given value empty? Objects, arrays, strings
is.empty = function(value) {
if (is.object(value)) {
var length = Object.getOwnPropertyNames(value).length;
if (length === 0 || (length === 1 && is.array(value)) ||
(length === 2 && is.arguments(value))) {
return true;
}
return false;
}
return value === '';
};
// is a given value existy?
is.existy = function(value) {
return value != null;
};
// is a given value falsy?
is.falsy = function(value) {
return !value;
};
// is a given value truthy?
is.truthy = not(is.falsy);
// Arithmetic checks
/* -------------------------------------------------------------------------- */
// is a given number above minimum parameter?
is.above = function(n, min) {
return is.all.number(n, min) && n > min;
};
// above method does not support 'all' and 'any' interfaces
is.above.api = ['not'];
// is a given number decimal?
is.decimal = function(n) {
return is.number(n) && n % 1 !== 0;
};
// are given values equal? supports numbers, strings, regexes, booleans
// TODO: Add object and array support
is.equal = function(value, other) {
// check 0 and -0 equity with Infinity and -Infinity
if (is.all.number(value, other)) {
return value === other && 1 / value === 1 / other;
}
// check regexes as strings too
if (is.all.string(value, other) || is.all.regexp(value, other)) {
return '' + value === '' + other;
}
if (is.all.boolean(value, other)) {
return value === other;
}
return false;
};
// equal method does not support 'all' and 'any' interfaces
is.equal.api = ['not'];
// is a given number even?
is.even = function(n) {
return is.number(n) && n % 2 === 0;
};
// is a given number finite?
is.finite = isFinite || function(n) {
return is.not.infinite(n) && is.not.nan(n);
};
// is a given number infinite?
is.infinite = function(n) {
return n === Infinity || n === -Infinity;
};
// is a given number integer?
is.integer = function(n) {
return Number.isInteger(n);
};
// is a given number negative?
is.negative = function(n) {
return is.number(n) && n < 0;
};
// is a given number odd?
is.odd = function(n) {
return is.number(n) && (n % 2 === 1 || n % 2 === -1);
};
// is a given number positive?
is.positive = function(n) {
return is.number(n) && n > 0;
};
// is a given number above maximum parameter?
is.under = function(n, max) {
return is.all.number(n, max) && n < max;
};
// least method does not support 'all' and 'any' interfaces
is.under.api = ['not'];
// is a given number within minimum and maximum parameters?
is.within = function(n, min, max) {
return is.all.number(n, min, max) && n > min && n < max;
};
// within method does not support 'all' and 'any' interfaces
is.within.api = ['not'];
// Regexp checks
/* -------------------------------------------------------------------------- */
// Steven Levithan, Jan Goyvaerts: Regular Expressions Cookbook
// Scott Gonzalez: Email address validation
// dateString match m/d/yy and mm/dd/yyyy, allowing any combination of one or two digits for the day and month, and two or four digits for the year
// eppPhone match extensible provisioning protocol format
// nanpPhone match north american number plan format
// time match hours, minutes, and seconds, 24-hour clock
var regexes = {
affirmative: /^(?:1|t(?:rue)?|y(?:es)?|ok(?:ay)?)$/,
alphaNumeric: /^[A-Za-z0-9]+$/,
caPostalCode: /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z]\s?[0-9][A-Z][0-9]$/,
creditCard: /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/,
dateString: /^(1[0-2]|0?[1-9])([\/-])(3[01]|[12][0-9]|0?[1-9])(?:\2)(?:[0-9]{2})?[0-9]{2}$/,
email: /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i, // eslint-disable-line no-control-regex
eppPhone: /^\+[0-9]{1,3}\.[0-9]{4,14}(?:x.+)?$/,
hexadecimal: /^(?:0x)?[0-9a-fA-F]+$/,
hexColor: /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,
ipv4: /^(?:(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/,
ipv6: /^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i,
nanpPhone: /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/,
socialSecurityNumber: /^(?!000|666)[0-8][0-9]{2}-?(?!00)[0-9]{2}-?(?!0000)[0-9]{4}$/,
timeString: /^(2[0-3]|[01]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9])$/,
ukPostCode: /^[A-Z]{1,2}[0-9RCHNQ][0-9A-Z]?\s?[0-9][ABD-HJLNP-UW-Z]{2}$|^[A-Z]{2}-?[0-9]{4}$/,
url: /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/i,
usZipCode: /^[0-9]{5}(?:-[0-9]{4})?$/
};
function regexpCheck(regexp, regexes) {
is[regexp] = function(value) {
return is.existy(value) && regexes[regexp].test(value);
};
}
// create regexp checks methods from 'regexes' object
for (var regexp in regexes) {
if (regexes.hasOwnProperty(regexp)) {
regexpCheck(regexp, regexes);
}
}
// simplify IP checks by calling the regex helpers for IPv4 and IPv6
is.ip = function(value) {
return is.ipv4(value) || is.ipv6(value);
};
// String checks
/* -------------------------------------------------------------------------- */
// is a given string or sentence capitalized?
is.capitalized = function(string) {
if (is.not.string(string)) {
return false;
}
var words = string.split(' ');
for (var i = 0; i < words.length; i++) {
var word = words[i];
if (word.length) {
var chr = word.charAt(0);
if (chr !== chr.toUpperCase()) {
return false;
}
}
}
return true;
};
// is string end with a given target parameter?
is.endWith = function(string, target) {
if (is.not.string(string)) {
return false;
}
target += '';
var position = string.length - target.length;
return position >= 0 && string.indexOf(target, position) === position;
};
// endWith method does not support 'all' and 'any' interfaces
is.endWith.api = ['not'];
// is a given string include parameter target?
is.include = function(string, target) {
return string.indexOf(target) > -1;
};
// include method does not support 'all' and 'any' interfaces
is.include.api = ['not'];
// is a given string all lowercase?
is.lowerCase = function(string) {
return is.string(string) && string === string.toLowerCase();
};
// is a given string palindrome?
is.palindrome = function(string) {
if (is.not.string(string)) {
return false;
}
string = string.replace(/[^a-zA-Z0-9]+/g, '').toLowerCase();
var length = string.length - 1;
for (var i = 0, half = Math.floor(length / 2); i <= half; i++) {
if (string.charAt(i) !== string.charAt(length - i)) {
return false;
}
}
return true;
};
// is a given value space?
// horizontal tab: 9, line feed: 10, vertical tab: 11, form feed: 12, carriage return: 13, space: 32
is.space = function(value) {
if (is.not.char(value)) {
return false;
}
var charCode = value.charCodeAt(0);
return (charCode > 8 && charCode < 14) || charCode === 32;
};
// is string start with a given target parameter?
is.startWith = function(string, target) {
return is.string(string) && string.indexOf(target) === 0;
};
// startWith method does not support 'all' and 'any' interfaces
is.startWith.api = ['not'];
// is a given string all uppercase?
is.upperCase = function(string) {
return is.string(string) && string === string.toUpperCase();
};
// Time checks
/* -------------------------------------------------------------------------- */
var days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
var months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
// is a given dates day equal given day parameter?
is.day = function(date, day) {
return is.date(date) && day.toLowerCase() === days[date.getDay()];
};
// day method does not support 'all' and 'any' interfaces
is.day.api = ['not'];
// is a given date in daylight saving time?
is.dayLightSavingTime = function(date) {
var january = new Date(date.getFullYear(), 0, 1);
var july = new Date(date.getFullYear(), 6, 1);
var stdTimezoneOffset = Math.max(january.getTimezoneOffset(), july.getTimezoneOffset());
return date.getTimezoneOffset() < stdTimezoneOffset;
};
// is a given date future?
is.future = function(date) {
var now = new Date();
return is.date(date) && date.getTime() > now.getTime();
};
// is date within given range?
is.inDateRange = function(date, start, end) {
if (is.not.date(date) || is.not.date(start) || is.not.date(end)) {
return false;
}
var stamp = date.getTime();
return stamp > start.getTime() && stamp < end.getTime();
};
// inDateRange method does not support 'all' and 'any' interfaces
is.inDateRange.api = ['not'];
// is a given date in last month range?
is.inLastMonth = function(date) {
return is.inDateRange(date, new Date(new Date().setMonth(new Date().getMonth() - 1)), new Date());
};
// is a given date in last week range?
is.inLastWeek = function(date) {
return is.inDateRange(date, new Date(new Date().setDate(new Date().getDate() - 7)), new Date());
};
// is a given date in last year range?
is.inLastYear = function(date) {
return is.inDateRange(date, new Date(new Date().setFullYear(new Date().getFullYear() - 1)), new Date());
};
// is a given date in next month range?
is.inNextMonth = function(date) {
return is.inDateRange(date, new Date(), new Date(new Date().setMonth(new Date().getMonth() + 1)));
};
// is a given date in next week range?
is.inNextWeek = function(date) {
return is.inDateRange(date, new Date(), new Date(new Date().setDate(new Date().getDate() + 7)));
};
// is a given date in next year range?
is.inNextYear = function(date) {
return is.inDateRange(date, new Date(), new Date(new Date().setFullYear(new Date().getFullYear() + 1)));
};
// is the given year a leap year?
is.leapYear = function(year) {
return is.number(year) && ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0);
};
// is a given dates month equal given month parameter?
is.month = function(date, month) {
return is.date(date) && month.toLowerCase() === months[date.getMonth()];
};
// month method does not support 'all' and 'any' interfaces
is.month.api = ['not'];
// is a given date past?
is.past = function(date) {
var now = new Date();
return is.date(date) && date.getTime() < now.getTime();
};
// is a given date in the parameter quarter?
is.quarterOfYear = function(date, quarter) {
return is.date(date) && is.number(quarter) && quarter === Math.floor((date.getMonth() + 3) / 3);
};
// quarterOfYear method does not support 'all' and 'any' interfaces
is.quarterOfYear.api = ['not'];
// is a given date indicate today?
is.today = function(date) {
var now = new Date();
var todayString = now.toDateString();
return is.date(date) && date.toDateString() === todayString;
};
// is a given date indicate tomorrow?
is.tomorrow = function(date) {
var now = new Date();
var tomorrowString = new Date(now.setDate(now.getDate() + 1)).toDateString();
return is.date(date) && date.toDateString() === tomorrowString;
};
// is a given date weekend?
// 6: Saturday, 0: Sunday
is.weekend = function(date) {
return is.date(date) && (date.getDay() === 6 || date.getDay() === 0);
};
// is a given date weekday?
is.weekday = not(is.weekend);
// is a given dates year equal given year parameter?
is.year = function(date, year) {
return is.date(date) && is.number(year) && year === date.getFullYear();
};
// year method does not support 'all' and 'any' interfaces
is.year.api = ['not'];
// is a given date indicate yesterday?
is.yesterday = function(date) {
var now = new Date();
var yesterdayString = new Date(now.setDate(now.getDate() - 1)).toDateString();
return is.date(date) && date.toDateString() === yesterdayString;
};
// Environment checks
/* -------------------------------------------------------------------------- */
var freeGlobal = is.windowObject(typeof global == 'object' && global) && global;
var freeSelf = is.windowObject(typeof self == 'object' && self) && self;
var thisGlobal = is.windowObject(typeof this == 'object' && this) && this;
var root = freeGlobal || freeSelf || thisGlobal || Function('return this')();
var document = freeSelf && freeSelf.document;
var previousIs = root.is;
// store navigator properties to use later
var navigator = freeSelf && freeSelf.navigator;
var platform = (navigator && navigator.platform || '').toLowerCase();
var userAgent = (navigator && navigator.userAgent || '').toLowerCase();
var vendor = (navigator && navigator.vendor || '').toLowerCase();
// is current device android?
is.android = function() {
return /android/.test(userAgent);
};
// android method does not support 'all' and 'any' interfaces
is.android.api = ['not'];
// is current device android phone?
is.androidPhone = function() {
return /android/.test(userAgent) && /mobile/.test(userAgent);
};
// androidPhone method does not support 'all' and 'any' interfaces
is.androidPhone.api = ['not'];
// is current device android tablet?
is.androidTablet = function() {
return /android/.test(userAgent) && !/mobile/.test(userAgent);
};
// androidTablet method does not support 'all' and 'any' interfaces
is.androidTablet.api = ['not'];
// is current device blackberry?
is.blackberry = function() {
return /blackberry/.test(userAgent) || /bb10/.test(userAgent);
};
// blackberry method does not support 'all' and 'any' interfaces
is.blackberry.api = ['not'];
// is current browser chrome?
// parameter is optional
is.chrome = function(range) {
var match = /google inc/.test(vendor) ? userAgent.match(/(?:chrome|crios)\/(\d+)/) : null;
return match !== null && is.not.opera() && compareVersion(match[1], range);
};
// chrome method does not support 'all' and 'any' interfaces
is.chrome.api = ['not'];
// is current device desktop?
is.desktop = function() {
return is.not.mobile() && is.not.tablet();
};
// desktop method does not support 'all' and 'any' interfaces
is.desktop.api = ['not'];
// is current browser edge?
// parameter is optional
is.edge = function(range) {
var match = userAgent.match(/edge\/(\d+)/);
return match !== null && compareVersion(match[1], range);
};
// edge method does not support 'all' and 'any' interfaces
is.edge.api = ['not'];
// is current browser firefox?
// parameter is optional
is.firefox = function(range) {
var match = userAgent.match(/(?:firefox|fxios)\/(\d+)/);
return match !== null && compareVersion(match[1], range);
};
// firefox method does not support 'all' and 'any' interfaces
is.firefox.api = ['not'];
// is current browser internet explorer?
// parameter is optional
is.ie = function(range) {
var match = userAgent.match(/(?:msie |trident.+?; rv:)(\d+)/);
return match !== null && compareVersion(match[1], range);
};
// ie method does not support 'all' and 'any' interfaces
is.ie.api = ['not'];
// is current device ios?
is.ios = function() {
return is.iphone() || is.ipad() || is.ipod();
};
// ios method does not support 'all' and 'any' interfaces
is.ios.api = ['not'];
// is current device ipad?
// parameter is optional
is.ipad = function(range) {
var match = userAgent.match(/ipad.+?os (\d+)/);
return match !== null && compareVersion(match[1], range);
};
// ipad method does not support 'all' and 'any' interfaces
is.ipad.api = ['not'];
// is current device iphone?
// parameter is optional
is.iphone = function(range) {
// avoid false positive for Facebook in-app browser on ipad;
// original iphone doesn't have the OS portion of the UA
var match = is.ipad() ? null : userAgent.match(/iphone(?:.+?os (\d+))?/);
return match !== null && compareVersion(match[1] || 1, range);
};
// iphone method does not support 'all' and 'any' interfaces
is.iphone.api = ['not'];
// is current device ipod?
// parameter is optional
is.ipod = function(range) {
var match = userAgent.match(/ipod.+?os (\d+)/);
return match !== null && compareVersion(match[1], range);
};
// ipod method does not support 'all' and 'any' interfaces
is.ipod.api = ['not'];
// is current operating system linux?
is.linux = function() {
return /linux/.test(platform) && is.not.android();
};
// linux method does not support 'all' and 'any' interfaces
is.linux.api = ['not'];
// is current operating system mac?
is.mac = function() {
return /mac/.test(platform);
};
// mac method does not support 'all' and 'any' interfaces
is.mac.api = ['not'];
// is current device mobile?
is.mobile = function() {
return is.iphone() || is.ipod() || is.androidPhone() || is.blackberry() || is.windowsPhone();
};
// mobile method does not support 'all' and 'any' interfaces
is.mobile.api = ['not'];
// is current state offline?
is.offline = not(is.online);
// offline method does not support 'all' and 'any' interfaces
is.offline.api = ['not'];
// is current state online?
is.online = function() {
return !navigator || navigator.onLine === true;
};
// online method does not support 'all' and 'any' interfaces
is.online.api = ['not'];
// is current browser opera?
// parameter is optional
is.opera = function(range) {
var match = userAgent.match(/(?:^opera.+?version|opr)\/(\d+)/);
return match !== null && compareVersion(match[1], range);
};
// opera method does not support 'all' and 'any' interfaces
is.opera.api = ['not'];
// is current browser opera mini?
// parameter is optional
is.operaMini = function(range) {
var match = userAgent.match(/opera mini\/(\d+)/);
return match !== null && compareVersion(match[1], range);
};
// operaMini method does not support 'all' and 'any' interfaces
is.operaMini.api = ['not'];
// is current browser phantomjs?
// parameter is optional
is.phantom = function(range) {
var match = userAgent.match(/phantomjs\/(\d+)/);
return match !== null && compareVersion(match[1], range);
};
// phantom method does not support 'all' and 'any' interfaces
is.phantom.api = ['not'];
// is current browser safari?
// parameter is optional
is.safari = function(range) {
var match = userAgent.match(/version\/(\d+).+?safari/);
return match !== null && compareVersion(match[1], range);
};
// safari method does not support 'all' and 'any' interfaces
is.safari.api = ['not'];
// is current device tablet?
is.tablet = function() {
return is.ipad() || is.androidTablet() || is.windowsTablet();
};
// tablet method does not support 'all' and 'any' interfaces
is.tablet.api = ['not'];
// is current device supports touch?
is.touchDevice = function() {
return !!document && ('ontouchstart' in freeSelf ||
('DocumentTouch' in freeSelf && document instanceof DocumentTouch));
};
// touchDevice method does not support 'all' and 'any' interfaces
is.touchDevice.api = ['not'];
// is current operating system windows?
is.windows = function() {
return /win/.test(platform);
};
// windows method does not support 'all' and 'any' interfaces
is.windows.api = ['not'];
// is current device windows phone?
is.windowsPhone = function() {
return is.windows() && /phone/.test(userAgent);
};
// windowsPhone method does not support 'all' and 'any' interfaces
is.windowsPhone.api = ['not'];
// is current device windows tablet?
is.windowsTablet = function() {
return is.windows() && is.not.windowsPhone() && /touch/.test(userAgent);
};
// windowsTablet method does not support 'all' and 'any' interfaces
is.windowsTablet.api = ['not'];
// Object checks
/* -------------------------------------------------------------------------- */
// has a given object got parameterized count property?
is.propertyCount = function(object, count) {
if (is.not.object(object) || is.not.number(count)) {
return false;
}
var n = 0;
for (var property in object) {
if (hasOwnProperty.call(object, property) && ++n > count) {
return false;
}
}
return n === count;
};
// propertyCount method does not support 'all' and 'any' interfaces
is.propertyCount.api = ['not'];
// is given object has parameterized property?
is.propertyDefined = function(object, property) {
return is.object(object) && is.string(property) && property in object;
};
// propertyDefined method does not support 'all' and 'any' interfaces
is.propertyDefined.api = ['not'];
// is a given value thenable (like Promise)?
is.thenable = function(value) {
return is.object(value) && typeof value.then === 'function';
};
// Array checks
/* -------------------------------------------------------------------------- */
// is a given item in an array?
is.inArray = function(value, array) {
if (is.not.array(array)) {
return false;
}
for (var i = 0; i < array.length; i++) {
if (array[i] === value) {
return true;
}
}
return false;
};
// inArray method does not support 'all' and 'any' interfaces
is.inArray.api = ['not'];
// is a given array sorted?
is.sorted = function(array, sign) {
if (is.not.array(array)) {
return false;
}
var predicate = comparator[sign] || comparator['>='];
for (var i = 1; i < array.length; i++) {
if (!predicate(array[i], array[i - 1])) {
return false;
}
}
return true;
};
// API
// Set 'not', 'all' and 'any' interfaces to methods based on their api property
/* -------------------------------------------------------------------------- */
function setInterfaces() {
var options = is;
for (var option in options) {
if (hasOwnProperty.call(options, option) && is['function'](options[option])) {
var interfaces = options[option].api || ['not', 'all', 'any'];
for (var i = 0; i < interfaces.length; i++) {
if (interfaces[i] === 'not') {
is.not[option] = not(is[option]);
}
if (interfaces[i] === 'all') {
is.all[option] = all(is[option]);
}
if (interfaces[i] === 'any') {
is.any[option] = any(is[option]);
}
}
}
}
}
setInterfaces();
// Configuration methods
// Intentionally added after setInterfaces function
/* -------------------------------------------------------------------------- */
// change namespace of library to prevent name collisions
// var preferredName = is.setNamespace();
// preferredName.odd(3);
// => true
is.setNamespace = function() {
root.is = previousIs;
return this;
};
// set optional regexes to methods
is.setRegexp = function(regexp, name) {
for (var r in regexes) {
if (hasOwnProperty.call(regexes, r) && (name === r)) {
regexes[r] = regexp;
}
}
};
return is;
}));
================================================
FILE: package.json
================================================
{
"name": "is_js",
"version": "0.9.0",
"main": "is.js",
"license": "MIT",
"description": "micro check library",
"homepage": "http://is.js.org/",
"repository": "arasatasaygin/is.js",
"scripts": {
"build": "npm run lint && npm run min",
"lint": "eslint .",
"min": "uglifyjs is.js -m --comments \"/^!/\" -o is.min.js",
"test": "mocha --check-leaks -R dot",
"test:phantom": "mocha-phantomjs -R dot test/index.html"
},
"pre-commit": [
"lint"
],
"devDependencies": {
"chai": "^3.4.0",
"eslint": "^2.13.1",
"lodash": "^4.15.0",
"mocha": "^2.2.1",
"mocha-phantomjs": "^4.1.0",
"pre-commit": "^1.1.3",
"uglify-js": "^2.7.3"
},
"files": [
"is.js",
"is.min.js"
]
}
================================================
FILE: test/.eslintrc.js
================================================
module.exports = {
env: {
mocha: true
},
globals: {
is: false,
chai: false
}
};
================================================
FILE: test/index.html
================================================
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>is.js tests</title>
<link rel="stylesheet" media="all" href="../node_modules/mocha/mocha.css">
</head>
<body>
<div id="mocha"></div>
<div id="messages"></div>
<div id="fixtures"></div>
<script src="../node_modules/lodash/lodash.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../is.js"></script>
<script>mocha.setup('bdd')</script>
<script src="test.js"></script>
<script>mocha.run()</script>
</body>
</html>
================================================
FILE: test/test.js
================================================
;(function(root) { // eslint-disable-line no-extra-semi
var _ = root._ || require('lodash'),
document = root.document,
expect = _.get(root, 'chai.expect') || require('chai').expect,
is = root.is || require('../is'),
window = root.window;
function checkApi(name, list) {
list || (list = ['all', 'any', 'not']);
_.each(['all', 'any', 'not'], function(api) {
var exists = _.includes(list, api);
describe('is.' + api + '.' + name, function() {
it('should ' + (exists ? '' : 'not ') + 'exist', function() {
expect(is[api][name]).to[exists ? 'be': 'not'].exist;
});
});
});
}
describe('type checks', function() {
describe('is.arguments', function() {
it('should return true if passed parameter type is arguments', function() {
var getArguments = function() {
return arguments;
};
var args = getArguments('test');
expect(is.arguments(args)).to.be.true;
});
it('should return false if passed parameter type is not arguments', function() {
var notArgs = ['test'];
expect(is.arguments(notArgs)).to.be.false;
});
});
checkApi('arguments');
describe('is.array', function() {
it('should return true if passed parameter type is array', function() {
var array = ['test'];
expect(is.array(array)).to.be.true;
});
it('should return false if passed parameter type is not array', function() {
var notArray = 'test';
expect(is.array(notArray)).to.be.false;
});
});
checkApi('array');
describe('is.boolean', function() {
it('should return true if passed parameter type is boolean', function() {
var bool = true;
expect(is.boolean(bool)).to.be.true;
});
it('should return false if passed parameter type is not boolean', function() {
var notBool = 'test';
expect(is.boolean(notBool)).to.be.false;
});
});
checkApi('boolean');
describe('is.date', function() {
it('should return true if passed parameter type is date', function() {
var date = new Date();
expect(is.date(date)).to.be.true;
});
it('should return false if passed parameter type is not date', function() {
var notDate = 'test';
expect(is.date(notDate)).to.be.false;
});
});
checkApi('date');
describe('is.error', function() {
it('should return true if passed parameter type is error', function() {
var error = new Error();
expect(is.error(error)).to.be.true;
});
it('should return false if passed parameter type is not error', function() {
var notError = 'test';
expect(is.error(notError)).to.be.false;
});
});
checkApi('error');
describe('is.function', function() {
it('should return true if passed parameter type is function', function() {
expect(is.function(is.function)).to.be.true;
});
it('should return false if passed parameter type is not function', function() {
var notFunction = 'test';
expect(is.function(notFunction)).to.be.false;
});
});
checkApi('function');
describe('is.nan', function() {
it('should return true if passed parameter type is NaN', function() {
expect(is.nan(NaN)).to.be.true;
});
it('should return false if passed parameter type is not NaN', function() {
var notNaN = 'test';
expect(is.nan(notNaN)).to.be.false;
});
});
checkApi('nan');
describe('is.null', function() {
it('should return true if passed parameter type is null', function() {
expect(is.null(null)).to.be.true;
});
it('should return false if passed parameter type is not null', function() {
var notNull = 'test';
expect(is.null(notNull)).to.be.false;
});
});
checkApi('null');
describe('is.number', function() {
it('should return true if passed parameter type is number', function() {
expect(is.number(1)).to.be.true;
});
it('should return false if passed parameter type is not number', function() {
var notNumber = 'test';
expect(is.number(notNumber)).to.be.false;
});
it('should return false if passed parameter is NaN', function() {
expect(is.number(NaN)).to.be.false;
})
});
checkApi('number');
describe('is.object', function() {
it('should return true if passed parameter type is object', function() {
expect(is.object({})).to.be.true;
});
it('should return false if passed parameter type is not object', function() {
var notObject = 'test';
expect(is.object(notObject)).to.be.false;
});
});
checkApi('object');
describe('is.json',function() {
it('should return true if passed parameter type is a json object', function() {
expect(is.json({})).to.be.true;
});
it('should return false if passed parameter type is not a json object', function() {
var notObject = 'test';
expect(is.json(notObject)).to.be.false;
});
});
checkApi('json');
describe('is.regexp', function() {
it('should return true if passed parameter type is regexp', function() {
var regexp = new RegExp();
expect(is.regexp(regexp)).to.be.true;
});
it('should return false if passed parameter type is not regexp', function() {
var notRegexp = 'test';
expect(is.regexp(notRegexp)).to.be.false;
});
});
checkApi('regexp');
describe('is.sameType', function() {
it('should return true if passed parameter types are same', function() {
expect(is.sameType(1, 2)).to.be.true;
expect(is.sameType('test', 'test')).to.be.true;
});
it('should return false if passed parameter types are not same', function() {
expect(is.sameType(1, 'test')).to.be.false;
});
});
checkApi('sameType', ['not']);
describe('is.char', function() {
it('should return true if passed parameter type is char', function() {
expect(is.char('t')).to.be.true;
});
it('should return false if passed parameter type is not a char', function() {
expect(is.char('test')).to.be.false;
});
});
checkApi('char');
describe('is.string', function() {
it('should return true if passed parameter type is string', function() {
expect(is.string('test')).to.be.true;
});
it('should return false if passed parameter type is not string', function() {
expect(is.string(1)).to.be.false;
});
});
checkApi('string');
describe('is.undefined', function() {
it('should return true if passed parameter type is undefined', function() {
expect(is.undefined(undefined)).to.be.true;
});
it('should return false if passed parameter type is not undefined', function() {
expect(is.undefined(null)).to.be.false;
expect(is.undefined('test')).to.be.false;
});
});
checkApi('undefined');
});
describe('presence checks', function() {
describe('is.empty', function() {
it('should return true if given array is empty', function() {
expect(is.empty([])).to.be.true;
});
it('should return false if given object is not empty', function() {
expect(is.empty({test: 'test'})).to.be.false;
});
});
checkApi('empty');
describe('is.existy', function() {
it('should return false if given value is null', function() {
expect(is.existy(null)).to.be.false;
});
it('should return false if given value is undefined', function() {
expect(is.existy(undefined)).to.be.false;
});
it('should return true if given value is not null or undefined', function() {
expect(is.existy('test')).to.be.true;
});
});
checkApi('existy');
describe('is.truthy', function() {
it('should return true if given value is truthy', function() {
expect(is.truthy('test')).to.be.true;
});
it('should return false if given value is not truthy', function() {
expect(is.truthy(undefined)).to.be.false;
});
it('should return false if given value is false', function() {
expect(is.truthy(false)).to.be.false;
});
});
checkApi('truthy');
describe('is.falsy', function() {
it('should return false if given value is truthy', function() {
expect(is.falsy('test')).to.be.false;
});
it('should return true if given value is falsy', function() {
expect(is.falsy(undefined)).to.be.true;
});
it('should return true if given value is false', function() {
expect(is.falsy(false)).to.be.true;
});
});
checkApi('falsy');
describe('is.space', function() {
it('should return false if given value is not string', function() {
expect(is.space(1)).to.be.false;
});
it('should return true if given value is space', function() {
expect(is.space(' ')).to.be.true;
});
});
checkApi('space');
});
describe('arithmetic checks', function() {
describe('is.equal', function() {
it('should return true if given two numbers are equal', function() {
expect(is.equal(3, 1 + 2)).to.be.true;
});
it('should return false if given two numbers are not equal', function() {
expect(is.equal(3, 2)).to.be.false;
});
it('should return true if given two strings are same', function() {
expect(is.equal('test', 'test')).to.be.true;
});
it('should return false if given two strings are not same', function() {
expect(is.equal('test', 'test2')).to.be.false;
});
it('should return true if given two boolean are same', function() {
expect(is.equal(false, false)).to.be.true;
});
it('should return false if given two boolean are not same', function() {
expect(is.equal(false, true)).to.be.false;
});
});
checkApi('equal', ['not']);
describe('is.even', function() {
it('should return true if given number is even', function() {
expect(is.even(2)).to.be.true;
});
it('should return false if given number is not even', function() {
expect(is.even(3)).to.be.false;
});
it('should return false if given number is not integer', function() {
expect(is.even(2.5)).to.be.false;
});
});
checkApi('even');
describe('is.odd', function() {
it('should return true if given number is odd', function() {
expect(is.odd(3)).to.be.true;
});
it('should return true if given number is negative odd', function() {
expect(is.odd(-3)).to.be.true;
});
it('should return false if given number is not odd', function() {
expect(is.odd(2)).to.be.false;
});
it('should return false if given number is not integer', function() {
expect(is.odd(2.5)).to.be.false;
});
});
checkApi('odd');
describe('is.positive', function() {
it('should return true if given number is positive', function() {
expect(is.positive(3)).to.be.true;
});
it('should return false if given number is not positive', function() {
expect(is.positive(-2)).to.be.false;
});
});
checkApi('positive');
describe('is.negative', function() {
it('should return true if given number is negative', function() {
expect(is.negative(-3)).to.be.true;
});
it('should return false if given number is not negative', function() {
expect(is.negative(2)).to.be.false;
});
});
checkApi('negative');
describe('is.above', function() {
it('should return true if given number is above minimum value', function() {
expect(is.above(13, 12)).to.be.true;
});
it('should return false if given number is not above minimum value', function() {
expect(is.above(12, 13)).to.be.false;
});
});
checkApi('above', ['not']);
describe('is.under', function() {
it('should return true if given number is under maximum value', function() {
expect(is.under(11, 12)).to.be.true;
});
it('should return false if given number is not under maximum value', function() {
expect(is.under(12, 11)).to.be.false;
});
});
checkApi('under', ['not']);
describe('is.within', function() {
it('should return true if given number is within minimum and maximum values', function() {
expect(is.within(10, 5, 15)).to.be.true;
});
it('should return false if given number is not within minimum and maximum values', function() {
expect(is.within(20, 5, 15)).to.be.false;
});
});
checkApi('within', ['not']);
describe('is.decimal', function() {
it('should return true if given number is decimal', function() {
expect(is.decimal(4.2)).to.be.true;
});
it('should return false if given number is not decimal', function() {
expect(is.decimal(2)).to.be.false;
});
});
checkApi('decimal');
describe('is.integer', function() {
it('should return true if given number is integer', function() {
expect(is.integer(4)).to.be.true;
});
it('should return false if given number is not integer', function() {
expect(is.integer(2.2)).to.be.false;
});
});
checkApi('integer');
describe('is.finite', function() {
it('should return true if given number is finite', function() {
expect(is.finite(4)).to.be.true;
});
it('should return false if given number is not finite', function() {
expect(is.finite(Infinity)).to.be.false;
});
});
checkApi('finite');
describe('is.infinite', function() {
it('should return true if given number is infinite', function() {
expect(is.infinite(Infinity)).to.be.true;
});
it('should return false if given number is not infinite', function() {
expect(is.infinite(1)).to.be.false;
expect(is.infinite(NaN)).to.be.false;
});
});
checkApi('infinite');
});
describe('regexp checks', function() {
describe('is.url', function() {
it('should return true if given value is url', function() {
expect(is.url('http://www.test.com')).to.be.true;
});
it('should return false if given value is not url', function() {
expect(is.url(1)).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.url(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.url(undefined)).to.be.false;
});
});
checkApi('url');
describe('is.email', function() {
it('should return true if given value is email', function() {
expect(is.email('test@test.com')).to.be.true;
});
it('should return false if given value is not email', function() {
expect(is.email('test@test')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.email(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.email(undefined)).to.be.false;
});
});
checkApi('email');
describe('is.creditCard', function() {
it('should return true if given value is credit card', function() {
expect(is.creditCard(378282246310005)).to.be.true;
});
it('should return false if given value is not credit card', function() {
expect(is.creditCard(123)).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.creditCard(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.creditCard(undefined)).to.be.false;
});
});
checkApi('creditCard');
describe('is.alphaNumeric', function() {
it('should return true if given value is alpha numeric', function() {
expect(is.alphaNumeric(123)).to.be.true;
});
it('should return false if given value is not alpha numeric', function() {
expect(is.alphaNumeric('*?')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.alphaNumeric(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.alphaNumeric(undefined)).to.be.false;
});
});
checkApi('alphaNumeric');
describe('is.timeString', function() {
it('should return true if given value is time string', function() {
expect(is.timeString('13:45:30')).to.be.true;
});
it('should return false if given value is not time string', function() {
expect(is.timeString('12:12:90')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.timeString(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.timeString(undefined)).to.be.false;
});
});
checkApi('timeString');
describe('is.dateString', function() {
it('should return true if given value is date string', function() {
expect(is.dateString('11/11/2011')).to.be.true;
expect(is.dateString('10-21-2012')).to.be.true;
});
it('should return false if given value is not date string', function() {
expect(is.dateString('1')).to.be.false;
expect(is.dateString('10/21-2012')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.dateString(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.dateString(undefined)).to.be.false;
});
});
checkApi('dateString');
describe('is.usZipCode', function() {
it('should return true if given value is US zip code', function() {
expect(is.usZipCode('02201-1020')).to.be.true;
});
it('should return false if given value is not US zip code', function() {
expect(is.usZipCode('1')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.usZipCode(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.usZipCode(undefined)).to.be.false;
});
});
checkApi('usZipCode');
describe('is.caPostalCode', function() {
it('should return true if given value is Canada postal code', function() {
expect(is.caPostalCode('L8V3Y1')).to.be.true;
});
it('should return true if given value is Canada postal code with space', function() {
expect(is.caPostalCode('L8V 3Y1')).to.be.true;
});
it('should return false if given value is not Canada postal code', function() {
expect(is.caPostalCode('1')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.caPostalCode(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.caPostalCode(undefined)).to.be.false;
});
});
checkApi('caPostalCode');
describe('is.ukPostCode', function() {
it('should return true if given value is UK post code', function() {
expect(is.ukPostCode('B184BJ')).to.be.true;
});
it('should return false if given value is not UK post code', function() {
expect(is.ukPostCode('1')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.ukPostCode(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.ukPostCode(undefined)).to.be.false;
});
});
checkApi('ukPostCode');
describe('is.nanpPhone', function() {
it('should return true if given value is nanpPhone', function() {
expect(is.nanpPhone('609-555-0175')).to.be.true;
});
it('should return false if given value is not nanpPhone', function() {
expect(is.nanpPhone('1')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.nanpPhone(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.nanpPhone(undefined)).to.be.false;
});
});
checkApi('nanpPhone');
describe('is.eppPhone', function() {
it('should return true if given value is eppPhone', function() {
expect(is.eppPhone('+90.2322456789')).to.be.true;
});
it('should return false if given value is not eppPhone', function() {
expect(is.eppPhone('1')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.eppPhone(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.eppPhone(undefined)).to.be.false;
});
});
checkApi('eppPhone');
describe('is.socialSecurityNumber', function() {
it('should return true if given value is socialSecurityNumber', function() {
expect(is.socialSecurityNumber('017-90-7890')).to.be.true;
expect(is.socialSecurityNumber('017907890')).to.be.true;
});
it('should return false if given value is not socialSecurityNumber', function() {
expect(is.socialSecurityNumber('1')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.socialSecurityNumber(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.socialSecurityNumber(undefined)).to.be.false;
});
});
checkApi('socialSecurityNumber');
describe('is.affirmative', function() {
it('should return true if given value is affirmative', function() {
expect(is.affirmative('yes')).to.be.true;
});
it('should return false if given value is not affirmative', function() {
expect(is.affirmative('no')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.affirmative(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.affirmative(undefined)).to.be.false;
});
});
checkApi('affirmative');
describe('is.hexadecimal', function() {
it('should return true if given value is hexadecimal', function() {
expect(is.hexadecimal('ff')).to.be.true;
expect(is.hexadecimal('0xff')).to.be.true;
});
it('should return false if given value is not hexadecimal', function() {
expect(is.hexadecimal(0.287)).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.hexadecimal(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.hexadecimal(undefined)).to.be.false;
});
});
checkApi('hexadecimal');
describe('is.hexColor', function() {
it('should return true if given value is hexColor', function() {
expect(is.hexColor('#333')).to.be.true;
});
it('should return false if given value is not hexColor', function() {
expect(is.hexColor(0.287)).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.hexColor(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.hexColor(undefined)).to.be.false;
});
});
checkApi('hexColor');
describe('is.ip', function() {
it('should return true if given value is a valid IP address', function() {
expect(is.ip('2001:DB8:0:0:1::1')).to.be.true;
});
it('should return false if given value is not a valid IP address', function() {
expect(is.ip('985.12.3.4')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.ip(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.ip(undefined)).to.be.false;
});
});
checkApi('ip');
describe('is.ipv4', function() {
it('should return true if given value is a valid IPv4 address', function() {
expect(is.ipv4('198.12.3.142')).to.be.true;
});
it('should return false if given value is not a valid IPv4 address', function() {
expect(is.ipv4('985.12.3.4')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.ipv4(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.ipv4(undefined)).to.be.false;
});
});
checkApi('ipv4');
describe('is.ipv6', function() {
it('should return true if given value is a valid IPv6 address', function() {
expect(is.ipv6('2001:DB8:0:0:1::1')).to.be.true;
});
it('should return false if given value is not a valid IPv6 address', function() {
expect(is.ipv6('985.12.3.4')).to.be.false;
});
it('should return false if the given value is null', function() {
expect(is.ipv6(null)).to.be.false;
});
it('should return false if the given value is undefined', function() {
expect(is.ipv6(undefined)).to.be.false;
});
});
checkApi('ipv6');
});
describe('string checks', function() {
describe('is.include', function() {
it('should return true if given string contains substring', function() {
expect(is.include('test.com', 't.com')).to.be.true;
});
it('should return false if given string does not contain substring', function() {
expect(is.include('test.com', 'nope')).to.be.false;
});
});
checkApi('include', ['not']);
describe('is.upperCase', function() {
it('should return true if given string is uppercase', function() {
expect(is.upperCase('TEST')).to.be.true;
});
it('should return false if given string is not uppercase', function() {
expect(is.upperCase('test')).to.be.false;
});
});
checkApi('upperCase');
describe('is.lowerCase', function() {
it('should return true if given string is lowerCase', function() {
expect(is.lowerCase('test')).to.be.true;
});
it('should return false if given string is not lowerCase', function() {
expect(is.lowerCase('TEST')).to.be.false;
});
});
checkApi('lowerCase');
describe('is.startWith', function() {
it('should return true if given string starts with substring', function() {
expect(is.startWith('test', 'te')).to.be.true;
});
it('should return false if given string does not start with substring', function() {
expect(is.startWith('test', 'st')).to.be.false;
});
});
checkApi('startWith', ['not']);
describe('is.endWith', function() {
it('should return true if given string ends with substring', function() {
expect(is.endWith('test', 't')).to.be.true;
expect(is.endWith('test', 'st')).to.be.true;
});
it('should return false if given string does not end with substring', function() {
expect(is.endWith('test', 'te')).to.be.false;
});
it('should prevent true return if endWith is not present in the string', function() {
expect(is.endWith('id', '_id')).to.be.false;
});
});
checkApi('endWith', ['not']);
describe('is.capitalized', function() {
it('should return true if given string is capitalized', function() {
expect(is.capitalized('Test')).to.be.true;
});
it('should return false if given string is not capitalized', function() {
expect(is.capitalized('test')).to.be.false;
});
it('should return true if words are capitalized', function() {
expect(is.capitalized('Test Is Good')).to.be.true;
expect(is.capitalized('Test Is Good')).to.be.true;
});
it('should return false if words are not capitalized', function() {
expect(is.capitalized('Test is good')).to.be.false;
});
});
checkApi('capitalized');
describe('is.palindrome', function() {
it('should return true if given string is palindrome', function() {
expect(is.palindrome('abba')).to.be.true;
expect(is.palindrome('testset')).to.be.true;
expect(is.palindrome('A man, a plan, a canal - Panama!')).to.be.true;
});
it('should return false if given string is not palindrome', function() {
expect(is.palindrome('test')).to.be.false;
});
});
checkApi('palindrome');
});
describe('time checks', function() {
describe('is.today', function() {
it('should return true if given date is today', function() {
var date = new Date();
expect(is.today(date)).to.be.true;
});
it('should return false if given date is not today', function() {
var date = new Date();
expect(is.today(date.setDate(date.getDate() - 1))).to.be.false;
});
});
checkApi('today');
describe('is.yesterday', function() {
it('should return true if given date is yesterday', function() {
var date = new Date();
var yesterday = new Date(date.setDate(date.getDate() - 1));
expect(is.yesterday(yesterday)).to.be.true;
});
it('should return false if given date is not yesterday', function() {
var date = new Date();
expect(is.yesterday(date)).to.be.false;
});
});
checkApi('yesterday');
describe('is.tomorrow', function() {
it('should return true if given date is tomorrow', function() {
var date = new Date();
var tomorrow = new Date(date.setDate(date.getDate() + 1));
expect(is.tomorrow(tomorrow)).to.be.true;
});
it('should return false if given date is not tomorrow', function() {
var date = new Date();
expect(is.tomorrow(date)).to.be.false;
});
});
checkApi('tomorrow');
describe('is.past', function() {
it('should return true if given date is past', function() {
var date = new Date();
var past = new Date(date.setDate(date.getDate() - 1));
expect(is.past(past)).to.be.true;
});
it('should return false if given date is not past', function() {
var date = new Date();
expect(is.past(date)).to.be.false;
});
});
checkApi('past');
describe('is.future', function() {
it('should return true if given date is future', function() {
var date = new Date();
var future = new Date(date.setDate(date.getDate() + 1));
expect(is.future(future)).to.be.true;
});
it('should return false if given date is not future', function() {
var date = new Date();
var past = new Date(date.setDate(date.getDate() - 1));
expect(is.future(date)).to.be.false;
expect(is.future(past)).to.be.false;
});
});
checkApi('future');
describe('is.day', function() {
it('should return true if given day string is the day of the date object', function() {
var time = 1421572235303;
expect(is.day(new Date(time), 'sunday')).to.be.true;
});
it('should return false if given day string is not the day of the date object', function() {
var time = 1421572235303;
expect(is.day(new Date(time), 'monday')).to.be.false;
});
});
checkApi('day', ['not']);
describe('is.month', function() {
it('should return true if given month string is the month of the date object', function() {
var time = 1421572235303;
expect(is.month(new Date(time), 'january')).to.be.true;
});
it('should return false if given month string is not the month of the date object', function() {
var time = 1421572235303;
expect(is.month(new Date(time), 'february')).to.be.false;
});
});
checkApi('month', ['not']);
describe('is.year', function() {
it('should return true if given year string is the year of the date object', function() {
var time = 1421572235303;
expect(is.year(new Date(time), 2015)).to.be.true;
});
it('should return false if given year string is not the year of the date object', function() {
var time = 1421572235303;
expect(is.year(new Date(time), 2016)).to.be.false;
});
});
checkApi('year', ['not']);
describe('is.leapYear', function() {
it('should return true if given year is a leap year', function() {
expect(is.leapYear(2016)).to.be.true;
});
it('should return false if given year is not a leap year', function() {
expect(is.leapYear(2015)).to.be.false;
});
});
checkApi('leapYear');
describe('is.weekend', function() {
it('should return true if given date is weekend', function() {
var time = 1421572235303;
expect(is.weekend(new Date(time))).to.be.true;
});
it('should return false if given date is not weekend', function() {
var time = 1421572235303;
var date = new Date(time);
var friday = new Date(date.setDate(date.getDate() - 2));
expect(is.weekend(friday)).to.be.false;
});
});
checkApi('weekend');
describe('is.weekday', function() {
it('should return true if given date is weekday', function() {
var time = 1421572235303;
var date = new Date(time);
var friday = new Date(date.setDate(date.getDate() - 2));
expect(is.weekday(friday)).to.be.true;
});
it('should return false if given date is not weekday', function() {
var time = 1421572235303;
var sunday = new Date(time);
expect(is.weekday(sunday)).to.be.false;
});
});
checkApi('weekday');
describe('is.inDateRange', function() {
it('should return true if date is within given start date and end date', function() {
var today = new Date();
var date = new Date();
var tomorrow = new Date(date.setDate(date.getDate() + 1));
var yesterday = new Date(date.setDate(date.getDate() - 2));
expect(is.inDateRange(today, yesterday, tomorrow)).to.be.true;
});
it('should return false if date is not within given start date and end date', function() {
var today = new Date();
var date = new Date();
var tomorrow = new Date(date.setDate(date.getDate() + 1));
var yesterday = new Date(date.setDate(date.getDate() - 2));
expect(is.inDateRange(yesterday, today, tomorrow)).to.be.false;
});
});
checkApi('inDateRange', ['not']);
describe('is.inLastWeek', function() {
it('should return true if date is within last week', function() {
var date = new Date();
var twoDaysAgo = new Date(date.setDate(date.getDate() - 2));
expect(is.inLastWeek(twoDaysAgo)).to.be.true;
});
it('should return false if date is not within last week', function() {
var date = new Date();
var eightDaysAgo = new Date(date.setDate(date.getDate() - 8));
expect(is.inLastWeek(eightDaysAgo)).to.be.false;
});
});
checkApi('inLastWeek');
describe('is.inLastMonth', function() {
it('should return true if date is within last month', function() {
var date = new Date();
var tenDaysAgo = new Date(date.setDate(date.getDate() - 10));
expect(is.inLastMonth(tenDaysAgo)).to.be.true;
});
it('should return false if date is not within last month', function() {
var date = new Date();
var fiftyDaysAgo = new Date(date.setDate(date.getDate() - 50));
expect(is.inLastMonth(fiftyDaysAgo)).to.be.false;
});
});
checkApi('inLastMonth');
describe('is.inLastYear', function() {
it('should return true if date is within last year', function() {
var date = new Date();
var threeMonthsAgo = new Date(date.setMonth(date.getMonth() - 3));
expect(is.inLastYear(threeMonthsAgo)).to.be.true;
});
it('should return false if date is not within last year', function() {
var date = new Date();
var future = new Date(date.setDate(date.getDate() + 1));
expect(is.inLastYear(future)).to.be.false;
});
});
checkApi('inLastYear');
describe('is.inNextWeek', function() {
it('should return true if date is within next week', function() {
var date = new Date();
var future = new Date(date.setDate(date.getDate() + 1));
expect(is.inNextWeek(future)).to.be.true;
});
it('should return false if date is not within next week', function() {
var date = new Date();
var yesterday = new Date(date.setDate(date.getDate() - 1));
expect(is.inNextWeek(yesterday)).to.be.false;
});
});
checkApi('inNextWeek');
describe('is.inNextMonth', function() {
it('should return true if date is within next month', function() {
var date = new Date();
var aWeekLater = new Date(date.setDate(date.getDate() + 7));
expect(is.inNextMonth(aWeekLater)).to.be.true;
});
it('should return false if date is not within next month', function() {
var date = new Date();
var yesterday = new Date(date.setDate(date.getDate() - 1));
expect(is.inNextMonth(yesterday)).to.be.false;
});
});
checkApi('inNextMonth');
describe('is.inNextYear', function() {
it('should return true if date is within next year', function() {
var date = new Date();
var threeMonthsLater = new Date(date.setMonth(date.getMonth() + 3));
expect(is.inNextYear(threeMonthsLater)).to.be.true;
});
it('should return false if date is not within next year', function() {
var date = new Date();
var past = new Date(date.setDate(date.getDate() - 1));
expect(is.inNextYear(past)).to.be.false;
});
});
checkApi('inNextYear');
describe('is.quarterOfYear', function() {
it('should return true if given quarter is the quarter of the date object', function() {
var time = 1421572235303;
var date = new Date(time);
expect(is.quarterOfYear(date, 1)).to.be.true;
});
it('should return false if given quarter is not the quarter of the date object', function() {
var time = 1421572235303;
var date = new Date(time);
expect(is.quarterOfYear(date, 2)).to.be.false;
});
});
checkApi('quarterOfYear', ['not']);
describe('is.dayLightSavingTime', function() {
it('should return false if given date is not in daylight saving time', function() {
var time = 1421572235303;
var date = new Date(time);
expect(is.dayLightSavingTime(date)).to.be.false;
});
it('should return false if given date is in daylight saving time', function() {
var time = 1421572235303;
var date = new Date(time);
var sixMonthsAgo = new Date(date.setMonth(date.getMonth() - 6));
expect(is.dayLightSavingTime(sixMonthsAgo)).to.be.true;
});
});
checkApi('dayLightSavingTime');
});
describe('object checks', function() {
describe('is.propertyCount', function() {
it('should return true if given count matches that of the object', function() {
var obj = {
test: 'test',
is: 'is',
good: 'good'
};
expect(is.propertyCount(obj, 3)).to.be.true;
});
it('should return false if given count does not match that of the object', function() {
var obj = {
test: 'test',
is: 'is'
};
expect(is.propertyCount(obj, 3)).to.be.false;
});
});
checkApi('propertyCount', ['not']);
describe('is.propertyDefined', function() {
it('should return true if given property is in objects', function() {
var obj = {
test: 'test',
is: 'is',
good: 'good'
};
expect(is.propertyDefined(obj, 'good')).to.be.true;
});
it('should return false if given property is not in objects', function() {
var obj = {
test: 'test',
is: 'is'
};
expect(is.propertyDefined(obj, 'good')).to.be.false;
});
});
checkApi('propertyDefined', ['not']);
describe('is.windowObject', function() {
it('should return true if given object is window object', function() {
expect(is.windowObject(window)).to.be[!!window];
});
it('should return false if given object is not window object', function() {
expect(is.windowObject({})).to.be.false;
});
});
checkApi('windowObject');
describe('is.domNode', function() {
it('should return true if given object is a DOM node', function() {
var obj = document && document.createElement('div');
expect(is.domNode(obj)).to.be[!!document];
});
it('should return false if given object is not a DOM node', function() {
expect(is.domNode({})).to.be.false;
});
});
checkApi('domNode');
describe('is.thenable', function() {
it('should return true if passed parameter type is Promise', function() {
var promise = Promise.resolve(true); // eslint-disable-line no-undef
expect(is.thenable(promise)).to.be.true;
});
it('should return false if passed parameter type is not Promise', function() {
var notPromise = 'test';
expect(is.thenable(notPromise)).to.be.false;
});
});
checkApi('thenable');
});
describe('array checks', function() {
describe('is.sorted', function() {
it('should return true if given array is sorted', function() {
var array1 = [1, 2, 3, 4, 5];
expect(is.sorted(array1)).to.be.true;
expect(is.sorted(array1, '>=')).to.be.true;
expect(is.sorted(array1, '>')).to.be.true;
expect(is.sorted(array1, '<=')).to.be.false;
expect(is.sorted(array1, '<')).to.be.false;
var array2 = [5, 4, 4, 3, 1];
expect(is.sorted(array2)).to.be.false;
expect(is.sorted(array2, '>=')).to.be.false;
expect(is.sorted(array2, '>')).to.be.false;
expect(is.sorted(array2, '<=')).to.be.true;
expect(is.sorted(array2, '<')).to.be.false;
var array3 = [10];
expect(is.sorted(array3)).to.be.true;
expect(is.sorted(array3, '>=')).to.be.true;
expect(is.sorted(array3, '>')).to.be.true;
expect(is.sorted(array3, '<=')).to.be.true;
expect(is.sorted(array3, '<')).to.be.true;
});
it('should return false if given array is not sorted', function() {
var array = [1, 2, 3, 5, 4];
expect(is.sorted(array)).to.be.false;
expect(is.sorted(array, '>=')).to.be.false;
expect(is.sorted(array, '>')).to.be.false;
expect(is.sorted(array, '<=')).to.be.false;
expect(is.sorted(array, '<')).to.be.false;
});
});
checkApi('sorted');
describe('is.inArray', function() {
it('should return true if the item is in the array', function() {
var value = 3;
var array = [1, 4, 6, 7, 3];
expect(is.inArray(value, array)).to.be.true;
});
it('should return false if the item is not in the array', function() {
var value = 2;
var array = [1, 4, 6, 7, 3];
expect(is.inArray(value, array)).to.be.false;
});
});
checkApi('inArray', ['not']);
});
}(this));
gitextract_38eizkuu/
├── .editorconfig
├── .eslintignore
├── .eslintrc.js
├── .gitattributes
├── .gitignore
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── bower.json
├── is.js
├── package.json
└── test/
├── .eslintrc.js
├── index.html
└── test.js
SYMBOL INDEX (8 symbols across 2 files)
FILE: is.js
function not (line 45) | function not(func) {
function all (line 52) | function all(func) {
function any (line 66) | function any(func) {
function compareVersion (line 88) | function compareVersion(version, range) {
function getParams (line 96) | function getParams(args) {
function regexpCheck (line 351) | function regexpCheck(regexp, regexes) {
function setInterfaces (line 878) | function setInterfaces() {
FILE: test/test.js
function checkApi (line 8) | function checkApi(name, list) {
Condensed preview — 15 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (141K chars).
[
{
"path": ".editorconfig",
"chars": 557,
"preview": "# EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs.\n# See h"
},
{
"path": ".eslintignore",
"chars": 10,
"preview": "is.min.js\n"
},
{
"path": ".eslintrc.js",
"chars": 235,
"preview": "module.exports = {\n extends: 'eslint:recommended',\n env: {\n browser: true,\n node: true,\n amd:"
},
{
"path": ".gitattributes",
"chars": 12,
"preview": "* text=auto\n"
},
{
"path": ".gitignore",
"chars": 46,
"preview": ".DS_Store\n*.log\nbower_components\nnode_modules\n"
},
{
"path": ".travis.yml",
"chars": 281,
"preview": "language: node_js\nsudo: false\nnode_js:\n - \"4\"\n - \"6\"\ncache:\n directories:\n - $HOME/.npm\ngit:\n depth: 10\nbranches:"
},
{
"path": "CONTRIBUTING.md",
"chars": 941,
"preview": "# Contributing to is.js\n\n## General Guidelines\n\nThanks for considering to contribute is.js\n\n- Please don’t re-build mini"
},
{
"path": "LICENSE",
"chars": 1086,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2014-2016 Aras Atasaygin\n\nPermission is hereby granted, free of charge, to any pers"
},
{
"path": "README.md",
"chars": 45887,
"preview": "is.js\n=====\n\n[](http://js.org)\n\n#### This "
},
{
"path": "bower.json",
"chars": 163,
"preview": "{\n \"name\": \"is_js\",\n \"main\": \"is.js\",\n \"ignore\": [\n \"bower_components\",\n \"node_modules\",\n \"test\",\n \"**/.*"
},
{
"path": "is.js",
"chars": 33345,
"preview": "/*!\n * is.js 0.9.0\n * Author: Aras Atasaygin\n */\n\n// AMD with global, Node, or global\n;(function(root, factory) { // "
},
{
"path": "package.json",
"chars": 744,
"preview": "{\n \"name\": \"is_js\",\n \"version\": \"0.9.0\",\n \"main\": \"is.js\",\n \"license\": \"MIT\",\n \"description\": \"micro check library\""
},
{
"path": "test/.eslintrc.js",
"chars": 120,
"preview": "module.exports = {\n env: {\n mocha: true\n },\n globals: {\n is: false,\n chai: false\n }\n};\n"
},
{
"path": "test/index.html",
"chars": 608,
"preview": "<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\">\n <title>is.js tests</title>\n <link rel=\"stylesheet\" media"
},
{
"path": "test/test.js",
"chars": 51077,
"preview": ";(function(root) { // eslint-disable-line no-extra-semi\n var _ = root._ || require('lodash'),\n document = r"
}
]
About this extraction
This page contains the full source code of the arasatasaygin/is.js GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 15 files (131.9 KB), approximately 33.4k tokens, and a symbol index with 8 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.