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