UNPKG

diginext-utils

Version:
22 lines 605 B
/** * Creates an array with all falsy values removed. * Falsy values are: false, null, 0, "", undefined, and NaN. * * @template T - The type of elements in the array * @param array - The array to compact * @returns A new array with falsy values removed * * @example * ```ts * compact([0, 1, false, 2, '', 3, null, undefined, NaN]); * // [1, 2, 3] * compact(['a', '', 'b', null, 'c']); // ['a', 'b', 'c'] * ``` */ export function compact(array) { if (!Array.isArray(array)) { return []; } return array.filter((item) => Boolean(item)); } //# sourceMappingURL=compact.js.map