-
-
Notifications
You must be signed in to change notification settings - Fork 675
Expand file tree
/
Copy pathis-float.d.ts
More file actions
43 lines (33 loc) · 777 Bytes
/
is-float.d.ts
File metadata and controls
43 lines (33 loc) · 777 Bytes
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
34
35
36
37
38
39
40
41
42
43
/**
Returns a boolean for whether the given number is a float, like `1.5` or `-1.5`.
Use-case:
- If you want to make a conditional branch based on the result of whether a number is a float or not.
@example
```
import type {IsFloat, PositiveInfinity} from 'type-fest';
type A = IsFloat<1.5>;
//=> true
type B = IsFloat<-1.5>;
//=> true
type C = IsFloat<1e-7>;
//=> true
type D = IsFloat<1.0>;
//=> false
type E = IsFloat<PositiveInfinity>;
//=> false
type F = IsFloat<1.23e+21>;
//=> false
```
@category Type Guard
@category Numeric
*/
export type IsFloat<T> = T extends number
? `${T}` extends `${number}e${infer E extends '-' | '+'}${number}`
? E extends '-'
? true
: false
: `${T}` extends `${number}.${number}`
? true
: false
: false;
export {};