-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
38 lines (35 loc) · 817 Bytes
/
utils.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
34
35
36
37
38
/**
* Is x a number
* @param {*} x
* @returns {x is number}
*/
export function isNumber(x: any): x is number {
return (typeof x === 'number');
}
/**
* Is x a string
* @param {*} x
* @returns {x is string}
*/
export function isString(x: any): x is string {
return (typeof x === 'string');
}
/**
* Is x a null or undefined
* @param {*} x
* @returns {(x is null | undefined)}
*/
export function isNull(x: any): x is null | undefined {
const type = Object.prototype.toString.call(x) as string;
return (type === '[object Null]' || type === '[object Undefined]');
}
/**
* Is x a array
* - contains class that inherited array
*
* @param {*} x
* @returns {x is any}
*/
export function isArray<T>(x: any): x is T[] {
return (Object.prototype.toString.call(x) === '[object Array]');
}