Skip to content

lamansky/unarray

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unarray

Retrieves a single value wrapped in an array.

Installation

Requires Node.js 4.0.0 or above.

npm i unarray

API

The module exports a single function.

Parameters

  1. a (array)
  2. Optional: Object argument:
    • Optional: fallback (any): A value to return if the function fails to retrieve a single value.
    • Optional: recursive (bool): If true, will retrieve a single value wrapped in nested arrays. Defaults to false.

Return Value

A single value if found. On failure, returns fallback if provided; otherwise returns the last-searched array.

Examples

const unarray = require('unarray')

unarray([123]) // 123
unarray([123], {fallback: 'abc'}) // 123
unarray([1, 2]) // [1, 2]
unarray([1, 2], {fallback: 3}) // 3
unarray([[123]]) // [123]
unarray([[123]], {recursive: true}) // 123

About

[Node.js] Retrieves a single value wrapped in an array.

Resources

License

Stars

Watchers

Forks

Packages

No packages published