An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

[![Build Status](https://travis-ci.com/georapbox/is-api.svg?branch=master)](https://travis-ci.com/georapbox/is-api)
[![npm version](https://img.shields.io/npm/v/is-api.svg)](http://badge.fury.io/js/is-api)
[![npm downloads](https://img.shields.io/npm/dt/is-api.svg)](http://badge.fury.io/js/is-api)
[![npm license](https://img.shields.io/npm/l/is-api.svg)](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)