包详细信息

which-typed-array

inspect-js187.6mMIT1.1.19

Which kind of Typed Array is this JavaScript value? Works cross-realm, without instanceof, and despite Symbol.toStringTag.

array, TypedArray, typed array, which

自述文件

which-typed-array Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

Which kind of Typed Array is this JavaScript value? Works cross-realm, without instanceof, and despite Symbol.toStringTag.

Example

var whichTypedArray = require('which-typed-array');
var assert = require('assert');

assert.equal(false, whichTypedArray(undefined));
assert.equal(false, whichTypedArray(null));
assert.equal(false, whichTypedArray(false));
assert.equal(false, whichTypedArray(true));
assert.equal(false, whichTypedArray([]));
assert.equal(false, whichTypedArray({}));
assert.equal(false, whichTypedArray(/a/g));
assert.equal(false, whichTypedArray(new RegExp('a', 'g')));
assert.equal(false, whichTypedArray(new Date()));
assert.equal(false, whichTypedArray(42));
assert.equal(false, whichTypedArray(NaN));
assert.equal(false, whichTypedArray(Infinity));
assert.equal(false, whichTypedArray(new Number(42)));
assert.equal(false, whichTypedArray('foo'));
assert.equal(false, whichTypedArray(Object('foo')));
assert.equal(false, whichTypedArray(function () {}));
assert.equal(false, whichTypedArray(function* () {}));
assert.equal(false, whichTypedArray(x => x * x));
assert.equal(false, whichTypedArray([]));

assert.equal('Int8Array', whichTypedArray(new Int8Array()));
assert.equal('Uint8Array', whichTypedArray(new Uint8Array()));
assert.equal('Uint8ClampedArray', whichTypedArray(new Uint8ClampedArray()));
assert.equal('Int16Array', whichTypedArray(new Int16Array()));
assert.equal('Uint16Array', whichTypedArray(new Uint16Array()));
assert.equal('Int32Array', whichTypedArray(new Int32Array()));
assert.equal('Uint32Array', whichTypedArray(new Uint32Array()));
assert.equal('Float32Array', whichTypedArray(new Float32Array()));
assert.equal('Float64Array', whichTypedArray(new Float64Array()));
assert.equal('BigInt64Array', whichTypedArray(new BigInt64Array()));
assert.equal('BigUint64Array', whichTypedArray(new BigUint64Array()));

Tests

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

更新日志

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.19 - 2025-03-08

Commits

  • [Refactor] use get-proto, improve types e05d535
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/tsconfig, @types/tape 0dade9c
  • [Deps] update call-bound, for-each 490791a
  • [Tests] skip npm ls in older nodes f83aaca
  • [Dev Deps] update @ljharb/tsconfig 63c4795

v1.1.18 - 2024-12-18

Commits

v1.1.17 - 2024-12-18

Commits

  • [types] improve types 86bc612
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/tsconfig, @types/tape 2e9bed6
  • [Deps] update call-bind, gopd 34579df
  • [Refactor] use call-bound directly 2a2d84e

v1.1.16 - 2024-11-27

Commits

  • [actions] split out node 10-20, and 20+ 8e289a9
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/eslint-config, @types/node, @types/tape, auto-changelog, tape 3d4a678
  • [Tests] replace aud with npm audit 6fbada9
  • [types] add an additional overload db5a791
  • [Dev Deps] remove an unused DT package 6bfff4c
  • [Dev Deps] add missing peer dep 05fd582

v1.1.15 - 2024-03-10

Commits

  • [types] use a namespace; improve type f42bec3
  • [types] use shared config 464a9e3
  • [actions] remove redundant finisher; use reusable workflow d114ee8
  • [Dev Deps] update @types/node, tape, typescript; add @arethetypeswrong/cli 9cc63d8
  • [types] add a helpful hover description 29ccf8d
  • [Deps] update available-typed-arrays, call-bind, has-tostringtag 7ecfd8e

v1.1.14 - 2024-02-01

Commits

  • [patch] add types 49c4d4c
  • [Dev Deps] update aud, npmignore, tape e5fab7b
  • [Deps] update available-typed-arrays, call-bind 97e2b44
  • [Deps] update has-tostringtag 1efa8bf

v1.1.13 - 2023-10-19

Commits

  • [Refactor] avoid call-binding entirely when there is no method to bind 9ff452b

v1.1.12 - 2023-10-19

Commits

  • [Fix] somehow node 0.12 - 3 can hit here, and they lack slice but have set c28e9b8
  • [Deps] update call-bind a648554
  • [Dev Deps] update tape 7a094d6

v1.1.11 - 2023-07-17

Commits

  • [Fix] node < v0.6 lacks proper Object toString behavior b8fd654
  • [Dev Deps] update tape e1734c9

v1.1.10 - 2023-07-10

Commits

  • [actions] update rebase action to use reusable workflow 2c10582
  • [Robustness] use call-bind b2335fd
  • [Dev Deps] update @ljharb/eslint-config, aud, tape ad5e41b

v1.1.9 - 2022-11-02

Commits

  • [Dev Deps] update aud, is-callable, tape 9a20b3c
  • [Refactor] use gopd instead of es-abstract helper 00157af
  • [Deps] update is-typed-array 6714240
  • [meta] add sideEffects flag 89b96cc

v1.1.8 - 2022-05-14

Commits

  • [actions] reuse common workflows 95ea6c0
  • [meta] use npmignore to autogenerate an npmignore file d08436a
  • [readme] add github actions/codecov badges 35ae3af
  • [Dev Deps] update eslint, @ljharb/eslint-config, safe-publish-latest, tape 86e6e3a
  • [actions] update codecov uploader 0aa6e30
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, tape a881a78
  • [Refactor] use for-each instead of foreach 9dafa03
  • [Deps] update es-abstract, is-typed-array 0684022
  • [Deps] update es-abstract, is-typed-array 633a529

v1.1.7 - 2021-08-30

Commits

  • [Refactor] use globalThis if available 2a16d1f
  • [meta] changelog cleanup ba99f56
  • [Dev Deps] update @ljharb/eslint-config 19a6e04
  • [Deps] update available-typed-arrays 50dbc58
  • [Deps] update is-typed-array c1b83ea

v1.1.6 - 2021-08-06

Fixed

  • [Fix] if Symbol.toStringTag exists but is not present, use Object.prototype.toString #51 #49

Commits

  • [Dev Deps] update is-callable, tape 63eb1e3
  • [Deps] update is-typed-array c5056f0

v1.1.5 - 2021-08-05

Commits

  • [actions] use node/install instead of node/run; use codecov action 63fa8dd
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, is-callable, tape 1107c74
  • [Deps] update available-typed-arrays, call-bind, es-abstract, is-typed-array f953454
  • [Fix] use has-tostringtag to behave correctly in the presence of symbol shams 8aee720
  • [meta] use prepublishOnly script for npm 7+ 6c5167b

v1.1.4 - 2020-12-05

Commits

  • [meta] npmignore github action workflows aa427e7

v1.1.3 - 2020-12-05

Commits

  • [Tests] migrate tests to Github Actions 803d4dd
  • [Tests] run nyc on all tests 205a13f
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, is-callable, tape 97ceb07
  • [actions] add "Allow Edits" workflow b140492
  • [Deps] update es-abstract; use call-bind where applicable 2abdb87
  • [actions] switch Automatic Rebase workflow to pull_request_target event 256d34b
  • [Dev Deps] update auto-changelog; add aud ddea96f
  • [meta] gitignore nyc output 8a812bd

v1.1.2 - 2020-04-07

Commits

  • [Dev Deps] update make-arrow-function, make-generator-function 28c61ef
  • [Dev Deps] update @ljharb/eslint-config a233879
  • [Dev Deps] update auto-changelog df0134c
  • [Fix] move foreach to dependencies 6ef29c0
  • [Tests] only audit prod deps eb21044
  • [Deps] update es-abstract 5ef0236
  • [Dev Deps] update tape 7456037
  • [Deps] update available-typed-arrays 8a856c9

v1.1.1 - 2020-01-24

