unwrapper
A simple module that unwraps an array when deemed necessary for the result passed to a given function. The threshold in which it is deemed necessary is determined by the length of the array returned. A length of 1 is assumed to be something you want unwrapped.
install
npm i unwrapper --save
Example
var unwrap = ;var api = ; //// Pretend this API returns an [] even when you expect it to be a single entity//api;
API
;
fn
: Function to executedef
: Optional Default value to use if no results returnedpred
: Predicate function for more advanced decisions than an Array of length1
Advanced usage
In some scenarios you may want to only unwrap certain Arrays of length one (e.g. listing directories of a length 1). In this case you can pass a pred
argument to unwrapper
:
;