refactor: truthy filter
Signed-off-by: Varun Patil <radialapps@gmail.com>pull/953/head
parent
f2f6899d53
commit
07a20fb454
|
@ -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)
|
||||||
|
|
|
@ -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]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue