npm install typedarray.prototype.slice

ES spec-compliant shim for TypedArray.prototype.slice

About typedarray.prototype.slice

The npm package "typedarray.prototype.slice" is an essential tool for developers working with typed arrays in JavaScript. It provides a robust, ES spec-compliant shim for the slice method on TypedArray prototypes. This method is crucial for applications that involve manipulating buffer data, such as graphics or audio processing software. By using this package, developers can ensure that their applications adhere to the latest ECMAScript standards, thereby maintaining compatibility and performance. The package helps in achieving part of the array without modifying the original array, enhancing functionality and efficiency in data handling tasks.

To incorporate "typedarray.prototype.slice" into your project, simply run the command `npm install typedarray.prototype.slice` in your terminal. This installation adds a powerful slicing capability to typed arrays in your JavaScript code, which is not available by default in older environments or some current implementations. Once installed, the module does not alter any existing prototypes unless explicitly imported and engaged in the script, making it a safe and reliable addition to any project. This specific implementation also ensures that the slice method behaves consistently across different platforms and JavaScript engines, reducing bugs and inconsistencies in data-intensive applications.

By utilizing "typedarray.prototype.slice", developers gain access to a standardized and efficient slicing method, making the handling of binary data smoother and more predictable. This package is particularly beneficial in projects where performance and standards compliance are critical. With its straightforward implementation and adherence to ECMAScript specifications, "typedarray.prototype.slice" is an invaluable tool for modern web development, ensuring that developers can focus on creating sophisticated features without worrying about underlying data structure manipulations.

More from es-shims

es-shims npm packages

Find the best node modules for your project.

Search npm

regexp.prototype.flags

ES6 spec-compliant RegExp.prototype.flags shim...

Read more
,

string.prototype.trimend

ES2019 spec-compliant String.prototype.trimEnd shim...

Read more
,

string.prototype.trimstart

ES2019 spec-compliant String.prototype.trimStart shim...

Read more
,

arraybuffer.prototype.slice

ES spec-compliant shim for ArrayBuffer.prototype...

Read more
,

string.prototype.matchall

Spec-compliant polyfill for String.prototype...

Read more
,

object.groupby

An ESnext spec-compliant `Object.groupBy` shim/polyfill/replacement that works as far down as ES3...

Read more
,

array.prototype.tosorted

An ESnext spec-compliant `Array.prototype...

Read more
,

es-iterator-helpers

An ESnext spec-compliant iterator helpers shim/polyfill/replacement that works as far down as ES3...

Read more
,

array.prototype.toreversed

An ESnext spec-compliant `Array.prototype...

Read more
,

typedarray.prototype.slice

ES spec-compliant shim for TypedArray.prototype...

Read more
,

string.prototype.replaceall

Spec-compliant polyfill for String.prototype...

Read more
,

error-cause

An ES-spec-compliant shim/polyfill/replacement for the `...

Read more

Dependencies

Core dependencies of this npm package and its dev dependencies.

call-bind, define-properties, es-abstract, es-errors, typed-array-buffer, typed-array-byte-offset, @es-shims/api, @ljharb/eslint-config, aud, auto-changelog, available-typed-arrays, eclint, es-value-fixtures, eslint, evalmd, for-each, functions-have-names, has-strict-mode, in-publish, npmignore, nyc, object-inspect, safe-publish-latest, tape

Documentation

A README file for the typedarray.prototype.slice code repository. View Code

TypedArray.prototype.slice Version Badge

github actions coverage License Downloads

npm badge

An ES spec-compliant TypedArray.prototype.slice shim. Invoke its "shim" method to shim TypedArray.prototype.slice if it is unavailable.

This package implements the es-shim API interface. It works in an ES5-supported environment and complies with the spec.

Most common usage:

var assert = require('assert');
var slice = require('typedarray.prototype.slice');

var arr = new Uint8Array([1, 2, 3]);

var arr2 = slice(arr);

arr2[0] = 2;
arr2[1] = 3;

assert.deepEqual(arr, new Uint8Array([1, 2, 3]));
assert.deepEqual(arr2, new Uint8Array([2, 3, 3]));
assert.notEqual(arr.buffer, arr2.buffer);

if (!Uint8Array.prototype.slice) {
    slice.shim();
}

var arr3 = arr.slice();
arr3[0] = 2;
arr3[1] = 3;

assert.deepEqual(arr, new Uint8Array([1, 2, 3]));
assert.deepEqual(arr3, new Uint8Array([2, 3, 3]));
assert.notEqual(arr.buffer, arr3.buffer);

Engines where this is needed

- node v0.11.4 - v4: no prototype or own `slice` method
- node < v0.11.3: own `slice` method that fails to clone the underlying buffer

Tests

Simply clone the repo, npm install, and run npm test