@sullux/fp-light-to-array

0.0.1 • Public • Published

home

fp-light-to-array

npm i @sullux/fp-light-to-array
source
test

Produces an array from any input.

toArray

toArray(any)

If the input is already an array, the original input is returned. If the input is iterable, it is spread into a new array. The values null, undefined and '' (empty string) produce an empty array. A Date, function or number value is returned in a single-element array, while objects return an array of entries (as from Object.entries).

const { toArray } = require('@sullux/fp-light-to-array')

toArray() // []

toArray(null) // []

toArray('') // []

toArray('foo') // ['f', 'o', 'o']

toArray(42) // [42]

toArray(new Date()) // [Date: 2019-03-01T14:56:53.812Z]

toArray(() => 42) // { Function: [Function] }

toArray({ foo: 42, bar: 'baz' }) // [['foo', 42], ['bar', 'baz']]

/@sullux/fp-light-to-array/

    Package Sidebar

    Install

    npm i @sullux/fp-light-to-array

    Weekly Downloads

    2

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    1.81 kB

    Total Files

    3

    Last publish

    Collaborators

    • sullux