unbox-primitive <sup>Version Badge</sup>

github actions coverage dependency status dev dependency status License Downloads

npm badge

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.

Example

var unboxPrimitive = require('unbox-primitive');
var assert = require('assert');

assert.equal(unboxPrimitive(new Boolean(false)), false);
assert.equal(unboxPrimitive(new String('f')), 'f');
assert.equal(unboxPrimitive(new Number(42)), 42);
const s = Symbol();
assert.equal(unboxPrimitive(Object(s)), s);
assert.equal(unboxPrimitive(new BigInt(42)), 42n);

// any primitive, or non-boxed-primitive object, will throw

Tests

Simply clone the repo, npm install, and run npm test

unbox-primitive - Installation

To install unbox-primitive via this registry, you'll need to install via the --registry parameter with your package manager.

n

NPM

npm install unbox-primitive --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Yarn

yarn config set registry https://js.registry.sudovanilla.org
yarn install unbox-primitive

Learn more about the config option.

PNPM

pnpm install unbox-primitive --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Bun Logo

Bun

bun install unbox-primitive --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Learn more about setting this up in your bunfig.toml configuration.


For Deno, add the following to your .npmrc file in your directory:

registry="https://js.registry.sudovanilla.org"

Then run the deno install command.

unbox-primitive - Download

Download Tarball (v1.1.0)

Integrity sha512-nWJ91DjeOkej/TA8pXQ3myruKpKEYgqvpw9lz4OPHj/NWFNluYrjbz9j01CJ8yKQd2g4jFoOkINCTW2I5LEEyw==
SHASUM 8d9d2c9edeea8460c7f35033a88867944934d1e2
Tarball https://js.registry.sudovanilla.org/unbox-primitive/-/unbox-primitive-1.1.0.tgz