An ESnext spec-compliant `Array.prototype.toReversed` shim/polyfill/replacement that works as far down as ES3.
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.
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
A README file for the array.prototype.toreversed code repository. View Code
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.
npm install --save array.prototype.toreversed
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));
Simply clone the repo, npm install
, and run npm test