Big update!Announcing Socket for GitHub 1.0. Learn more
Socket
BlogLoveFAQ
Install
Log in

which-boxed-primitive

Package Overview
Dependencies
5
Maintainers
1
Versions
3
Issues
File Explorer

Advanced tools

which-boxed-primitive

Which kind of boxed JS primitive is this?

    1.0.2latest

Version published
Maintainers
1
Weekly downloads
21,810,476
increased by1.02%

Weekly downloads

Changelog

Source

v1.0.2 - 2020-12-14

Commits

Readme

Source

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

Keywords

FAQs

What is which-boxed-primitive?

Which kind of boxed JS primitive is this?

Is which-boxed-primitive popular?

The npm package which-boxed-primitive receives a total of 17,841,093 weekly downloads. As such, which-boxed-primitive popularity was classified as popular.

Is which-boxed-primitive well maintained?

We found that which-boxed-primitive demonstrated a not healthy version release cadence and project activity. It has 1 open source maintainer collaborating on the project.

Last updated on 14 Dec 2020
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc