Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

array.prototype.flatten

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array.prototype.flatten

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

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7K
increased by138.13%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 24 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc