-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
util.ts
86 lines (68 loc) · 2.24 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
export { promisify } from "./_util/_util_promisify.ts";
export { callbackify } from "./_util/_util_callbackify.ts";
import * as types from "./_util/_util_types.ts";
export { types };
export function isArray(value: unknown): boolean {
return Array.isArray(value);
}
export function isBoolean(value: unknown): boolean {
return typeof value === "boolean" || value instanceof Boolean;
}
export function isNull(value: unknown): boolean {
return value === null;
}
export function isNullOrUndefined(value: unknown): boolean {
return value === null || value === undefined;
}
export function isNumber(value: unknown): boolean {
return typeof value === "number" || value instanceof Number;
}
export function isString(value: unknown): boolean {
return typeof value === "string" || value instanceof String;
}
export function isSymbol(value: unknown): boolean {
return typeof value === "symbol";
}
export function isUndefined(value: unknown): boolean {
return value === undefined;
}
export function isObject(value: unknown): boolean {
return value !== null && typeof value === "object";
}
export function isError(e: unknown): boolean {
return e instanceof Error;
}
export function isFunction(value: unknown): boolean {
return typeof value === "function";
}
export function isRegExp(value: unknown): boolean {
return value instanceof RegExp;
}
export function isPrimitive(value: unknown): boolean {
return (
value === null || (typeof value !== "object" && typeof value !== "function")
);
}
export function validateIntegerRange(
value: number,
name: string,
min = -2147483648,
max = 2147483647
): void {
// The defaults for min and max correspond to the limits of 32-bit integers.
if (!Number.isInteger(value)) {
throw new Error(`${name} must be 'an integer' but was ${value}`);
}
if (value < min || value > max) {
throw new Error(
`${name} must be >= ${min} && <= ${max}. Value was ${value}`
);
}
}
import { _TextDecoder, _TextEncoder } from "./_utils.ts";
/** The global TextDecoder */
export type TextDecoder = import("./_utils.ts")._TextDecoder;
export const TextDecoder = _TextDecoder;
/** The global TextEncoder */
export type TextEncoder = import("./_utils.ts")._TextEncoder;
export const TextEncoder = _TextEncoder;