es-shims/Array.prototype.flat

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

Homepage:

Size: 38

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

array.prototype.flat Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

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.

Getting started
install --save array.prototype.flat
Usage/Examples
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));
Tests

Simply clone the repo, npm install, and run npm test


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.