Commits

  • [Tests] use shared travis-ci configs 0a627d9
  • [meta] add auto-changelog 2a14c58
  • [meta] remove unused Makefile and associated utilities 75f7f22
  • [Tests] up to node v12.10, v11.15, v10.16, v8.16, v6.17 4162327
  • [Refactor] use es-abstract’s callBound, available-typed-arrays, has-symbols 9b04a2a
  • [readme] fix repo URLs, remove testling 03ed52f
  • [Dev Deps] update eslint, @ljharb/eslint-config, replace, semver, tape bfbcf3e
  • [actions] add automatic rebasing / merge commit blocking cc88ac5
  • [meta] create FUNDING.yml acbc723
  • [Dev Deps] update eslint, @ljharb/eslint-config, is-callable, tape f1ab63e
  • [Dev Deps] update eslint, @ljharb/eslint-config; add safe-publish-latest ac9f50b
  • [Tests] use npx aud instead of nsp or npm audit with hoops aaaa15d
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape 602fc9a
  • [Deps] update available-typed-arrays, is-typed-array b2d69b6
  • [meta] add funding field 156f613

v1.1.0 - 2019-02-16

Commits

  • [Tests] remove jscs 381c9b4
  • [Tests] up to node v8.2, v7.10, v6.11, v5.8; improve matrix; newer npm breaks on older node 7015c19
  • [Tests] up to node v10.0, v9.11, v8.11, v6.14, v4.9; use nvm install-latest-npm ad67885
  • [Tests] up to node v11.6, v10.15, v8.15, v6.16 dd94bfb
  • [Refactor] use an array instead of an object for storing Typed Array names de98bc1
  • [meta] ignore test.html 06cfb1b
  • [Tests] up to node v7.0, v6.9, v4.6; improve test matrix df76eaa
  • [New] add BigInt64Array and BigUint64Array d6bca3a
  • [Dev Deps] update jscs, nsp, eslint f23b45b
  • [Dev Deps] update @ljharb/eslint-config, eslint, semver, tape ddb4484
  • [Dev Deps] update eslint, @ljharb/eslint-config, covert, is-callable, replace, semver, tape 4524e59
  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config, semver 1ec7056
  • [Dev Deps] update jscs, nsp, eslint, @ljharb/eslint-config 799487d
  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config, semver 8092598
  • [Tests] up to node v11.10 a5aabb1
  • [Dev Deps] update @ljharb/eslint-config, eslint, nsp, semver, tape 277be33
  • [Tests] use npm audit instead of nsp ee97dc7
  • [Dev Deps] update tape, eslint, @ljharb/eslint-config 262ffb0
  • [Dev Deps] update jscs, eslint, @ljharb/eslint-config d6bbcfc
  • [Tests] up to node v6.2 2ff89eb
  • Only apps should have lockfiles e2bc271
  • [Dev Deps] update nsp, eslint, @ljharb/eslint-config b79e93b
  • [Dev Deps] update nsp, eslint, @ljharb/eslint-config 016dbff
  • [Dev Deps] update eslint, tape 6ce4bbc
  • [Tests] on node v10.1 f0683a0
  • [Tests] up to node v7.2 2f29cef
  • [Dev Deps] update replace 73b5ba6
  • [Deps] update function-bind c8a18c2
  • [Tests] on node v5.12 812102b
  • [Tests] on node v5.10 271584f

v1.0.1 - 2016-03-19

Commits

  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config, semver, is-callable 4a628c5
  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config, is-callable 8e09372
  • [Tests] up to node v5.6, v4.3 3a35bf9
  • [Dev Deps] update jscs, eslint, @ljharb/eslint-config 9410d5e
  • [Fix] Symbol.toStringTag is on the super-[[Prototype]] of Float32Array, not the [[Prototype]]. 7c40a3a
  • [Tests] up to node v5.9, v4.4 07878e7
  • Use the object form of "author" in package.json 65caa56
  • [Tests] use pretest/posttest for linting/security c170f7e
  • [Deps] update is-typed-array 9ab324e
  • [Deps] update function-bind a723142
  • [Deps] update is-typed-array ed82ce4
  • [Tests] on node v4.2 f581c20

v1.0.0 - 2015-10-05

Commits