Sha256: 3ecc7f581f7fb05285603cda3ad834641764469649e274abaea1fc91ec873b4d

Contents?: true

Size: 1.53 KB

Versions: 11

Compression:

Stored size: 1.53 KB

Contents

# simple-is.js
A maximally minimal type-testing library. Use it to make your code
more readable. Works in node and browsers.



## Usage
`var is = require("simple-is");`

Use `is.number(x)` instead of `typeof x === "number"` (also `is.boolean`, `is.string`, `is.fn`).

Use `is.nan(x)` instead of `typeof x === "number" && isNaN(x)`, `x !== x` or ES6 `Number.isNaN(x)`.

Use `is.object(x)` instead of `x !== null && typeof x === "object"`.

Use `is.primitive(x)` instead of `x === null || x === undefined || typeof x === "boolean" || typeof x === "number" || typeof x === "string"` (verbose on purpose).

Use `is.array(x)` instead of ES5 `Array.isArray`.

Use `is.finitenumber(x)` instead of `typeof x === "number" && isFinite(x)` or ES6 `Number.isFinite(x)`.

Use `is.someof(x, ["first", 2, obj])` instead of (usually) `x === "first" || x === 2 || x === obj` or (alternatively)  `["first", 2, obj].indexOf(x) >= 0`. Great for reducing copy and paste mistake in `if`-conditions and for making them more readable.

Use `is.noneof(x, ["first", 2, obj])` instead of (usually) `x !== "first" && x !== 2 && x !== obj` or (alternatively)  `["first", 2, obj].indexOf(x) === -1`.

Use `is.own(x, "name")` instead of `Object.prototype.hasOwnProperty.call(x, "name")`.

That's it.



## Installation

### Node
Install using npm

    npm install simple-is

```javascript
var is = require("simple-is");
```

### Browser
Clone the repo and include it in a script tag

    git clone https://github.com/olov/simple-is.git

```html
<script src="simple-is/simple-is.js"></script>
```

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
ilog-0.4.1 node_modules/simple-is/README.md
ilog-0.4.0 node_modules/simple-is/README.md
ilog-0.3.3 node_modules/simple-is/README.md
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/simple-is/README.md
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/simple-is/README.md
es6_tilt-0.1.2 test/dummy/app/assets/javascripts/node_modules/simple-is/README.md
es6_tilt-0.1.1 test/dummy/app/assets/javascripts/node_modules/simple-is/README.md
es6_tilt-0.1.0 test/dummy/app/assets/javascripts/node_modules/simple-is/README.md
gulp_assets-1.0.0.pre.5 template/node_modules/babel-core/node_modules/regenerator/node_modules/defs/node_modules/simple-is/README.md
gulp_assets-1.0.0.pre.4 template/node_modules/babel-core/node_modules/regenerator/node_modules/defs/node_modules/simple-is/README.md
gulp_assets-1.0.0.pre.3 template/node_modules/babel-core/node_modules/regenerator/node_modules/defs/node_modules/simple-is/README.md