1 | # which-typed-array <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
---|
2 |
|
---|
3 | [![github actions][actions-image]][actions-url]
|
---|
4 | [![coverage][codecov-image]][codecov-url]
|
---|
5 | [![dependency status][deps-svg]][deps-url]
|
---|
6 | [![dev dependency status][dev-deps-svg]][dev-deps-url]
|
---|
7 | [![License][license-image]][license-url]
|
---|
8 | [![Downloads][downloads-image]][downloads-url]
|
---|
9 |
|
---|
10 | [![npm badge][npm-badge-png]][package-url]
|
---|
11 |
|
---|
12 | Which kind of Typed Array is this JavaScript value? Works cross-realm, without `instanceof`, and despite Symbol.toStringTag.
|
---|
13 |
|
---|
14 | ## Example
|
---|
15 |
|
---|
16 | ```js
|
---|
17 | var whichTypedArray = require('which-typed-array');
|
---|
18 | var assert = require('assert');
|
---|
19 |
|
---|
20 | assert.equal(false, whichTypedArray(undefined));
|
---|
21 | assert.equal(false, whichTypedArray(null));
|
---|
22 | assert.equal(false, whichTypedArray(false));
|
---|
23 | assert.equal(false, whichTypedArray(true));
|
---|
24 | assert.equal(false, whichTypedArray([]));
|
---|
25 | assert.equal(false, whichTypedArray({}));
|
---|
26 | assert.equal(false, whichTypedArray(/a/g));
|
---|
27 | assert.equal(false, whichTypedArray(new RegExp('a', 'g')));
|
---|
28 | assert.equal(false, whichTypedArray(new Date()));
|
---|
29 | assert.equal(false, whichTypedArray(42));
|
---|
30 | assert.equal(false, whichTypedArray(NaN));
|
---|
31 | assert.equal(false, whichTypedArray(Infinity));
|
---|
32 | assert.equal(false, whichTypedArray(new Number(42)));
|
---|
33 | assert.equal(false, whichTypedArray('foo'));
|
---|
34 | assert.equal(false, whichTypedArray(Object('foo')));
|
---|
35 | assert.equal(false, whichTypedArray(function () {}));
|
---|
36 | assert.equal(false, whichTypedArray(function* () {}));
|
---|
37 | assert.equal(false, whichTypedArray(x => x * x));
|
---|
38 | assert.equal(false, whichTypedArray([]));
|
---|
39 |
|
---|
40 | assert.equal('Int8Array', whichTypedArray(new Int8Array()));
|
---|
41 | assert.equal('Uint8Array', whichTypedArray(new Uint8Array()));
|
---|
42 | assert.equal('Uint8ClampedArray', whichTypedArray(new Uint8ClampedArray()));
|
---|
43 | assert.equal('Int16Array', whichTypedArray(new Int16Array()));
|
---|
44 | assert.equal('Uint16Array', whichTypedArray(new Uint16Array()));
|
---|
45 | assert.equal('Int32Array', whichTypedArray(new Int32Array()));
|
---|
46 | assert.equal('Uint32Array', whichTypedArray(new Uint32Array()));
|
---|
47 | assert.equal('Float32Array', whichTypedArray(new Float32Array()));
|
---|
48 | assert.equal('Float64Array', whichTypedArray(new Float64Array()));
|
---|
49 | assert.equal('BigInt64Array', whichTypedArray(new BigInt64Array()));
|
---|
50 | assert.equal('BigUint64Array', whichTypedArray(new BigUint64Array()));
|
---|
51 | ```
|
---|
52 |
|
---|
53 | ## Tests
|
---|
54 | Simply clone the repo, `npm install`, and run `npm test`
|
---|
55 |
|
---|
56 | [package-url]: https://npmjs.org/package/which-typed-array
|
---|
57 | [npm-version-svg]: https://versionbadg.es/inspect-js/which-typed-array.svg
|
---|
58 | [deps-svg]: https://david-dm.org/inspect-js/which-typed-array.svg
|
---|
59 | [deps-url]: https://david-dm.org/inspect-js/which-typed-array
|
---|
60 | [dev-deps-svg]: https://david-dm.org/inspect-js/which-typed-array/dev-status.svg
|
---|
61 | [dev-deps-url]: https://david-dm.org/inspect-js/which-typed-array#info=devDependencies
|
---|
62 | [npm-badge-png]: https://nodei.co/npm/which-typed-array.png?downloads=true&stars=true
|
---|
63 | [license-image]: https://img.shields.io/npm/l/which-typed-array.svg
|
---|
64 | [license-url]: LICENSE
|
---|
65 | [downloads-image]: https://img.shields.io/npm/dm/which-typed-array.svg
|
---|
66 | [downloads-url]: https://npm-stat.com/charts.html?package=which-typed-array
|
---|
67 | [codecov-image]: https://codecov.io/gh/inspect-js/which-typed-array/branch/main/graphs/badge.svg
|
---|
68 | [codecov-url]: https://app.codecov.io/gh/inspect-js/which-typed-array/
|
---|
69 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/which-typed-array
|
---|
70 | [actions-url]: https://github.com/inspect-js/which-typed-array/actions
|
---|