datasurvey/src/main/webapp/app/core/util/operators.ts

10 lines
363 B
TypeScript

/*
* Function used to workaround https://github.com/microsoft/TypeScript/issues/16069
* es2019 alternative `const filteredArr = myArr.flatMap((x) => x ? x : []);`
*/
export function isPresent<T>(t: T | undefined | null | void): t is T {
return t !== undefined && t !== null;
}
export const filterNaN = (input: number): number => (isNaN(input) ? 0 : input);