A simple utility for collapsing single-element arrays.
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.travis.yml
deep.js
index.js
object.js
package.json
readme.md

readme.md

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')
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'
  }
}
*/

License

MIT