b713832daa25678cf20e378b30019abee456af34d5649a17d601dbecc094314ad3f2c8c8ac70302fc68b5dbe80d1126081a30087bd6ff12a6cca0d7f3d43be 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # object-is <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![github actions][actions-image]][actions-url]
  3. [![coverage][codecov-image]][codecov-url]
  4. [![License][license-image]][license-url]
  5. [![Downloads][downloads-image]][downloads-url]
  6. [![npm badge][npm-badge-png]][package-url]
  7. ES2015-compliant shim for Object.is - differentiates between -0 and +0, and can compare to NaN.
  8. Essentially, Object.is returns the same value as === - but true for NaN, and false for -0 and +0.
  9. 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).
  10. ## Example
  11. ```js
  12. Object.is = require('object-is');
  13. var assert = require('assert');
  14. assert.ok(Object.is());
  15. assert.ok(Object.is(undefined));
  16. assert.ok(Object.is(undefined, undefined));
  17. assert.ok(Object.is(null, null));
  18. assert.ok(Object.is(true, true));
  19. assert.ok(Object.is(false, false));
  20. assert.ok(Object.is('foo', 'foo'));
  21. var arr = [1, 2];
  22. assert.ok(Object.is(arr, arr));
  23. assert.equal(Object.is(arr, [1, 2]), false);
  24. assert.ok(Object.is(0, 0));
  25. assert.ok(Object.is(-0, -0));
  26. assert.equal(Object.is(0, -0), false);
  27. assert.ok(Object.is(NaN, NaN));
  28. assert.ok(Object.is(Infinity, Infinity));
  29. assert.ok(Object.is(-Infinity, -Infinity));
  30. ```
  31. ## Tests
  32. Simply clone the repo, `npm install`, and run `npm test`
  33. [package-url]: https://npmjs.com/package/object-is
  34. [npm-version-svg]: https://versionbadg.es/es-shims/object-is.svg
  35. [deps-svg]: https://david-dm.org/es-shims/object-is.svg
  36. [deps-url]: https://david-dm.org/es-shims/object-is
  37. [dev-deps-svg]: https://david-dm.org/es-shims/object-is/dev-status.svg
  38. [dev-deps-url]: https://david-dm.org/es-shims/object-is#info=devDependencies
  39. [npm-badge-png]: https://nodei.co/npm/object-is.png?downloads=true&stars=true
  40. [license-image]: https://img.shields.io/npm/l/object-is.svg
  41. [license-url]: LICENSE
  42. [downloads-image]: https://img.shields.io/npm/dm/object-is.svg
  43. [downloads-url]: https://npm-stat.com/charts.html?package=object-is
  44. [codecov-image]: https://codecov.io/gh/es-shims/object-is/branch/main/graphs/badge.svg
  45. [codecov-url]: https://app.codecov.io/gh/es-shims/object-is/
  46. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/object-is
  47. [actions-url]: https://github.com/es-shims/object-is/actions