@strong-roots-capital/as-array
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

as-array Build status npm version codecov

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' } ]

Related

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    4
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    4

Package Sidebar

Install

npm i @strong-roots-capital/as-array

Weekly Downloads

4

Version

1.0.0

License

ISC

Unpacked Size

4.8 kB

Total Files

4

Last publish

Collaborators

  • amchelle
  • hamroctopus