npm install array.prototype.toreversed

An ESnext spec-compliant `Array.prototype.toReversed` shim/polyfill/replacement that works as far down as ES3.

About array.prototype.toreversed

The npm package "array.prototype.toreversed" offers a robust solution for developers needing a straightforward, efficient method to reverse arrays in JavaScript. This package is an ESnext spec-compliant shim/polyfill/replacement for `Array.prototype.toReversed`, ensuring it operates seamlessly across different JavaScript environments, including those as old as ES3. This compatibility is crucial for maintaining legacy systems while also taking advantage of modern JavaScript features. The package ensures that developers can apply a non-destructive reverse function to arrays, meaning the original array remains unaltered while a new reversed array is returned. This functionality is particularly beneficial in functional programming paradigms where immutability is a key concern.

To integrate this functionality into your project, simply run the command `npm install array.prototype.toreversed`. This installation process is quick and adds immediate reverse array capabilities to your applications. The inclusion of this node module helps streamline development processes by eliminating the need to manually script complex logic for reversing array elements, thereby reducing potential errors and improving code readability. Once installed, the package does not modify the original Array prototype, which is a significant advantage for developers looking to maintain clear, predictable codebases. This approach aligns well with modern development practices that prioritize minimal side effects and promote easier maintenance and testing.

By utilizing "array.prototype.toreversed", developers can enhance their applications' performance and reliability. The package's compliance with the latest ECMAScript specifications ensures that it integrates well with contemporary development tools and frameworks, making it a future-proof choice for developers aiming to build scalable, efficient applications. The non-invasive nature of the shim also means that it can be safely used in virtually any JavaScript project without risking interference with other array functions or existing code, showcasing its versatility and reliability as a top choice for professional development environments.

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-shim-unscopables, @es-shims/api, @ljharb/eslint-config, aud, auto-changelog, eslint, evalmd, functions-have-names, has-strict-mode, in-publish, nyc, safe-publish-latest, tape

Documentation

A README file for the array.prototype.toreversed code repository. View Code

array.prototype.toreversed Version Badge

dependency status dev dependency status License Downloads

npm badge

An ESnext spec-compliant Array.prototype.toReversed shim/polyfill/replacement that works as far down as ES3.

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

Because Array.prototype.toReversed depends on a receiver (the this value), the main export takes the array to operate on as the first argument.

Getting started

npm install --save array.prototype.toreversed

Usage/Examples

var toReversed = require('array.prototype.toreversed');
var assert = require('assert');

var arr = [0, 1, 2, 3, 4, 5];

var results = toReversed(arr);

assert.deepEqual(results, [5, 4, 3, 2, 1, 0]);
assert.deepEqual(arr, [0, 1, 2, 3, 4, 5]);
var toReversed = require('array.prototype.toreversed');
var assert = require('assert');
/* when Array#toReversed is not present */
delete Array.prototype.toReversed;
var shimmed = toReversed.shim();

assert.equal(shimmed, toReversed.getPolyfill());
assert.deepEqual(arr.toReversed(), toReversed(arr));
var toReversed = require('array.prototype.toreversed');
var assert = require('assert');
/* when Array#toReversed is present */
var shimmed = toReversed.shim();

assert.equal(shimmed, Array.prototype.toReversed);
assert.deepEqual(arr.toReversed(), toReversed(arr));

Tests

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