UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

30 lines (28 loc) 702 B
import { dfdlT } from "@monstermann/dfdl"; //#region src/number/isFloat.ts /** * `isFloat(value)` * * Returns `true` if `value` is a finite floating-point number (not an integer), otherwise `false`. This function acts as a type guard. * * ```ts * isFloat(3.14); // true * isFloat(0.5); // true * isFloat(42); // false * isFloat(NaN); // false * isFloat(Infinity); // false * ``` * * ```ts * pipe(3.14, isFloat()); // true * pipe(0.5, isFloat()); // true * pipe(42, isFloat()); // false * pipe(NaN, isFloat()); // false * pipe(Infinity, isFloat()); // false * ``` */ const isFloat = dfdlT((value) => { return Number.isFinite(value) && !Number.isInteger(value); }, 1); //#endregion export { isFloat };