https://github.com/georapbox/is-api
Tiny javascript library that you can extend with your own type checking methods.
https://github.com/georapbox/is-api
is javascript javascript-library type-checking
Last synced: 3 months ago
JSON representation
Tiny javascript library that you can extend with your own type checking methods.
- Host: GitHub
- URL: https://github.com/georapbox/is-api
- Owner: georapbox
- License: mit
- Created: 2017-10-12T10:40:37.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-02-09T08:19:42.000Z (about 4 years ago)
- Last Synced: 2025-10-26T03:51:54.136Z (5 months ago)
- Topics: is, javascript, javascript-library, type-checking
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.com/georapbox/is-api)
[](http://badge.fury.io/js/is-api)
[](http://badge.fury.io/js/is-api)
[](http://badge.fury.io/js/is-api)
# is-api
Inspired by the [is.js](http://is.js.org/) micro library, this is tiny javascript library that you can extend with your own type checking (and more) methods and benefit from the interfaces `not`, `all` and `any` the library provides with.
By default, the library is "naked". Use the `extend()` method to provide it with your own type checking methods.
## Why?
Because I liked the idea to do my type checks using a more functional way, but I also wanted to include only the methods I needed at any project.
## Install
### npm
```sh
$ npm install --save is-api
```
### GIT
```sh
$ git clone https://github.com/georapbox/is-api.git
```
## Usage example
```js
var is = require('is-api');
is.extend({
'array': Array.isArray,
'greaterThanFive': function (value) {
return val > 5;
}
});
// Check if a value is array
is.array([1, 2, 3]);
// -> true
is.array({foo: 'bar'});
// -> false
// Check if a value is NOT an array
is.not.array([1, 2, 3]);
// -> false
is.not.array({foo: 'bar'});
// -> true
// Check if all values are arrays
is.all.array([1, 2, 3], ['a', 'b', 'c']);
// -> true
is.all.array([1, 2, 3], 10);
// -> false
// Check if any of the values are arrays
is.any.array([1, 2, 3], 10);
// -> true
is.any.array(5, 10);
// -> false
// Check if a value is greater than 5
is.greaterThanFive(6);
// -> true
is.greaterThanFive(3);
// -> false
is.not.greaterThanFive(6);
// -> false
is.not.greaterThanFive(3);
// -> true
is.any.greaterThanFive(3, 7);
// -> true
is.any.greaterThanFive(2, 5, 4);
// -> false
is.all.greaterThanFive(6, 10, 45);
// -> true
```
## No Conflict
When the library is used in a normal browser global namespace environment, you can use `noConflict()` method which returns the current API instance to you in order not to pollute your global namespace.
```js
var utils = {};
utils.is = is.noConflict();
utils.is.extend({...});
```
## License
[The MIT License (MIT)](https://georapbox.mit-license.org/@2017)