which-builtin-type
What is the type of this builtin JS value?
Last updated 4 months ago by ljharb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install which-builtin-type 
SYNC missed versions from official npm registry.

which-builtin-type Version Badge

github actions coverage License Downloads

npm badge

What is the type of this builtin JavaScript value? Works cross-realm, without instanceof, and can not be fooled by a constructor property.

Example

var whichBuiltinType = require('which-builtin-type');
var assert = require('assert');

assert.equal(undefined, whichBuiltinType(undefined));
assert.equal(null, whichBuiltinType(null));
assert.equal('Boolean', whichBuiltinType(false));
assert.equal('Boolean', whichBuiltinType(true));
assert.equal('Array', whichBuiltinType([]));
assert.equal('Object', whichBuiltinType({}));
assert.equal('RegExp', whichBuiltinType(/a/g));
assert.equal('RegExp', whichBuiltinType(new RegExp('a', 'g')));
assert.equal('Date', whichBuiltinType(new Date()));
assert.equal('Number', whichBuiltinType(42));
assert.equal('Number', whichBuiltinType(NaN));
assert.equal('Number', whichBuiltinType(Infinity));
assert.equal('Number', whichBuiltinType(new Number(42)));
assert.equal('String', whichBuiltinType('foo'));
assert.equal('String', whichBuiltinType(Object('foo')));
assert.equal('Function', whichBuiltinType(function () {}));
assert.equal('GeneratorFunction', whichBuiltinType(function* () {}));
assert.equal('Function', whichBuiltinType(x => x * x));
assert.equal('Array', whichBuiltinType([]));
assert.equal('Int8Array', whichBuiltinType(new Int8Array()));
assert.equal('Uint8Array', whichBuiltinType(new Uint8Array()));
assert.equal('Uint8ClampedArray', whichBuiltinType(new Uint8ClampedArray()));
assert.equal('Int16Array', whichBuiltinType(new Int16Array()));
assert.equal('Uint16Array', whichBuiltinType(new Uint16Array()));
assert.equal('Int32Array', whichBuiltinType(new Int32Array()));
assert.equal('Uint32Array', whichBuiltinType(new Uint32Array()));
assert.equal('Float32Array', whichBuiltinType(new Float32Array()));
assert.equal('Float64Array', whichBuiltinType(new Float64Array()));
assert.equal('BigInt64Array', whichBuiltinType(new BigInt64Array()));
assert.equal('BigUint64Array', whichBuiltinType(new BigUint64Array()));

Tests

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

Current Tags

  • 1.1.4                                ...           latest (4 months ago)

7 Versions

  • 1.1.4                                ...           4 months ago
  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dev Dependencies (19)

© 2010 - cnpmjs.org x YWFE | Home | YWFE