Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
array-back
Advanced tools
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.
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))
Lodash is a comprehensive utility library that provides a wide range of functions for working with arrays, objects, strings, etc. It includes methods like _.toArray which can convert values to arrays, similar to array-back, but it also offers a much larger set of utilities for different purposes.
Arrify is a minimalistic package that converts a non-array value into an array. It is similar to array-back in its basic functionality but does not offer additional features like flattening nested arrays or handling sparse arrays.
Takes any input and guarantees an array back.
arguments
, Set
) to a real array.undefined
to an empty array.null
, objects and iterables other than Set
) into an array containing that value.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 ]
Array
⏏Kind: Exported function
Param | Type | Description |
---|---|---|
input | * | The input value to convert to an array |
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.
FAQs
Guarantees an array back
The npm package array-back receives a total of 5,536,048 weekly downloads. As such, array-back popularity was classified as popular.
We found that array-back demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.