castArray 76 bytes
Cast a value into an array
Usage
The castArray
function ensures that the input value is always returned as an array. If the input is already an array, it returns a shallow copy of the array. If the input is not an array, it wraps the input in a new array.
import * as _ from 'radashi'
const numberToArray = _.castArray(1) // => [1]const arrayToArray = _.castArray([1, 2, 3]) // => [1, 2, 3]const stringToArray = _.castArray('hello') // => ['hello']
const nullToArray = _.castArray(null) // => [null]const undefinedToArray = _.castArray(undefined) // => [undefined]