collapse-array

A simple utility for collapsing single-element arrays.

npm install collapse-array
15 downloads in the last week
22 downloads in the last month

collapse-array

collapse-array is a simple utility for collapsing single-element arrays.

Build status

Browser support

Install

npm install collapse-array

Example

var collapse = require('collapse-array')

collapse([4])
// => 4

collapse([[[[2],[3]]]])
// => [2, 3]

collapse([1, 2, 3])
// => [1, 2, 3]

collapse({
  a: 123,
  b: [['one'], ['two', 'three'], ['four']],
  c: function() {
    return 'hello'
  }
})
/*
{
  a: 123,
  b: ['one', ['two', 'three'], 'four'],
  c: function() {
    return 'hello'
  }
}
*/

License

MIT

npm loves you