Skip to content package
which-boxed-primitive v1.1.0 Which kind of boxed JS primitive is this?
node >= 0.4 5 deps cjs types open source
overview readme
license MIT
deps 5
unpacked 18.3 kB
files 12
node >= 0.4 $ npm install which-boxed-primitive@1.1.0n npmREADME GitHub-flavored package documentation.
downloads Across all versions, last 30 days.
127,200,412 weekly -0.3%
491,588,338 in 30 days
Oct 16 → Nov 14 hover or arrows
compatibility Runtime metadata.
keywords Tagged topics.
boxed primitive object ecmascript javascript which
versions Latest published Dec 16, 2024
maintainers Registry package owners.
contents which-boxed-primitive
Which kind of boxed JS primitive is this? This module works cross-realm/iframe, does not depend on instanceof or mutable properties, and works despite ES6 Symbol.toStringTag.
Example
var whichBoxedPrimitive = require ( 'which-boxed-primitive' );
var assert = require ( 'assert' );
// unboxed primitives return `null`
// boxed primitives return the builtin constructor name
assert. equal ( whichBoxedPrimitive (undefined), null);
assert. equal ( whichBoxedPrimitive (null), null);
assert. equal ( whichBoxedPrimitive ( false ), null);
assert. equal ( whichBoxedPrimitive ( true ), null);
assert. equal ( whichBoxedPrimitive ( new Boolean ( false )), 'Boolean' );
assert. equal (
Tests
Simply clone the repo, npm install, and run npm test
install size Estimated unpacked size across 15 packages.
323.3 kB
Includes dependencies.
dependencies 5 direct dependencies.
whichBoxedPrimitive
(
new
Boolean
(
true
)),
'Boolean'
);
assert. equal ( whichBoxedPrimitive ( 42 ), null);
assert. equal ( whichBoxedPrimitive (NaN), null);
assert. equal ( whichBoxedPrimitive (Infinity), null);
assert. equal ( whichBoxedPrimitive ( new Number ( 42 )), 'Number' );
assert. equal ( whichBoxedPrimitive ( new Number (NaN)), 'Number' );
assert. equal ( whichBoxedPrimitive ( new Number (Infinity)), 'Number' );
assert. equal ( whichBoxedPrimitive ( '' ), null);
assert. equal ( whichBoxedPrimitive ( 'foo' ), null);
assert. equal ( whichBoxedPrimitive ( new String ( '' )), 'String' );
assert. equal ( whichBoxedPrimitive ( new String ( 'foo' )), 'String' );
assert. equal ( whichBoxedPrimitive ( Symbol ()), null);
assert. equal ( whichBoxedPrimitive ( Object ( Symbol ()), 'Symbol' );
assert. equal ( whichBoxedPrimitive ( 42 n ), null);
assert. equal ( whichBoxedPrimitive ( Object ( 42 n ), 'BigInt' );
// non-boxed-primitive objects return `undefined`
assert. equal ( whichBoxedPrimitive ([]), undefined);
assert. equal ( whichBoxedPrimitive ({}), undefined);
assert. equal ( whichBoxedPrimitive ( /a/ g ), undefined);
assert. equal ( whichBoxedPrimitive ( new RegExp ( 'a' , 'g' )), undefined);
assert. equal ( whichBoxedPrimitive ( new Date ()), undefined);
assert. equal ( whichBoxedPrimitive ( function () {}), undefined);
assert. equal ( whichBoxedPrimitive ( function* () {}), undefined);
assert. equal ( whichBoxedPrimitive (x => x * x), undefined);
assert. equal ( whichBoxedPrimitive ([]), undefined);
copy