@strong-roots-capital/as-array
Version:
Promote non-array values to an array
18 lines (17 loc) • 382 B
TypeScript
/**
* as-array
* Promote non-array values to an array
*/
/**
* Promote `value` to an array, if not already.
*
* @remarks
*
* - will not modify arrays
* - promotes `null` to []
* - promotes `undefined` to []
*
* @param value - Value to wrap in an array if necessary
* @returns Value wrapped in an array
*/
export default function asArray<T = any>(value: T | T[]): T[];