@lou.codes/parsers
Version:
👁️🗨️ Parsers without nonsense
23 lines (22 loc) • 614 B
JavaScript
import { isNaN } from "@lou.codes/constants/Number.js";
/**
* NaN handler.
*
* @category Number
* @remarks
* Takes a `number` that could be `NaN` and makes it `undefined` if it is `NaN`.
* @example
* ```typescript
* undefineNaN(10); // 10
* undefineNaN(13.10); // 13.1
* undefineNaN(NaN); // undefined
* ```
*
* @template Number Generic of the number to handle.
* @param number Number to handle.
* @returns Number if it's not `NaN`, otherwise `undefined`.
*/
export const undefineNaN = (
// eslint-disable-next-line @typescript-eslint/ban-types
number,
) => (isNaN(number) ? undefined : number);