securityos/node_modules/which-builtin-type
Berkeley 927854894b First commit 2024-09-06 12:32:35 -03:00
..
test First commit 2024-09-06 12:32:35 -03:00
.eslintrc First commit 2024-09-06 12:32:35 -03:00
.nycrc First commit 2024-09-06 12:32:35 -03:00
CHANGELOG.md First commit 2024-09-06 12:32:35 -03:00
LICENSE First commit 2024-09-06 12:32:35 -03:00
README.md First commit 2024-09-06 12:32:35 -03:00
index.js First commit 2024-09-06 12:32:35 -03:00
package.json First commit 2024-09-06 12:32:35 -03:00

README.md

which-builtin-type Version Badge

github actions coverage dependency status dev dependency status 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