react-querybuilder
Version:
React Query Builder component for constructing queries and filters, with utilities for executing them in various database and evaluation contexts
28 lines (20 loc) • 695 B
text/typescript
import type { Zero } from "./numeric.mjs";
/**
Returns a boolean for whether the given number is a float, like `1.5` or `-1.5`.
It returns `false` for `Infinity`.
Use-case:
- If you want to make a conditional branch based on the result of whether a number is a float or not.
@example
```
type Float = IsFloat<1.5>;
//=> true
type IntegerWithDecimal = IsInteger<1.0>;
//=> false
type NegativeFloat = IsInteger<-1.5>;
//=> true
type Infinity_ = IsInteger<Infinity>;
//=> false
```
@group type-fest
*/
export type IsFloat<T> = T extends number ? `${T}` extends `${infer _Sign extends "" | "-"}${number}.${infer Decimal extends number}` ? Decimal extends Zero ? false : true : false : false;