Socket
Socket
Sign inDemoInstall

array-back

Package Overview
Dependencies
0
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    array-back

Guarantees an array back


Version published
Weekly downloads
5.3M
increased by2.4%
Maintainers
1
Install size
11.3 kB
Created
Weekly downloads
 

Package description

What is array-back?

The array-back npm package is designed to ensure that any value provided to it is returned as an array. This can be useful when you are not sure if a function will receive an argument as a single value or an array of values. It helps to normalize the input for further processing.

What are array-back's main functionalities?

Convert a non-array value to an array

This feature takes a single value and wraps it in an array. If the value is already an array, it returns the array unchanged.

[].concat(arrayBack(value))

Flatten nested arrays

This feature can be used to flatten nested arrays into a single-level array.

arrayBack([1, [2, [3]]])

Ignore empty slots in sparse arrays

This feature allows the conversion of sparse arrays into compact arrays without empty slots.

arrayBack(new Array(5))

Other packages similar to array-back

Readme

Source

view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI Coverage Status js-standard-style

array-back

Takes any input and guarantees an array back.

  • Converts array-like objects (e.g. arguments, Set) to a real array.
  • Converts undefined to an empty array.
  • Converts any another other, singular value (including null, objects and iterables other than Set) into an array containing that value.
  • Ignores input which is already an array.

Example

> const arrayify = require('array-back')

> arrayify(undefined)
[]

> arrayify(null)
[ null ]

> arrayify(0)
[ 0 ]

> arrayify([ 1, 2 ])
[ 1, 2 ]

> arrayify(new Set([ 1, 2 ]))
[ 1, 2 ]

> function f(){ return arrayify(arguments); }
> f(1,2,3)
[ 1, 2, 3 ]

arrayify(input) ⇒ Array

Kind: Exported function

ParamTypeDescription
input*The input value to convert to an array

Load anywhere

This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.

Node.js:

const arrayify = require('array-back')

Within Node.js with ECMAScript Module support enabled:

import arrayify from 'array-back'

Within an modern browser ECMAScript Module:

import arrayify from './node_modules/array-back/index.js'

© 2015-22 Lloyd Brookes <75pound@gmail.com>.

Isomorphic test suite by test-runner and web-runner. Documented by jsdoc-to-markdown.

Keywords

FAQs

Last updated on 14 Jan 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc