@strong-roots-capital/as-array
v1.0.0
Published
Promote non-array values to an array
Downloads
6
Readme
as-array
Promote non-array values to an array
- dead-simple
- strongly-typed
- promotes objects as expected
- no dependencies
Install
npm install @strong-roots-capital/as-array
Use
import asArray from '@strong-roots-capital/as-array'
console.log(asArray(null))
//=>[]
console.log(asArray(undefined))
//=>[]
console.log(asArray([]))
//=>[]
console.log(asArray('horse'))
//=>[ 'horse' ]
console.log(asArray(1))
//=>[ 1 ]
console.log(asArray([1, 2, 3]))
//=>[ 1, 2, 3 ]
console.log(asArray({foo: 'bar'}))
//=>[ { foo: 'bar' } ]
console.log(asArray([{foo: 'bar'}, {loo: 'fah'}]))
//=>[ { foo: 'bar' }, { loo: 'fah' } ]