• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..18-Dec-2021-

.github/H18-Dec-2021-1311

.nycrcH A D18-Dec-2021216 1413

LICENSEH A D18-Dec-20211 KiB2217

README.mdH A D18-Dec-20211.5 KiB4232

package.jsonH A D18-Dec-20211.7 KiB6564

README.md

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