Détail du package

which-builtin-type

inspect-js112.7mMIT1.2.1

What is the type of this builtin JS value?

type, builtin, ecmascript

readme

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

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.2.1 - 2024-12-12

Commits

  • [meta] sort package.json 8305bf9
  • [actions] re-add finishers 67140db
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/tsconfig, @types/function.prototype.name, @types/tape, has-symbols 5adff02
  • [Deps] update call-bind, is-date-object, is-regex, which-boxed-primitive 87922d3
  • [Refactor] use call-bound directly 8f633bc
  • [Deps] update is-regex, which-typed-array a912742

v1.2.0 - 2024-11-23

Commits

  • [New] add types d4aa2db
  • [actions] split out node 10-20, and 20+ 7b3d28b
  • [Refactor] use callBound to cache Promise#then a000377
  • [Dev Deps] update auto-changelog, object-inspect, tape 37062d2
  • [Tests] replace aud with npm audit 337aac1
  • [Deps] update is-finalizationregistry 4ef8763
  • [Dev Deps] add missing peer dep 1cb2842

v1.1.4 - 2024-07-29

Commits

  • [readme] fix URLs f26fc22
  • [Dev Deps] update @ljharb/eslint-config, aud, available-typed-arrays, npmignore, object-inspect, object.assign, tape f724135
  • [Deps] update function.prototype.name, has-tostringtag, which-collection, which-typed-array 831119b

v1.1.3 - 2022-11-02

Commits

  • [meta] use npmignore to autogenerate an npmignore file 0ccf168
  • [Dev Deps] update aud, has-bigints, has-symbols, in-publish, object-inspect, object.assign, tape 2c87b2e
  • [actions] update rebase action to use reusable workflow ab27caf
  • [meta] simplify exports 680d056
  • [Deps] update which-typed-array 3ca0216
  • [meta] add sideEffects flag caa2221

v1.1.2 - 2022-04-12

Commits

  • [actions] reuse common workflows b1b60aa
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, safe-publish-latest, tape 8115a20
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, object-inspect, tape 86b3c3b
  • [actions] update codecov uploader de30f4b
  • [Deps] update function.prototype.name, is-finalizationregistry, which-typed-array 0ba20f5
  • [Refactor] use is-async-function 6f36d89
  • [Deps] update is-weakref d775476

v1.1.1 - 2021-08-06

Commits

  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, available-typed-arrays, object-inspect, tape 8adae7d
  • [Deps] update is-date-object, is-generator-function, is-regex, which-typed-array 805b158
  • [Refactor] use has-tostringtag to behave correctly in the presence of symbol shams 9ec250a
  • [readme] add github actions/codecov badges 75b51b4

v1.1.0 - 2021-04-18

Commits

  • [Fix] prevent constructor or Symbol.toStringTag from lying about builtins 7638412
  • [actions] use node/install instead of node/run; use codecov action 6a06770
  • [New] recognize Promise 0d79e3a
  • [New] recognize WeakRef and FinalizationRegistry 020de6a
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, has-symbols, object-inspect, tape 71e47f5
  • [Deps] update function.prototype.name, is-regex f2d56b9
  • [meta] use prepublishOnly script for npm 7+ daae0a0
  • [Tests] increase coverage bd406f2

v1.0.1 - 2020-12-14

Commits

  • [Tests] migrate tests to Github Actions 165a1b5
  • [meta] do not publish github action workflow files 851f508
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, has-bigints, object-inspect, object.assign, tape 5b0906c
  • [Tests] run nyc on all tests; use tape runner 85924cd
  • [readme] fix repo URLs, remove defunct badges 8fb4bb5
  • [Dev Deps] update @ljharb/eslint-config, available-typed-arrays, make-arrow-function, make-generator-function 9d65291
  • [Deps] update function.prototype.name, is-generator-function, is-regex, which-boxed-primitive, which-collection, which-typed-array 7900c10
  • [actions] add "Allow Edits" workflow f9f04f5
  • [actions] switch Automatic Rebase workflow to pull_request_target event 4452dee

v1.0.0 - 2020-01-24

Commits