forked from sindresorhus/type-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
is-float.d.ts
33 lines (26 loc) · 684 Bytes
/
is-float.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type {Zero} from './numeric';
/**
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
```
*/
export type IsFloat<T> =
T extends number
? `${T}` extends `${infer _Sign extends '' | '-'}${number}.${infer Decimal extends number}`
? Decimal extends Zero
? false
: true
: false
: false;