Promote non-array values to an array
- dead-simple
- strongly-typed
- promotes objects as expected
- no dependencies
npm install @strong-roots-capital/as-array
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' } ]