array.prototype.flatten

An ESnext spec-compliant `Array.prototype.flatten` shim/polyfill/replacement that works as far down as ES3.

This method has been renamed to "flat" - please use `array.prototype.flat` instead
Last updated 8 years ago by ljharb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install array.prototype.flatten 
SYNC missed versions from official npm registry.

array.prototype.flatten Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

An ESnext spec-compliant Array.prototype.flatten 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.flatten depends on a receiver (the this value), the main export takes the array to operate on as the first argument.

Getting started

npm install --save array.prototype.flatten

Usage/Examples

var flatten = require('array.prototype.flatten');
var assert = require('assert');

var arr = [1, [2], [], 3, [[4]]];

assert.deepEqual(flatten(arr, 1), [1, 2, 3, [4]]);
var flatten = require('array.prototype.flatten');
var assert = require('assert');
/* when Array#flatten is not present */
delete Array.prototype.flatten;
var shimmedFlatten = flatten.shim();

assert.equal(shimmedFlatten, flatten.getPolyfill());
assert.deepEqual(arr.flatten(), flatten(arr));
var flatten = require('array.prototype.flatten');
var assert = require('assert');
/* when Array#flatten is present */
var shimmedIncludes = flatten.shim();

var mapper = function (x) { return [x, 1]; };

assert.equal(shimmedIncludes, Array.prototype.flatten);
assert.deepEqual(arr.flatten(mapper), flatten(arr, mapper));

Tests

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

Current Tags

  • 1.2.1                                ...           latest (8 years ago)

6 Versions

  • 1.2.1 [deprecated]           ...           8 years ago
  • 1.2.0 [deprecated]           ...           8 years ago
  • 1.1.1 [deprecated]           ...           8 years ago
  • 1.1.0 [deprecated]           ...           9 years ago
  • 1.0.1 [deprecated]           ...           9 years ago
  • 1.0.0 [deprecated]           ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (3)
Dev Dependencies (9)

Copyright 2013 - present © cnpmjs.org | Home |