|
1 |
| -# Array.prototype.reverse |
2 |
| -Array.prototype.reverse spec-compliant polyfill |
| 1 | +# array.prototype.reverse <sup>[![Version Badge][npm-version-svg]][package-url]</sup> |
| 2 | + |
| 3 | +[![github actions][actions-image]][actions-url] |
| 4 | +[![coverage][codecov-image]][codecov-url] |
| 5 | +[![dependency status][deps-svg]][deps-url] |
| 6 | +[![dev dependency status][dev-deps-svg]][dev-deps-url] |
| 7 | +[![License][license-image]][license-url] |
| 8 | +[![Downloads][downloads-image]][downloads-url] |
| 9 | + |
| 10 | +[![npm badge][npm-badge-png]][package-url] |
| 11 | + |
| 12 | +An ES spec-compliant `Array.prototype.reverse` shim/polyfill/replacement that works as far down as ES3. |
| 13 | + |
| 14 | +This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the [spec](https://tc39.es/ecma262/#sec-array.prototype.reverse). |
| 15 | + |
| 16 | +Because `Array.prototype.reverse` depends on a receiver (the “this” value), the main export takes the array to operate on as the first argument. |
| 17 | + |
| 18 | +## Example |
| 19 | + |
| 20 | +```js |
| 21 | +var reverse = require('array.prototype.reverse'); |
| 22 | +var assert = require('assert'); |
| 23 | + |
| 24 | +var a = [1, 2, 3]; |
| 25 | +assert.deepEqual(reverse(a), [3, 2, 1]); |
| 26 | +assert.deepEqual(a, [3, 2, 1]); |
| 27 | +``` |
| 28 | + |
| 29 | +```js |
| 30 | +var reverse = require('array.prototype.reverse'); |
| 31 | +var assert = require('assert'); |
| 32 | +/* when Array#reverse is not present */ |
| 33 | +delete Array.prototype.reverse; |
| 34 | +var shimmed = reverse.shim(); |
| 35 | +assert.equal(shimmed, reverse.getPolyfill()); |
| 36 | +assert.equal(shimmed, Array.prototype.reverse); |
| 37 | +assert.deepEqual([1, 2, 3].reverse(), reverse([1, 2, 3])); |
| 38 | +``` |
| 39 | + |
| 40 | +```js |
| 41 | +var reverse = require('array.prototype.reverse'); |
| 42 | +var assert = require('assert'); |
| 43 | +/* when Array#reverse is present */ |
| 44 | +var shimmed = reverse.shim(); |
| 45 | +assert.equal(shimmed, Array.prototype.reverse); |
| 46 | +assert.deepEqual([1, 2, 3].reverse(), reverse([1, 2, 3])); |
| 47 | +``` |
| 48 | + |
| 49 | +## Tests |
| 50 | +Simply clone the repo, `npm install`, and run `npm test` |
| 51 | + |
| 52 | +[package-url]: https://npmjs.org/package/array.prototype.reverse |
| 53 | +[npm-version-svg]: https://versionbadg.es/es-shims/Array.prototype.reverse.svg |
| 54 | +[deps-svg]: https://david-dm.org/es-shims/Array.prototype.reverse.svg |
| 55 | +[deps-url]: https://david-dm.org/es-shims/Array.prototype.reverse |
| 56 | +[dev-deps-svg]: https://david-dm.org/es-shims/Array.prototype.reverse/dev-status.svg |
| 57 | +[dev-deps-url]: https://david-dm.org/es-shims/Array.prototype.reverse#info=devDependencies |
| 58 | +[npm-badge-png]: https://nodei.co/npm/array.prototype.reverse.png?downloads=true&stars=true |
| 59 | +[license-image]: https://img.shields.io/npm/l/array.prototype.reverse.svg |
| 60 | +[license-url]: LICENSE |
| 61 | +[downloads-image]: https://img.shields.io/npm/dm/array.prototype.reverse.svg |
| 62 | +[downloads-url]: https://npm-stat.com/charts.html?package=array.prototype.reverse |
| 63 | +[codecov-image]: https://codecov.io/gh/es-shims/Array.prototype.reverse/branch/main/graphs/badge.svg |
| 64 | +[codecov-url]: https://app.codecov.io/gh/es-shims/Array.prototype.reverse/ |
| 65 | +[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Array.prototype.reverse |
| 66 | +[actions-url]: https://github.com/es-shims/Array.prototype.reverse/actions |
0 commit comments