unbox-primitive
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
call-bind | 1.0.7 | 21.6 kB | MIT | prod | |
has-bigints | 1.0.2 | 4.93 kB | MIT | prod | |
has-symbols | 1.0.3 | 6.9 kB | MIT | prod | |
which-boxed-primitive | 1.0.2 | 5.54 kB | MIT | prod |
Unbox-primitive is a JavaScript utility module that helps in unboxing a boxed JS primitive value. It proves to be beneficial as it can work cross-realms/iframe. The module doesn't depend on instanceof
or any mutable properties and can operate effectively despite ES6 Symbol.toStringTag.
To use the unbox-primitive package, you first need to install it via npm. You can do so using the command npm install unbox-primitive
. Once it is installed, you can require it in your JavaScript file and use its functionality. Here is an example of how you can use this package:
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
In the above code snippet, the unboxPrimitive function is used to convert boxed JS primitive values to actual primitive values.
The documentation for the unbox-primitive package can be found on the package's page on npm (unbox-primitive npm page) and on the GitHub page for the module (unbox-primitive GitHub page). The README in the GitHub repository includes a thorough description of the utility along with examples of its usage. For comprehensive understanding, users are encouraged to refer to these resources.