[6a3a178] | 1 | #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 | This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the [spec](https://tc39.es/ecma262).
|
---|
| 16 |
|
---|
| 17 | ## Example
|
---|
| 18 |
|
---|
| 19 | ```js
|
---|
| 20 | Object.is = require('object-is');
|
---|
| 21 | var assert = require('assert');
|
---|
| 22 |
|
---|
| 23 | assert.ok(Object.is());
|
---|
| 24 | assert.ok(Object.is(undefined));
|
---|
| 25 | assert.ok(Object.is(undefined, undefined));
|
---|
| 26 | assert.ok(Object.is(null, null));
|
---|
| 27 | assert.ok(Object.is(true, true));
|
---|
| 28 | assert.ok(Object.is(false, false));
|
---|
| 29 | assert.ok(Object.is('foo', 'foo'));
|
---|
| 30 |
|
---|
| 31 | var arr = [1, 2];
|
---|
| 32 | assert.ok(Object.is(arr, arr));
|
---|
| 33 | assert.notOk(Object.is(arr, [1, 2]));
|
---|
| 34 |
|
---|
| 35 | assert.ok(Object.is(0, 0));
|
---|
| 36 | assert.ok(Object.is(-0, -0));
|
---|
| 37 | assert.notOk(Object.is(0, -0));
|
---|
| 38 |
|
---|
| 39 | assert.ok(Object.is(NaN, NaN));
|
---|
| 40 | assert.ok(Object.is(Infinity, Infinity));
|
---|
| 41 | assert.ok(Object.is(-Infinity, -Infinity));
|
---|
| 42 | ```
|
---|
| 43 |
|
---|
| 44 | ## Tests
|
---|
| 45 | Simply clone the repo, `npm install`, and run `npm test`
|
---|
| 46 |
|
---|
| 47 | [1]: https://npmjs.org/package/object-is
|
---|
| 48 | [2]: http://versionbadg.es/es-shims/object-is.svg
|
---|
| 49 | [3]: https://travis-ci.org/es-shims/object-is.svg
|
---|
| 50 | [4]: https://travis-ci.org/es-shims/object-is
|
---|
| 51 | [5]: https://david-dm.org/es-shims/object-is.svg
|
---|
| 52 | [6]: https://david-dm.org/es-shims/object-is
|
---|
| 53 | [7]: https://david-dm.org/es-shims/object-is/dev-status.svg
|
---|
| 54 | [8]: https://david-dm.org/es-shims/object-is#info=devDependencies
|
---|
| 55 | [11]: https://nodei.co/npm/object-is.png?downloads=true&stars=true
|
---|
| 56 | [license-image]: http://img.shields.io/npm/l/object-is.svg
|
---|
| 57 | [license-url]: LICENSE
|
---|
| 58 | [downloads-image]: http://img.shields.io/npm/dm/object-is.svg
|
---|
| 59 | [downloads-url]: http://npm-stat.com/charts.html?package=object-is
|
---|
| 60 |
|
---|