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,
)) {
livePhotos.push(...utils.filterTruthy(res));
livePhotos.push(...res.filter(utils.truthy));
}
// Add stacked RAW files (deduped)

View File

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