collapse-array
v2.0.0
Published
A simple utility for collapsing single-element arrays.
Downloads
32
Readme
collapse-array
collapse-array is a simple utility for collapsing single-element arrays.
Install
npm install collapse-array
Example
var collapse = require('collapse-array')
var collapseDeep = require('collapse-array/deep')
var collapseObj = require('collapse-array/object')
collapse([4])
// => 4
collapse([1, 2, 3])
// => [1, 2, 3]
collapseDeep([[[[2],[3]]]])
// => [2, 3]
collapseObj({
a: 123,
b: [['one'], ['two', 'three'], ['four']],
c: function () {
return 'hello'
}
})
/*
{
a: 123,
b: ['one', ['two', 'three'], 'four'],
c: function () {
return 'hello'
}
}
*/