which-boxed-primitive (1.1.1)

Published 2026-02-24 14:08:35 +00:00 by atheaadmin

Installation

registry=
npm install which-boxed-primitive@1.1.1
"which-boxed-primitive": "1.1.1"

About this package

which-boxed-primitive Version Badge

dependency status dev dependency status License Downloads

npm badge

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(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(42n), null);
assert.equal(whichBoxedPrimitive(Object(42n), '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);

Tests

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

Dependencies

Dependencies

ID Version
is-bigint ^1.1.0
is-boolean-object ^1.2.1
is-number-object ^1.1.1
is-string ^1.1.1
is-symbol ^1.1.1

Development Dependencies

ID Version
@arethetypeswrong/cli ^0.17.1
@ljharb/eslint-config ^21.1.1
@ljharb/tsconfig ^0.2.2
@types/for-each ^0.3.3
@types/object-inspect ^1.13.0
@types/tape ^5.7.0
auto-changelog ^2.5.0
encoding ^0.1.13
es-value-fixtures ^1.5.0
eslint =8.8.0
for-each ^0.3.3
in-publish ^2.0.1
npmignore ^0.3.1
nyc ^10.3.2
object-inspect ^1.13.3
safe-publish-latest ^2.0.0
tape ^5.9.0
typescript next

Keywords

boxed primitive object ecmascript javascript which
Details
npm
2026-02-24 14:08:35 +00:00
0
Jordan Harband
MIT
latest
6.6 KiB
Assets (1)
Versions (1) View all
1.1.1 2026-02-24