(
array: (T | null | undefined)[],
opts: {
/** If true, also removes empty strings from the array. */
removeEmptyStrings?: boolean;
/** if provided, only includes items that are in the set. */
include?: Set<unknown>;
} = {},
)
| 332 | * @returns A new array with all null and undefined values removed. |
| 333 | */ |
| 334 | export const compactArray = <T, R = T>( |
| 335 | array: (T | null | undefined)[], |
| 336 | opts: { |
| 337 | /** If true, also removes empty strings from the array. */ |
| 338 | removeEmptyStrings?: boolean; |
| 339 | /** if provided, only includes items that are in the set. */ |
| 340 | include?: Set<unknown>; |
| 341 | } = {}, |
| 342 | ): R[] => { |
| 343 | return array.filter(item => { |
| 344 | if (item === null || item === undefined) { |
| 345 | return false; |
| 346 | } |
| 347 | |
| 348 | if (opts.removeEmptyStrings && item === '') { |
| 349 | return false; |
| 350 | } |
| 351 | |
| 352 | if (opts.include && !opts.include.has(item)) { |
| 353 | return false; |
| 354 | } |
| 355 | |
| 356 | return true; |
| 357 | }) as R[]; |
| 358 | }; |
| 359 | |
| 360 | /** |
| 361 | * Parses a location query object and returns a record with string arrays. |
no outgoing calls
no test coverage detected