source: imaps-frontend/node_modules/typed-array-byte-length/README.md

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.6 KB
Line 
1# typed-array-byte-offset <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
3[![github actions][actions-image]][actions-url]
4[![coverage][codecov-image]][codecov-url]
5[![License][license-image]][license-url]
6[![Downloads][downloads-image]][downloads-url]
7
8[![npm badge][npm-badge-png]][package-url]
9
10Robustly 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.
11
12## Example
13
14```js
15var typedArrayByteOffset = require('typed-array-byte-offset');
16var assert = require('assert');
17
18assert.equal(false, typedArrayByteOffset(undefined));
19assert.equal(false, typedArrayByteOffset(null));
20assert.equal(false, typedArrayByteOffset(false));
21assert.equal(false, typedArrayByteOffset(true));
22assert.equal(false, typedArrayByteOffset([]));
23assert.equal(false, typedArrayByteOffset({}));
24assert.equal(false, typedArrayByteOffset(/a/g));
25assert.equal(false, typedArrayByteOffset(new RegExp('a', 'g')));
26assert.equal(false, typedArrayByteOffset(new Date()));
27assert.equal(false, typedArrayByteOffset(42));
28assert.equal(false, typedArrayByteOffset(NaN));
29assert.equal(false, typedArrayByteOffset(Infinity));
30assert.equal(false, typedArrayByteOffset(new Number(42)));
31assert.equal(false, typedArrayByteOffset('foo'));
32assert.equal(false, typedArrayByteOffset(Object('foo')));
33assert.equal(false, typedArrayByteOffset(function () {}));
34assert.equal(false, typedArrayByteOffset(function* () {}));
35assert.equal(false, typedArrayByteOffset(x => x * x));
36assert.equal(false, typedArrayByteOffset([]));
37
38const buffer = new ArrayBuffer(32);
39
40assert.equal(8, typedArrayByteOffset(new Int8Array(buffer, 8)));
41assert.equal(8, typedArrayByteOffset(new Uint8Array(buffer, 8)));
42assert.equal(8, typedArrayByteOffset(new Uint8ClampedArray(buffer, 8)));
43assert.equal(4, typedArrayByteOffset(new Int16Array(buffer, 4)));
44assert.equal(4, typedArrayByteOffset(new Uint16Array(buffer, 4)));
45assert.equal(8, typedArrayByteOffset(new Int32Array(buffer, 8)));
46assert.equal(8, typedArrayByteOffset(new Uint32Array(buffer, 8)));
47assert.equal(16, typedArrayByteOffset(new Float32Array(buffer, 16)));
48assert.equal(16, typedArrayByteOffset(new Float64Array(buffer, 16)));
49assert.equal(16, typedArrayByteOffset(new BigInt64Array(buffer, 16)));
50assert.equal(16, typedArrayByteOffset(new BigUint64Array(buffer, 16)));
51```
52
53## Tests
54Simply clone the repo, `npm install`, and run `npm test`
55
56[package-url]: https://npmjs.org/package/typed-array-byte-offset
57[npm-version-svg]: https://versionbadg.es/inspect-js/typed-array-byte-offset.svg
58[deps-svg]: https://david-dm.org/inspect-js/typed-array-byte-offset.svg
59[deps-url]: https://david-dm.org/inspect-js/typed-array-byte-offset
60[dev-deps-svg]: https://david-dm.org/inspect-js/typed-array-byte-offset/dev-status.svg
61[dev-deps-url]: https://david-dm.org/inspect-js/typed-array-byte-offset#info=devDependencies
62[npm-badge-png]: https://nodei.co/npm/typed-array-byte-offset.png?downloads=true&stars=true
63[license-image]: https://img.shields.io/npm/l/typed-array-byte-offset.svg
64[license-url]: LICENSE
65[downloads-image]: https://img.shields.io/npm/dm/typed-array-byte-offset.svg
66[downloads-url]: https://npm-stat.com/charts.html?package=typed-array-byte-offset
67[codecov-image]: https://codecov.io/gh/inspect-js/typed-array-byte-offset/branch/main/graphs/badge.svg
68[codecov-url]: https://app.codecov.io/gh/inspect-js/typed-array-byte-offset/
69[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/typed-array-byte-offset
70[actions-url]: https://github.com/inspect-js/typed-array-byte-offset/actions
Note: See TracBrowser for help on using the repository browser.