super-utils-plus
Version:
A superior alternative to Lodash with improved performance, TypeScript support, and developer experience
29 lines (28 loc) • 803 B
TypeScript
/**
* Creates an array with all falsy values removed.
* Falsy values are false, null, 0, "", undefined, and NaN.
*
* @param array - The array to compact
* @returns The new array of filtered values
*
* @example
* ```ts
* compact([0, 1, false, 2, '', 3, null, undefined, NaN]);
* // => [1, 2, 3]
* ```
*/
export declare function compact<T>(array: T[]): T[];
/**
* Creates an array with all null and undefined values removed.
* Unlike compact, this preserves other falsy values like 0, '', and false.
*
* @param array - The array to compact
* @returns The new array of filtered values
*
* @example
* ```ts
* compactNil([0, 1, false, 2, '', 3, null, undefined, NaN]);
* // => [0, 1, false, 2, '', 3, NaN]
* ```
*/
export declare function compactNil<T>(array: T[]): NonNullable<T>[];