🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@lamansky/flatten

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lamansky/flatten

A one-liner function that flattens arrays.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

flatten

A one-liner function that flattens arrays.

Installation

Requires Node.js 6.0.0 or above.

npm i @lamansky/flatten

API

The module exports a single function.

Parameters

  • Bindable: arr (Array): The array to be flattened
  • Object argument:
    • Optional: depth (integer): Defaults to Infinity. If 0, the original arr is returned.

Return Value

The flattened Array

Example

const flatten = require('@lamansky/flatten')

const arr = [[[1], 2], [3]]

flatten(arr) // [1, 2, 3]
flatten(arr, {depth: 1}) // [[1], 2, 3]
flatten(arr, {depth: 0}) // [[[1], 2], [3]]

// Supports the bind operator
arr::flatten() // [1, 2, 3]
arr::flatten({depth: 1}) // [[1], 2, 3]

Keywords

flatten

FAQs

Package last updated on 03 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