UNPKG

diginext-utils

Version:
25 lines 702 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.compact = compact; /** * 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'] * ``` */ function compact(array) { if (!Array.isArray(array)) { return []; } return array.filter((item) => Boolean(item)); } //# sourceMappingURL=compact.js.map