which-boxed-primitive

WebJar for which-boxed-primitive

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

which-boxed-primitive
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

which-boxed-primitive
WebJar for which-boxed-primitive
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/inspect-js/which-boxed-primitive

Download which-boxed-primitive

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/which-boxed-primitive/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>which-boxed-primitive</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/which-boxed-primitive/
implementation 'org.webjars.npm:which-boxed-primitive:1.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/which-boxed-primitive/
implementation ("org.webjars.npm:which-boxed-primitive:1.0.2")
'org.webjars.npm:which-boxed-primitive:jar:1.0.2'
<dependency org="org.webjars.npm" name="which-boxed-primitive" rev="1.0.2">
  <artifact name="which-boxed-primitive" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='which-boxed-primitive', version='1.0.2')
)
libraryDependencies += "org.webjars.npm" % "which-boxed-primitive" % "1.0.2"
[org.webjars.npm/which-boxed-primitive "1.0.2"]

Dependencies

compile (5)

Group / Artifact Type Version
org.webjars.npm : is-bigint jar [1.0.1,2)
org.webjars.npm : is-string jar [1.0.5,2)
org.webjars.npm : is-boolean-object jar [1.1.0,2)
org.webjars.npm : is-number-object jar [1.0.4,2)
org.webjars.npm : is-symbol jar [1.0.3,2)

Project Modules

There are no modules declared in this project.

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

org.webjars.npm

Inspect JS

JavaScript value inspection tools.

Versions

Version
1.0.2
1.0.1