UNPKG

diginext-utils

Version:
32 lines 817 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toArray = toArray; const isNull_1 = require("./isNull"); /** * Converts a value to an array. * If the value is already an array, returns it as-is. * If the value is null/undefined, returns an empty array. * Otherwise, wraps the value in an array. * * @template T - The type of the value * @param value - The value to convert * @returns An array containing the value * * @example * ```ts * toArray(5); // [5] * toArray([1, 2, 3]); // [1, 2, 3] * toArray(null); // [] * toArray('hello'); // ['hello'] * ``` */ function toArray(value) { if ((0, isNull_1.isNull)(value)) { return []; } if (Array.isArray(value)) { return value; } return [value]; } //# sourceMappingURL=toArray.js.map