1 | # typed-array-length <sup>[![Version Badge][2]][1]</sup>
|
---|
2 |
|
---|
3 | [![dependency status][5]][6]
|
---|
4 | [![dev dependency status][7]][8]
|
---|
5 | [![License][license-image]][license-url]
|
---|
6 | [![Downloads][downloads-image]][downloads-url]
|
---|
7 |
|
---|
8 | [![npm badge][11]][1]
|
---|
9 |
|
---|
10 | Robustly get the length of a Typed Array, or `false` if it is not a Typed Array. Works cross-realm, in every engine, even if the `length` property is overridden.
|
---|
11 |
|
---|
12 | ## Example
|
---|
13 |
|
---|
14 | ```js
|
---|
15 | var typedArrayLength = require('typed-array-length');
|
---|
16 | var assert = require('assert');
|
---|
17 |
|
---|
18 | assert.equal(false, typedArrayLength(undefined));
|
---|
19 | assert.equal(false, typedArrayLength(null));
|
---|
20 | assert.equal(false, typedArrayLength(false));
|
---|
21 | assert.equal(false, typedArrayLength(true));
|
---|
22 | assert.equal(false, typedArrayLength([]));
|
---|
23 | assert.equal(false, typedArrayLength({}));
|
---|
24 | assert.equal(false, typedArrayLength(/a/g));
|
---|
25 | assert.equal(false, typedArrayLength(new RegExp('a', 'g')));
|
---|
26 | assert.equal(false, typedArrayLength(new Date()));
|
---|
27 | assert.equal(false, typedArrayLength(42));
|
---|
28 | assert.equal(false, typedArrayLength(NaN));
|
---|
29 | assert.equal(false, typedArrayLength(Infinity));
|
---|
30 | assert.equal(false, typedArrayLength(new Number(42)));
|
---|
31 | assert.equal(false, typedArrayLength('foo'));
|
---|
32 | assert.equal(false, typedArrayLength(Object('foo')));
|
---|
33 | assert.equal(false, typedArrayLength(function () {}));
|
---|
34 | assert.equal(false, typedArrayLength(function* () {}));
|
---|
35 | assert.equal(false, typedArrayLength(x => x * x));
|
---|
36 | assert.equal(false, typedArrayLength([]));
|
---|
37 |
|
---|
38 | assert.equal(1, typedArrayLength(new Int8Array(1)));
|
---|
39 | assert.equal(2, typedArrayLength(new Uint8Array(2)));
|
---|
40 | assert.equal(3, typedArrayLength(new Uint8ClampedArray(3)));
|
---|
41 | assert.equal(4, typedArrayLength(new Int16Array(4)));
|
---|
42 | assert.equal(5, typedArrayLength(new Uint16Array(5)));
|
---|
43 | assert.equal(6, typedArrayLength(new Int32Array(6)));
|
---|
44 | assert.equal(7, typedArrayLength(new Uint32Array(7)));
|
---|
45 | assert.equal(8, typedArrayLength(new Float32Array(8)));
|
---|
46 | assert.equal(9, typedArrayLength(new Float64Array(9)));
|
---|
47 | assert.equal(10, typedArrayLength(new BigInt64Array(10)));
|
---|
48 | assert.equal(11, typedArrayLength(new BigUint64Array(11)));
|
---|
49 | ```
|
---|
50 |
|
---|
51 | ## Tests
|
---|
52 | Simply clone the repo, `npm install`, and run `npm test`
|
---|
53 |
|
---|
54 | [1]: https://npmjs.org/package/typed-array-length
|
---|
55 | [2]: https://versionbadg.es/inspect-js/typed-array-length.svg
|
---|
56 | [5]: https://david-dm.org/inspect-js/typed-array-length.svg
|
---|
57 | [6]: https://david-dm.org/inspect-js/typed-array-length
|
---|
58 | [7]: https://david-dm.org/inspect-js/typed-array-length/dev-status.svg
|
---|
59 | [8]: https://david-dm.org/inspect-js/typed-array-length#info=devDependencies
|
---|
60 | [11]: https://nodei.co/npm/typed-array-length.png?downloads=true&stars=true
|
---|
61 | [license-image]: http://img.shields.io/npm/l/typed-array-length.svg
|
---|
62 | [license-url]: LICENSE
|
---|
63 | [downloads-image]: http://img.shields.io/npm/dm/typed-array-length.svg
|
---|
64 | [downloads-url]: http://npm-stat.com/charts.html?package=typed-array-length
|
---|