You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB

4 years ago
  1. #object-is <sup>[![Version Badge][2]][1]</sup>
  2. [![Build Status][3]][4] [![dependency status][5]][6] [![dev dependency status][7]][8]
  3. [![npm badge][11]][1]
  4. [![browser support][9]][10]
  5. ES6-compliant shim for Object.is - differentiates between -0 and +0, and can compare to NaN.
  6. Essentially, Object.is returns the same value as === - but true for NaN, and false for -0 and +0.
  7. ## Example
  8. ```js
  9. Object.is = require('object-is');
  10. var assert = require('assert');
  11. assert.ok(Object.is());
  12. assert.ok(Object.is(undefined));
  13. assert.ok(Object.is(undefined, undefined));
  14. assert.ok(Object.is(null, null));
  15. assert.ok(Object.is(true, true));
  16. assert.ok(Object.is(false, false));
  17. assert.ok(Object.is('foo', 'foo'));
  18. var arr = [1, 2];
  19. assert.ok(Object.is(arr, arr));
  20. assert.notOk(Object.is(arr, [1, 2]));
  21. assert.ok(Object.is(0, 0));
  22. assert.ok(Object.is(-0, -0));
  23. assert.notOk(Object.is(0, -0));
  24. assert.ok(Object.is(NaN, NaN));
  25. assert.ok(Object.is(Infinity, Infinity));
  26. assert.ok(Object.is(-Infinity, -Infinity));
  27. ```
  28. ## Tests
  29. Simply clone the repo, `npm install`, and run `npm test`
  30. [1]: https://npmjs.org/package/object-is
  31. [2]: http://vb.teelaun.ch/ljharb/object-is.svg
  32. [3]: https://travis-ci.org/ljharb/object-is.svg
  33. [4]: https://travis-ci.org/ljharb/object-is
  34. [5]: https://david-dm.org/ljharb/object-is.svg
  35. [6]: https://david-dm.org/ljharb/object-is
  36. [7]: https://david-dm.org/ljharb/object-is/dev-status.svg
  37. [8]: https://david-dm.org/ljharb/object-is#info=devDependencies
  38. [9]: https://ci.testling.com/ljharb/object-is.png
  39. [10]: https://ci.testling.com/ljharb/object-is
  40. [11]: https://nodei.co/npm/object-is.png?downloads=true&stars=true