1 | # array.prototype.findlast <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 ESnext spec-compliant `Array.prototype.findLast` 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 proposed [spec](https://tc39.es/proposal-array-find-from-last).
|
---|
15 |
|
---|
16 | Because `Array.prototype.findLast` depends on a receiver (the `this` value), the main export takes the array to operate on as the first argument.
|
---|
17 |
|
---|
18 | ## Getting started
|
---|
19 |
|
---|
20 | ```sh
|
---|
21 | npm install --save array.prototype.findlast
|
---|
22 | ```
|
---|
23 |
|
---|
24 | ## Usage/Examples
|
---|
25 |
|
---|
26 | ```js
|
---|
27 | var findLast = require('array.prototype.findlast');
|
---|
28 | var assert = require('assert');
|
---|
29 |
|
---|
30 | var arr = [1, [2], [], 3, [[4]]];
|
---|
31 | var isNumber = function (x) { return typeof x === 'number' };
|
---|
32 |
|
---|
33 | assert.deepEqual(findLast(arr, isNumber), 3);
|
---|
34 | ```
|
---|
35 |
|
---|
36 | ```js
|
---|
37 | var findLast = require('array.prototype.findlast');
|
---|
38 | var assert = require('assert');
|
---|
39 | /* when Array#findLast is not present */
|
---|
40 | delete Array.prototype.findLast;
|
---|
41 | var shimmed = findLast.shim();
|
---|
42 |
|
---|
43 | assert.equal(shimmed, findLast.getPolyfill());
|
---|
44 | assert.deepEqual(arr.findLast(isNumber), findLast(arr, isNumber));
|
---|
45 | ```
|
---|
46 |
|
---|
47 | ```js
|
---|
48 | var findLast = require('array.prototype.findlast');
|
---|
49 | var assert = require('assert');
|
---|
50 | /* when Array#findLast is present */
|
---|
51 | var shimmed = findLast.shim();
|
---|
52 |
|
---|
53 | assert.equal(shimmed, Array.prototype.findLast);
|
---|
54 | assert.deepEqual(arr.findLast(isNumber), findLast(arr, isNumber));
|
---|
55 | ```
|
---|
56 |
|
---|
57 | ## Tests
|
---|
58 | Simply clone the repo, `npm install`, and run `npm test`
|
---|
59 |
|
---|
60 | [package-url]: https://npmjs.org/package/array.prototype.findlast
|
---|
61 | [npm-version-svg]: https://versionbadg.es/es-shims/Array.prototype.findLast.svg
|
---|
62 | [deps-svg]: https://david-dm.org/es-shims/Array.prototype.findLast.svg
|
---|
63 | [deps-url]: https://david-dm.org/es-shims/Array.prototype.findLast
|
---|
64 | [dev-deps-svg]: https://david-dm.org/es-shims/Array.prototype.findLast/dev-status.svg
|
---|
65 | [dev-deps-url]: https://david-dm.org/es-shims/Array.prototype.findLast#info=devDependencies
|
---|
66 | [npm-badge-png]: https://nodei.co/npm/array.prototype.findlast.png?downloads=true&stars=true
|
---|
67 | [license-image]: https://img.shields.io/npm/l/array.prototype.findlast.svg
|
---|
68 | [license-url]: LICENSE
|
---|
69 | [downloads-image]: https://img.shields.io/npm/dm/array.prototype.findlast.svg
|
---|
70 | [downloads-url]: https://npm-stat.com/charts.html?package=array.prototype.findlast
|
---|
71 | [codecov-image]: https://codecov.io/gh/es-shims/Array.prototype.findLast/branch/main/graphs/badge.svg
|
---|
72 | [codecov-url]: https://app.codecov.io/gh/es-shims/Array.prototype.findLast/
|
---|
73 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Array.prototype.findLast
|
---|
74 | [actions-url]: https://github.com/es-shims/Array.prototype.findLast
|
---|