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

Package detail

typed-array-byte-length

inspect-js85.1mMIT1.0.3TypeScript support: included

Robustly get the byte length of a Typed Array

typed, array, byteLength, byte, length, robust, es, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array

readme

typed-array-byte-offset Version Badge

github actions coverage License Downloads

npm badge

Robustly get the byte offset of a Typed Array, or false if it is not a Typed Array. Works cross-realm, in every engine, even if the byteOffset property is overridden.

Example

var typedArrayByteOffset = require('typed-array-byte-offset');
var assert = require('assert');

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

const buffer = new ArrayBuffer(32);

assert.equal(8, typedArrayByteOffset(new Int8Array(buffer, 8)));
assert.equal(8, typedArrayByteOffset(new Uint8Array(buffer, 8)));
assert.equal(8, typedArrayByteOffset(new Uint8ClampedArray(buffer, 8)));
assert.equal(4, typedArrayByteOffset(new Int16Array(buffer, 4)));
assert.equal(4, typedArrayByteOffset(new Uint16Array(buffer, 4)));
assert.equal(8, typedArrayByteOffset(new Int32Array(buffer, 8)));
assert.equal(8, typedArrayByteOffset(new Uint32Array(buffer, 8)));
assert.equal(16, typedArrayByteOffset(new Float32Array(buffer, 16)));
assert.equal(16, typedArrayByteOffset(new Float64Array(buffer, 16)));
assert.equal(16, typedArrayByteOffset(new BigInt64Array(buffer, 16)));
assert.equal(16, typedArrayByteOffset(new BigUint64Array(buffer, 16)));

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.3 - 2024-12-17

Commits

  • [types] oops, this is a type export, not a value export 2fcf3e8

v1.0.2 - 2024-12-17

Commits

  • [types] improve types fcc9606
  • [types] use shared config ca29c46
  • [actions] split out node 10-20, and 20+ 9a38c81
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/eslint-config, @ljharb/tsconfig, @types/object-inspect, @types/tape, auto-changelog, object-inspect, tape 78cd1f2
  • [Deps] update call-bind, gopd, has-proto, is-typed-array 8c13b84
  • [Tests] replace aud with npm audit 0d9aee3
  • [Tests] use @arethetypeswrong/cli abf28fa
  • [Dev Deps] add missing peer dep dfd248d

v1.0.1 - 2024-02-20

Commits

  • add types 3144671
  • [actions] skip ls check on node < 10; remove redundant finisher 0f83947
  • [Refactor] use gopd 507b948
  • [Dev Deps] update aud, available-typed-arrays, npmignore, object-inspect, tape aba282d
  • [Deps] update call-bind, has-proto, is-typed-array acfe4a9
  • [meta] add sideEffects flag 063a8a7

v1.0.0 - 2023-07-14

Commits

  • Initial implementation, tests, readme b8800c8
  • Initial commit 72723d8
  • Only apps should have lockfiles a7dfc57