Détail du package

which-boxed-primitive

inspect-js148.6mMIT1.1.1

Which kind of boxed JS primitive is this?

boxed, primitive, object, ecmascript

readme

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.1.1 - 2024-12-15

Commits

  • [Deps] update is-boolean-object, is-number-object, is-string, is-symbol 5266e0c
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/tsconfig, @types/tape a660339

v1.1.0 - 2024-12-02

Commits

  • [actions] reuse common workflows 893df44
  • [meta] use npmignore to autogenerate an npmignore file bab1ff8
  • [Tests] use es-value-fixtures and for-each ecacfa0
  • [New] add types ab38e78
  • [actions] split out node 10-20, and 20+ 7ee9c3c
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, object-inspect, safe-publish-latest, tape 142215a
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, has-symbols, object-inspect, tape 3559371
  • [actions] update rebase action to use reusable workflow 928901a
  • [Deps] update is-bigint, is-boolean-object, is-number-object, is-string, is-symbol f7b14be
  • [Dev Deps] update @ljharb/eslint-config, auto-changelog, npmignore, object-inspect, tape 5296738
  • [Deps] update is-bigint, is-boolean-object, is-number-object, is-string, is-symbol caa6d1c
  • [meta] add missing engines.node ca40880
  • [Tests] replace aud with npm audit b0f4069
  • [Dev Deps] update aud 8d0e336
  • [Deps] update is-number-object eafcabf
  • [Dev Deps] add missing peer dep ec4dd52

v1.0.2 - 2020-12-14

Commits

  • [Tests] use shared travis-ci configs 8674582
  • [Tests] migrate tests to Github Actions dff6643
  • [meta] do not publish github action workflow files b26112a
  • [meta] make auto-changelog config consistent 8d10175
  • [readme] fix repo URLs, remove defunct badges ab8db24
  • [Tests] run nyc on all tests; use tape runner 7d084df
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, object-inspect, tape 576f6f3
  • [actions] add automatic rebasing / merge commit blocking 97efa53
  • [actions] add "Allow Edits" workflow fb1b4f7
  • [Dev Deps] update eslint, @ljharb/eslint-config, has-symbols, object-inspect, safe-publish-latest 1e03c61
  • [Deps] update is-boolean-object, is-number-object, is-string, is-symbol 13673df
  • [Dev Deps] update auto-changelog, in-publish, tape 65a0e15
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape f8a0afe
  • [Deps] update is-bigint, is-boolean-object e7a1ce2
  • [actions] switch Automatic Rebase workflow to pull_request_target event e46f193
  • [Dev Deps] update @ljharb/eslint-config, tape df3da14
  • [Dev Deps] update auto-changelog; add aud e2e8a12
  • [meta] add funding field 7df404b
  • [Dev Deps] update auto-changelog 0d6b76d
  • [Tests] only audit prod deps 246151c
  • [meta] fix changelog c2d1685
  • [readme] Fix spelling error 25fb2b5

v1.0.1 - 2019-08-10

Commits

  • [meta] avoid running safe-publish-latest when not publishing df44b27

v1.0.0 - 2019-08-10

Commits