404aa104263e337857be93f10692f9b00768c1a5b8492d937ee6d78472f3e3b0ca671d2211065ac068998633418f23d084fd82ee18e6d6d43b260665275b40 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # ArrayBuffer.prototype.slice <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![github actions][actions-image]][actions-url]
  3. [![coverage][codecov-image]][codecov-url]
  4. [![License][license-image]][license-url]
  5. [![Downloads][downloads-image]][downloads-url]
  6. [![npm badge][npm-badge-png]][package-url]
  7. An ES spec-compliant `ArrayBuffer.prototype.slice` shim. Invoke its "shim" method to shim ArrayBuffer.prototype.slice if it is unavailable.
  8. 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).
  9. Most common usage:
  10. ```js
  11. var assert = require('assert');
  12. var slice = require('arraybuffer.prototype.slice');
  13. var ab = new ArrayBuffer(1);
  14. var arr = new Uint8Array(ab);
  15. arr[0] = 123;
  16. var ab2 = slice(ab);
  17. var arr2 = new Uint8Array(ab2);
  18. arr2[0] = 234;
  19. assert.deepEqual(arr, new Uint8Array([123]));
  20. assert.deepEqual(arr2, new Uint8Array([234]));
  21. if (!ArrayBuffer.prototype.transfer) {
  22. slice.shim();
  23. }
  24. var ab2 = ab.slice();
  25. var arr2 = new Uint8Array(ab2);
  26. arr2[0] = 234;
  27. assert.deepEqual(arr, new Uint8Array([123]));
  28. assert.deepEqual(arr2, new Uint8Array([234]));
  29. ```
  30. ## Tests
  31. Simply clone the repo, `npm install`, and run `npm test`
  32. [package-url]: https://npmjs.org/package/arraybuffer.prototype.slice
  33. [npm-version-svg]: https://versionbadg.es/es-shims/ArrayBuffer.prototype.slice.svg
  34. [deps-svg]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice.svg
  35. [deps-url]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice
  36. [dev-deps-svg]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice/dev-status.svg
  37. [dev-deps-url]: https://david-dm.org/es-shims/ArrayBuffer.prototype.slice#info=devDependencies
  38. [npm-badge-png]: https://nodei.co/npm/arraybuffer.prototype.slice.png?downloads=true&stars=true
  39. [license-image]: https://img.shields.io/npm/l/arraybuffer.prototype.slice.svg
  40. [license-url]: LICENSE
  41. [downloads-image]: https://img.shields.io/npm/dm/arraybuffer.prototype.slice.svg
  42. [downloads-url]: https://npm-stat.com/charts.html?package=arraybuffer.prototype.slice
  43. [codecov-image]: https://codecov.io/gh/es-shims/ArrayBuffer.prototype.slice/branch/main/graphs/badge.svg
  44. [codecov-url]: https://app.codecov.io/gh/es-shims/ArrayBuffer.prototype.slice/
  45. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/ArrayBuffer.prototype.slice
  46. [actions-url]: https://github.com/es-shims/ArrayBuffer.prototype.slice/actions