1
+ /**
2
+ * A type decision function
3
+ */
1
4
export type Predicate < T > = ( x : unknown ) => x is T ;
2
5
3
6
/**
4
- * Return true if the value is string
7
+ * Return ` true` if the type of `x` is ` string`.
5
8
*/
6
9
export function isString ( x : unknown ) : x is string {
7
10
return typeof x === "string" ;
8
11
}
9
12
10
13
/**
11
- * Return true if the value is number
14
+ * Return ` true` if the type of `x` is ` number`.
12
15
*/
13
16
export function isNumber ( x : unknown ) : x is number {
14
17
return typeof x === "number" ;
15
18
}
16
19
17
20
/**
18
- * Return true if the value is boolean
21
+ * Return ` true` if the type of `x` is ` boolean`.
19
22
*/
20
23
export function isBoolean ( x : unknown ) : x is boolean {
21
24
return typeof x === "boolean" ;
22
25
}
23
26
24
27
/**
25
- * Return true if the value is array
28
+ * Return `true` if the type of `x` is `array`.
29
+ *
30
+ * Use `pred` to predicate the type of items.
26
31
*/
27
32
export function isArray < T extends unknown > (
28
33
x : unknown ,
@@ -32,7 +37,9 @@ export function isArray<T extends unknown>(
32
37
}
33
38
34
39
/**
35
- * Return true if the value is object
40
+ * Return `true` if the type of `x` is `object`.
41
+ *
42
+ * Use `pred` to predicate the type of values.
36
43
*/
37
44
export function isObject < T extends unknown > (
38
45
x : unknown ,
@@ -47,35 +54,35 @@ export function isObject<T extends unknown>(
47
54
}
48
55
49
56
/**
50
- * Return true if the value is function
57
+ * Return ` true` if the type of `x` is ` function`.
51
58
*/
52
59
export function isFunction ( x : unknown ) : x is ( ...args : unknown [ ] ) => unknown {
53
60
return Object . prototype . toString . call ( x ) === "[object Function]" ;
54
61
}
55
62
56
63
/**
57
- * Return true if the value is null
64
+ * Return ` true` if the type of `x` is ` null`.
58
65
*/
59
66
export function isNull ( x : unknown ) : x is null {
60
67
return x === null ;
61
68
}
62
69
63
70
/**
64
- * Return true if the value is undefined
71
+ * Return ` true` if the type of `x` is ` undefined`.
65
72
*/
66
73
export function isUndefined ( x : unknown ) : x is undefined {
67
74
return typeof x === "undefined" ;
68
75
}
69
76
70
77
/**
71
- * Return true if the value is null or undefined
78
+ * Return ` true` if the type of `x` is ` null` or ` undefined`.
72
79
*/
73
80
export function isNullish ( x : unknown ) : x is null | undefined {
74
81
return x == null ;
75
82
}
76
83
77
84
/**
78
- * Return true if a type of value is like a type of reference .
85
+ * Return ` true` if the type of `x` follows the type of `ref` .
79
86
*/
80
87
export function isLike < R , T extends unknown > (
81
88
ref : R ,
0 commit comments