Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

typed-array-length

inspect-js91.5mMIT1.0.7TypeScript support: included

Robustly get the length of a Typed Array

typed, array, length, robust, es, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array

readme

typed-array-length Version Badge

dependency status dev dependency status License Downloads

npm badge

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.

Example

var typedArrayLength = require('typed-array-length');
var assert = require('assert');

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

assert.equal(1, typedArrayLength(new Int8Array(1)));
assert.equal(2, typedArrayLength(new Uint8Array(2)));
assert.equal(3, typedArrayLength(new Uint8ClampedArray(3)));
assert.equal(4, typedArrayLength(new Int16Array(4)));
assert.equal(5, typedArrayLength(new Uint16Array(5)));
assert.equal(6, typedArrayLength(new Int32Array(6)));
assert.equal(7, typedArrayLength(new Uint32Array(7)));
assert.equal(8, typedArrayLength(new Float32Array(8)));
assert.equal(9, typedArrayLength(new Float64Array(9)));
assert.equal(10, typedArrayLength(new BigInt64Array(10)));
assert.equal(11, typedArrayLength(new BigUint64Array(11)));

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.0.7 - 2024-11-22

Fixed

  • [Fix] avoid relying on __proto__ accessor #9

Commits

  • [Tests] fix TS issues f36b6bd
  • [actions] split out node 10-20, and 20+ d81efa0
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/eslint-config, @types/object-inspect, auto-changelog, object-inspect, tape a61b15b
  • [Tests] replace aud with npm audit b0b4e8f

v1.0.6 - 2024-03-21

Commits

  • [types] vastly improve types 9f68d36
  • [types] use shared config b6b3cbc
  • [actions] remove redundant finisher c69896e
  • [Tests] actually check types in tests, and add attw e2c3f94

v1.0.5 - 2024-02-20

Commits

  • add types df51e65
  • [Refactor] use possible-typed-array-names for a single source of truth 84503a3
  • [actions] update rebase action to use reusable workflow f163023
  • [Dev Deps] update @ljharb/eslint-config, aud, npmignore, object-inspect, tape 57ca930
  • [Dev Deps] update aud, is-callable, object-inspect, tape 99343f4
  • [Refactor] use gopd and has-proto b134a5c
  • [Deps] update call-bind, is-typed-array 3b62f55
  • [meta] add missing engines.node ff3e9f7
  • [Deps] update is-typed-array 877f507
  • [meta] add sideEffects flag 6e91309

v1.0.4 - 2022-05-23

Commits

  • [actions] reuse common workflows dfd4a37
  • [meta] use npmignore to autogenerate an npmignore file a837e80
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, is-callable, object-inspect, tape 7b05a87
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, object-inspect, tape c495f6e
  • [meta] simplify "exports" e42a6b6
  • [Fix] ensure for-each dependency is properly listed 8ec761c
  • [Deps] update call-bind, is-typed-array 2cc173a
  • [meta] add safe-publish-latest e8e3afa
  • [Deps] update is-typed-array cd8084d

v1.0.3 - 2020-12-05

Commits

  • [Tests] migrate tests to Github Actions a578b83
  • [meta] avoid publishing github workflows f064a4b
  • [Tests] run nyc on all tests 69b841e
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, object-inspect, tape 4594e83
  • [actions] add "Allow Edits" workflow 81e953b
  • [Deps] update is-typed-array; use call-bind instead of es-abstract e7da56b
  • [readme] remove travis badge 6d610d8
  • [actions] switch Automatic Rebase workflow to pull_request_target event 2d0ad64

v1.0.2 - 2020-04-22

Commits

  • [Dev Deps] update make-arrow-function, make-generator-function 4facf69
  • [Deps] update is-typed-array, es-abstract aaf3585
  • [Dev Deps] update aud, auto-changelog f10e298
  • [meta] allow package.json to be required/imported 104f4c6
  • [Tests] only audit prod deps c748ab5
  • [Deps] update es-abstract 6cd213e
  • [Dev Deps] update tape 2b0b2ea
  • [Dev Deps] update @ljharb/eslint-config cf462f3
  • [Deps] update is-typed-array ff46995

v1.0.1 - 2020-01-19

Commits

v1.0.0 - 2020-01-18

Commits