|
|
пре 1 година | |
|---|---|---|
| .. | ||
| .github | пре 1 година | |
| test | пре 1 година | |
| .editorconfig | пре 1 година | |
| .eslintrc | пре 1 година | |
| .nycrc | пре 1 година | |
| CHANGELOG.md | пре 1 година | |
| LICENSE | пре 1 година | |
| README.md | пре 1 година | |
| auto.js | пре 1 година | |
| implementation.js | пре 1 година | |
| index.js | пре 1 година | |
| package.json | пре 1 година | |
| polyfill.js | пре 1 година | |
| shim.js | пре 1 година | |
An ESnext spec-compliant Array.prototype.findLast 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.findLast 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.findlast
var findLast = require('array.prototype.findlast');
var assert = require('assert');
var arr = [1, [2], [], 3, [[4]]];
var isNumber = function (x) { return typeof x === 'number' };
assert.deepEqual(findLast(arr, isNumber), 3);
var findLast = require('array.prototype.findlast');
var assert = require('assert');
/* when Array#findLast is not present */
delete Array.prototype.findLast;
var shimmed = findLast.shim();
assert.equal(shimmed, findLast.getPolyfill());
assert.deepEqual(arr.findLast(isNumber), findLast(arr, isNumber));
var findLast = require('array.prototype.findlast');
var assert = require('assert');
/* when Array#findLast is present */
var shimmed = findLast.shim();
assert.equal(shimmed, Array.prototype.findLast);
assert.deepEqual(arr.findLast(isNumber), findLast(arr, isNumber));
Simply clone the repo, npm install, and run npm test