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

Package detail

typed-array-byte-offset

inspect-js86.1mMIT1.0.4TypeScript support: included

Robustly get the byte offset of a Typed Array

typed, array, byteOffset, byte, offset, 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.4 - 2024-12-18

Commits

  • [Tests] split out and enhance "no-proto" tests 64d1a73
  • [types] improve types 21f484f
  • [Tests] add --disable-proto=delete tests 8f77f2a
  • [actions] re-add a finisher; add perms 59c1b7b
  • [Deps] update call-bind, gopd, has-proto, reflect.getprototypeof c0c30d5
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/tsconfig, @types/tape 2638bd5
  • [Deps] update is-typed-array, reflect.getprototypeof 11540a5
  • [Deps] update is-typed-array ad9cb70
  • [Dev Deps] update @types/tape 2838854

v1.0.3 - 2024-11-21

Fixed

  • [Fix] avoid relying on __proto__ accessor #4

Commits

  • [types] use shared config 10b0823
  • [actions] split out node 10-20, and 20+ 11554a9
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/eslint-config, @types/object-inspect, auto-changelog, object-inspect, tape c39dd06
  • [Tests] run tsc and @arethetypeswrong/cli in CI 0b984aa
  • [Tests] replace aud with npm audit 512b59d

v1.0.2 - 2024-02-20

Commits

  • add types 9eecdd2
  • [actions] skip ls check on node < 10; remove redundant finisher 4fb4c91
  • [Deps] update available-typed-arrays, has-proto 805cee2

v1.0.1 - 2024-02-17

Commits

  • [Dev Deps] update aud, npmignore, object-inspect, tape ffe7494
  • [Deps] update available-typed-arrays, call-bind, is-typed-array 3006bd7
  • [Refactor] use gopd 45827ea
  • [Dev Deps] update tape e33d080
  • [meta] add sideEffects flag f1dc0db

v1.0.0 - 2023-06-06

Commits