1 |
3a515b92
|
cagy
|
#object-is <sup>[![Version Badge][2]][1]</sup>
|
2 |
|
|
|
3 |
|
|
[![Build Status][3]][4]
|
4 |
|
|
[![dependency status][5]][6]
|
5 |
|
|
[![dev dependency status][7]][8]
|
6 |
|
|
[![License][license-image]][license-url]
|
7 |
|
|
[![Downloads][downloads-image]][downloads-url]
|
8 |
|
|
|
9 |
|
|
[![npm badge][11]][1]
|
10 |
|
|
|
11 |
|
|
ES2015-compliant shim for Object.is - differentiates between -0 and +0, and can compare to NaN.
|
12 |
|
|
|
13 |
|
|
Essentially, Object.is returns the same value as === - but true for NaN, and false for -0 and +0.
|
14 |
|
|
|
15 |
|
|
## Example
|
16 |
|
|
|
17 |
|
|
```js
|
18 |
|
|
Object.is = require('object-is');
|
19 |
|
|
var assert = require('assert');
|
20 |
|
|
|
21 |
|
|
assert.ok(Object.is());
|
22 |
|
|
assert.ok(Object.is(undefined));
|
23 |
|
|
assert.ok(Object.is(undefined, undefined));
|
24 |
|
|
assert.ok(Object.is(null, null));
|
25 |
|
|
assert.ok(Object.is(true, true));
|
26 |
|
|
assert.ok(Object.is(false, false));
|
27 |
|
|
assert.ok(Object.is('foo', 'foo'));
|
28 |
|
|
|
29 |
|
|
var arr = [1, 2];
|
30 |
|
|
assert.ok(Object.is(arr, arr));
|
31 |
|
|
assert.notOk(Object.is(arr, [1, 2]));
|
32 |
|
|
|
33 |
|
|
assert.ok(Object.is(0, 0));
|
34 |
|
|
assert.ok(Object.is(-0, -0));
|
35 |
|
|
assert.notOk(Object.is(0, -0));
|
36 |
|
|
|
37 |
|
|
assert.ok(Object.is(NaN, NaN));
|
38 |
|
|
assert.ok(Object.is(Infinity, Infinity));
|
39 |
|
|
assert.ok(Object.is(-Infinity, -Infinity));
|
40 |
|
|
```
|
41 |
|
|
|
42 |
|
|
## Tests
|
43 |
|
|
Simply clone the repo, `npm install`, and run `npm test`
|
44 |
|
|
|
45 |
|
|
[1]: https://npmjs.org/package/object-is
|
46 |
|
|
[2]: http://versionbadg.es/es-shims/object-is.svg
|
47 |
|
|
[3]: https://travis-ci.org/es-shims/object-is.svg
|
48 |
|
|
[4]: https://travis-ci.org/es-shims/object-is
|
49 |
|
|
[5]: https://david-dm.org/es-shims/object-is.svg
|
50 |
|
|
[6]: https://david-dm.org/es-shims/object-is
|
51 |
|
|
[7]: https://david-dm.org/es-shims/object-is/dev-status.svg
|
52 |
|
|
[8]: https://david-dm.org/es-shims/object-is#info=devDependencies
|
53 |
|
|
[11]: https://nodei.co/npm/object-is.png?downloads=true&stars=true
|
54 |
|
|
[license-image]: http://img.shields.io/npm/l/object-is.svg
|
55 |
|
|
[license-url]: LICENSE
|
56 |
|
|
[downloads-image]: http://img.shields.io/npm/dm/object-is.svg
|
57 |
|
|
[downloads-url]: http://npm-stat.com/charts.html?package=object-is
|