refactor: truthy filter

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/953/head
Varun Patil 2023-11-24 14:06:38 -08:00
parent f2f6899d53
commit 07a20fb454
2 changed files with 7 additions and 7 deletions

View File

@ -190,7 +190,7 @@ export async function extendWithStack(photos: IPhoto[]) {
}), }),
10, 10,
)) { )) {
livePhotos.push(...utils.filterTruthy(res)); livePhotos.push(...res.filter(utils.truthy));
} }
// Add stacked RAW files (deduped) // Add stacked RAW files (deduped)

View File

@ -116,12 +116,12 @@ export function isNumber<T>(num: T): boolean {
return !isNaN(cast) && isFinite(cast); return !isNaN(cast) && isFinite(cast);
} }
/** Check if a property is truthy */ /** Check if a value is truthy */
export function truthy<T, K extends keyof T>(obj: T, prop: K): obj is T & { [P in K]-?: T[K] } { export function truthy<T>(value: T): value is NonNullable<T> {
return !!obj[prop]; return !!value;
} }
/** Filter truthy values from an array */ /** Check if a property is truthy */
export function filterTruthy<T>(arr: T[]): NonNullable<T>[] { export function truthyProp<T, K extends keyof T>(obj: T, prop: K): obj is T & { [P in K]-?: T[K] } {
return arr.filter(Boolean) as NonNullable<T>[]; return truthy(obj[prop]);
} }