-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathutil.ts
49 lines (38 loc) · 1.2 KB
/
util.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
39
40
41
42
43
44
45
46
47
48
49
export const encoder = new TextEncoder();
export const decoder = new TextDecoder();
export function isArray<T>(input: T[] | unknown): input is T[] {
return Array.isArray(input);
}
export function isDefined<T>(input: T | undefined): input is T {
return input !== undefined;
}
export function isNotNull<T>(input: T | null): input is T {
return input !== null;
}
export function isNotNumber<T>(input: T | number): input is T {
return typeof input !== "number";
}
export function isNotString<T>(input: T | string): input is T {
return typeof input !== "string";
}
export function isNull(input: unknown): input is null {
return input === null;
}
export function isNumber(input: unknown): input is number {
return typeof input === "number";
}
export function isNotTrue<T>(input: T | true): input is T {
return input !== true;
}
export function isObject(input: unknown): input is Record<string, unknown> {
return (
input !== null && typeof input === "object" &&
Array.isArray(input) === false
);
}
export function isString(input: unknown): input is string {
return typeof input === "string";
}
export function isUndefined(input: unknown): input is undefined {
return input === undefined;
}