Name: Array.prototype.flat
Owner: ECMAScript Shims
Description: An ESnext spec-compliant `Array.prototype.flat` shim/polyfill/replacement that works as far down as ES3.
Created: 2017-10-01 17:21:07.0
Updated: 2018-05-22 18:41:49.0
Pushed: 2018-05-22 18:41:35.0
Size: 38
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
An ESnext spec-compliant Array.prototype.flat
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.flat
depends on a receiver (the this
value), the main export takes the array to operate on as the first argument.
install --save array.prototype.flat
flat = require('array.prototype.flat');
assert = require('assert');
arr = [1, [2], [], 3, [[4]]];
rt.deepEqual(flat(arr, 1), [1, 2, 3, [4]]);
s
flat = require('array.prototype.flat');
assert = require('assert');
hen Array#flat is not present */
te Array.prototype.flat;
shimmedFlat = flat.shim();
rt.equal(shimmedFlat, flat.getPolyfill());
rt.deepEqual(arr.flat(), flat(arr));
s
flat = require('array.prototype.flat');
assert = require('assert');
hen Array#flat is present */
shimmedIncludes = flat.shim();
mapper = function (x) { return [x, 1]; };
rt.equal(shimmedIncludes, Array.prototype.flat);
rt.deepEqual(arr.flat(mapper), flat(arr, mapper));
Simply clone the repo, npm install
, and run npm test