056bc3af060ae80c0f08c3c387c1a385f49fd80bd1bec8fffb010a2838e3e826c7e9ffd3f8fac71b45db0f33adda32329a7b281cd7497473f4d4f9c098deea 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # unbox-primitive <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![github actions][actions-image]][actions-url]
  3. [![coverage][codecov-image]][codecov-url]
  4. [![dependency status][deps-svg]][deps-url]
  5. [![dev dependency status][dev-deps-svg]][dev-deps-url]
  6. [![License][license-image]][license-url]
  7. [![Downloads][downloads-image]][downloads-url]
  8. [![npm badge][npm-badge-png]][package-url]
  9. Unbox a boxed JS primitive value. This module works cross-realm/iframe, does not depend on `instanceof` or mutable properties, and works despite ES6 Symbol.toStringTag.
  10. ## Example
  11. ```js
  12. var unboxPrimitive = require('unbox-primitive');
  13. var assert = require('assert');
  14. assert.equal(unboxPrimitive(new Boolean(false)), false);
  15. assert.equal(unboxPrimitive(new String('f')), 'f');
  16. assert.equal(unboxPrimitive(new Number(42)), 42);
  17. const s = Symbol();
  18. assert.equal(unboxPrimitive(Object(s)), s);
  19. assert.equal(unboxPrimitive(new BigInt(42)), 42n);
  20. // any primitive, or non-boxed-primitive object, will throw
  21. ```
  22. ## Tests
  23. Simply clone the repo, `npm install`, and run `npm test`
  24. [package-url]: https://npmjs.org/package/unbox-primitive
  25. [npm-version-svg]: https://versionbadg.es/ljharb/unbox-primitive.svg
  26. [deps-svg]: https://david-dm.org/ljharb/unbox-primitive.svg
  27. [deps-url]: https://david-dm.org/ljharb/unbox-primitive
  28. [dev-deps-svg]: https://david-dm.org/ljharb/unbox-primitive/dev-status.svg
  29. [dev-deps-url]: https://david-dm.org/ljharb/unbox-primitive#info=devDependencies
  30. [npm-badge-png]: https://nodei.co/npm/unbox-primitive.png?downloads=true&stars=true
  31. [license-image]: https://img.shields.io/npm/l/unbox-primitive.svg
  32. [license-url]: LICENSE
  33. [downloads-image]: https://img.shields.io/npm/dm/unbox-primitive.svg
  34. [downloads-url]: https://npm-stat.com/charts.html?package=unbox-primitive
  35. [codecov-image]: https://codecov.io/gh/ljharb/unbox-primitive/branch/main/graphs/badge.svg
  36. [codecov-url]: https://app.codecov.io/gh/ljharb/unbox-primitive/
  37. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/unbox-primitive
  38. [actions-url]: https://github.com/ljharb/unbox-primitive/actions