which-boxed-primitive
Advanced tools
Weekly downloads
Changelog
v1.0.2 - 2020-12-14
8674582
dff6643
b26112a
auto-changelog
config consistent 8d10175
ab8db24
nyc
on all tests; use tape
runner 7d084df
eslint
, @ljharb/eslint-config
, aud
, auto-changelog
, object-inspect
, tape
576f6f3
97efa53
fb1b4f7
eslint
, @ljharb/eslint-config
, has-symbols
, object-inspect
, safe-publish-latest
1e03c61
is-boolean-object
, is-number-object
, is-string
, is-symbol
13673df
auto-changelog
, in-publish
, tape
65a0e15
eslint
, @ljharb/eslint-config
, tape
f8a0afe
is-bigint
, is-boolean-object
e7a1ce2
pull_request_target
event e46f193
@ljharb/eslint-config
, tape
df3da14
auto-changelog
; add aud
e2e8a12
funding
field 7df404b
auto-changelog
0d6b76d
246151c
c2d1685
25fb2b5
Readme
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.
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);
Simply clone the repo, npm install
, and run npm test
FAQs
Which kind of boxed JS primitive is this?
The npm package which-boxed-primitive receives a total of 19,787,856 weekly downloads. As such, which-boxed-primitive popularity was classified as popular.
We found that which-boxed-primitive demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.