1 | # ArrayBuffer.prototype.slice <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 |
|
---|
10 | An ES spec-compliant `ArrayBuffer.prototype.slice` shim. Invoke its "shim" method to shim ArrayBuffer.prototype.slice if it is unavailable.
|
---|
11 |
|
---|
12 | This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES5-supported environment and complies with the [spec](https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice).
|
---|
13 |
|
---|
14 | Most common usage:
|
---|
15 | ```js
|
---|
16 | var assert = require('assert');
|
---|
17 | var slice = require('arraybuffer.prototype.slice');
|
---|
18 |
|
---|
19 | var ab = new ArrayBuffer(1);
|
---|
20 | var arr = new Uint8Array(ab);
|
---|
21 | arr[0] = 123;
|
---|
22 |
|
---|
23 | var ab2 = slice(ab);
|
---|
24 |
|
---|
25 | var arr2 = new Uint8Array(ab2);
|
---|
26 | arr2[0] = 234;
|
---|
27 |
|
---|
28 | assert.deepEqual(arr, new Uint8Array([123]));
|
---|
29 | assert.deepEqual(arr2, new Uint8Array([234]));
|
---|
30 |
|
---|
31 | if (!ArrayBuffer.prototype.transfer) {
|
---|
32 | slice.shim();
|
---|
33 | }
|
---|
34 |
|
---|
35 | var ab2 = ab.slice();
|
---|
36 |
|
---|
37 | var arr2 = new Uint8Array(ab2);
|
---|
38 | arr2[0] = 234;
|
---|
39 |
|
---|
40 | assert.deepEqual(arr, new Uint8Array([123]));
|
---|
41 | assert.deepEqual(arr2, new Uint8Array([234]));
|
---|
42 | ```
|
---|
43 |
|
---|
44 | ## Tests
|
---|
45 | Simply clone the repo, `npm install`, and run `npm test`
|
---|
46 |
|
---|
47 | [package-url]: https://npmjs.org/package/arraybuffer.prototype.slice
|
---|
48 | [npm-version-svg]: https://versionbadg.es/es-shims/ArrayBuffer.prototype.slice.svg
|
---|
49 | [deps-svg]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice.svg
|
---|
50 | [deps-url]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice
|
---|
51 | [dev-deps-svg]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice/dev-status.svg
|
---|
52 | [dev-deps-url]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice#info=devDependencies
|
---|
53 | [npm-badge-png]: https://nodei.co/npm/arraybuffer.prototype.slice.png?downloads=true&stars=true
|
---|
54 | [license-image]: https://img.shields.io/npm/l/arraybuffer.prototype.slice.svg
|
---|
55 | [license-url]: LICENSE
|
---|
56 | [downloads-image]: https://img.shields.io/npm/dm/arraybuffer.prototype.slice.svg
|
---|
57 | [downloads-url]: https://npm-stat.com/charts.html?package=arraybuffer.prototype.slice
|
---|
58 | [codecov-image]: https://codecov.io/gh/es-shims/ArrayBuffer.prototype.slice/branch/main/graphs/badge.svg
|
---|
59 | [codecov-url]: https://app.codecov.io/gh/es-shims/ArrayBuffer.prototype.slice/
|
---|
60 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/ArrayBuffer.prototype.slice
|
---|
61 | [actions-url]: https://github.com/es-shims/ArrayBuffer.prototype.slice/actions
|
---|