UNPKG

11.6 kBTypeScriptView Raw
1declare module "util" {
2 interface InspectOptions extends NodeJS.InspectOptions { }
3 function format(format: any, ...param: any[]): string;
4 function formatWithOptions(inspectOptions: InspectOptions, format: string, ...param: any[]): string;
5 /** @deprecated since v0.11.3 - use a third party module instead. */
6 function log(string: string): void;
7 function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
8 function inspect(object: any, options: InspectOptions): string;
9 namespace inspect {
10 let colors: {
11 [color: string]: [number, number] | undefined
12 };
13 let styles: {
14 [style: string]: string | undefined
15 };
16 let defaultOptions: InspectOptions;
17 /**
18 * Allows changing inspect settings from the repl.
19 */
20 let replDefaults: InspectOptions;
21 const custom: unique symbol;
22 }
23 /** @deprecated since v4.0.0 - use `Array.isArray()` instead. */
24 function isArray(object: any): object is any[];
25 /** @deprecated since v4.0.0 - use `util.types.isRegExp()` instead. */
26 function isRegExp(object: any): object is RegExp;
27 /** @deprecated since v4.0.0 - use `util.types.isDate()` instead. */
28 function isDate(object: any): object is Date;
29 /** @deprecated since v4.0.0 - use `util.types.isNativeError()` instead. */
30 function isError(object: any): object is Error;
31 function inherits(constructor: any, superConstructor: any): void;
32 function debuglog(key: string): (msg: string, ...param: any[]) => void;
33 /** @deprecated since v4.0.0 - use `typeof value === 'boolean'` instead. */
34 function isBoolean(object: any): object is boolean;
35 /** @deprecated since v4.0.0 - use `Buffer.isBuffer()` instead. */
36 function isBuffer(object: any): object is Buffer;
37 /** @deprecated since v4.0.0 - use `typeof value === 'function'` instead. */
38 function isFunction(object: any): boolean;
39 /** @deprecated since v4.0.0 - use `value === null` instead. */
40 function isNull(object: any): object is null;
41 /** @deprecated since v4.0.0 - use `value === null || value === undefined` instead. */
42 function isNullOrUndefined(object: any): object is null | undefined;
43 /** @deprecated since v4.0.0 - use `typeof value === 'number'` instead. */
44 function isNumber(object: any): object is number;
45 /** @deprecated since v4.0.0 - use `value !== null && typeof value === 'object'` instead. */
46 function isObject(object: any): boolean;
47 /** @deprecated since v4.0.0 - use `(typeof value !== 'object' && typeof value !== 'function') || value === null` instead. */
48 function isPrimitive(object: any): boolean;
49 /** @deprecated since v4.0.0 - use `typeof value === 'string'` instead. */
50 function isString(object: any): object is string;
51 /** @deprecated since v4.0.0 - use `typeof value === 'symbol'` instead. */
52 function isSymbol(object: any): object is symbol;
53 /** @deprecated since v4.0.0 - use `value === undefined` instead. */
54 function isUndefined(object: any): object is undefined;
55 function deprecate<T extends Function>(fn: T, message: string, code?: string): T;
56 function isDeepStrictEqual(val1: any, val2: any): boolean;
57
58 interface CustomPromisify<TCustom extends Function> extends Function {
59 __promisify__: TCustom;
60 }
61
62 function callbackify(fn: () => Promise<void>): (callback: (err: NodeJS.ErrnoException) => void) => void;
63 function callbackify<TResult>(fn: () => Promise<TResult>): (callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
64 function callbackify<T1>(fn: (arg1: T1) => Promise<void>): (arg1: T1, callback: (err: NodeJS.ErrnoException) => void) => void;
65 function callbackify<T1, TResult>(fn: (arg1: T1) => Promise<TResult>): (arg1: T1, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
66 function callbackify<T1, T2>(fn: (arg1: T1, arg2: T2) => Promise<void>): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException) => void) => void;
67 function callbackify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2) => Promise<TResult>): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
68 function callbackify<T1, T2, T3>(fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<void>): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException) => void) => void;
69 function callbackify<T1, T2, T3, TResult>(
70 fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
71 function callbackify<T1, T2, T3, T4>(
72 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException) => void) => void;
73 function callbackify<T1, T2, T3, T4, TResult>(
74 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
75 function callbackify<T1, T2, T3, T4, T5>(
76 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException) => void) => void;
77 function callbackify<T1, T2, T3, T4, T5, TResult>(
78 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>,
79 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
80 function callbackify<T1, T2, T3, T4, T5, T6>(
81 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<void>,
82 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException) => void) => void;
83 function callbackify<T1, T2, T3, T4, T5, T6, TResult>(
84 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<TResult>
85 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
86
87 function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
88 function promisify<TResult>(fn: (callback: (err: any, result: TResult) => void) => void): () => Promise<TResult>;
89 function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
90 function promisify<T1, TResult>(fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void): (arg1: T1) => Promise<TResult>;
91 function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
92 function promisify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void): (arg1: T1, arg2: T2) => Promise<TResult>;
93 function promisify<T1, T2>(fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2) => Promise<void>;
94 function promisify<T1, T2, T3, TResult>(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => void) => void):
95 (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>;
96 function promisify<T1, T2, T3>(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2, arg3: T3) => Promise<void>;
97 function promisify<T1, T2, T3, T4, TResult>(
98 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void,
99 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
100 function promisify<T1, T2, T3, T4>(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: any) => void) => void):
101 (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>;
102 function promisify<T1, T2, T3, T4, T5, TResult>(
103 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => void) => void,
104 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
105 function promisify<T1, T2, T3, T4, T5>(
106 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void,
107 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
108 function promisify(fn: Function): Function;
109
110 namespace types {
111 function isAnyArrayBuffer(object: any): boolean;
112 function isArgumentsObject(object: any): object is IArguments;
113 function isArrayBuffer(object: any): object is ArrayBuffer;
114 function isAsyncFunction(object: any): boolean;
115 function isBooleanObject(object: any): object is Boolean;
116 function isBoxedPrimitive(object: any): object is (Number | Boolean | String | Symbol /* | Object(BigInt) | Object(Symbol) */);
117 function isDataView(object: any): object is DataView;
118 function isDate(object: any): object is Date;
119 function isExternal(object: any): boolean;
120 function isFloat32Array(object: any): object is Float32Array;
121 function isFloat64Array(object: any): object is Float64Array;
122 function isGeneratorFunction(object: any): boolean;
123 function isGeneratorObject(object: any): boolean;
124 function isInt8Array(object: any): object is Int8Array;
125 function isInt16Array(object: any): object is Int16Array;
126 function isInt32Array(object: any): object is Int32Array;
127 function isMap(object: any): boolean;
128 function isMapIterator(object: any): boolean;
129 function isModuleNamespaceObject(value: any): boolean;
130 function isNativeError(object: any): object is Error;
131 function isNumberObject(object: any): object is Number;
132 function isPromise(object: any): boolean;
133 function isProxy(object: any): boolean;
134 function isRegExp(object: any): object is RegExp;
135 function isSet(object: any): boolean;
136 function isSetIterator(object: any): boolean;
137 function isSharedArrayBuffer(object: any): boolean;
138 function isStringObject(object: any): boolean;
139 function isSymbolObject(object: any): boolean;
140 function isTypedArray(object: any): object is NodeJS.TypedArray;
141 function isUint8Array(object: any): object is Uint8Array;
142 function isUint8ClampedArray(object: any): object is Uint8ClampedArray;
143 function isUint16Array(object: any): object is Uint16Array;
144 function isUint32Array(object: any): object is Uint32Array;
145 function isWeakMap(object: any): boolean;
146 function isWeakSet(object: any): boolean;
147 function isWebAssemblyCompiledModule(object: any): boolean;
148 }
149
150 class TextDecoder {
151 readonly encoding: string;
152 readonly fatal: boolean;
153 readonly ignoreBOM: boolean;
154 constructor(
155 encoding?: string,
156 options?: { fatal?: boolean; ignoreBOM?: boolean }
157 );
158 decode(
159 input?: NodeJS.ArrayBufferView | ArrayBuffer | null,
160 options?: { stream?: boolean }
161 ): string;
162 }
163
164 interface EncodeIntoResult {
165 /**
166 * The read Unicode code units of input.
167 */
168
169 read: number;
170 /**
171 * The written UTF-8 bytes of output.
172 */
173 written: number;
174 }
175
176 class TextEncoder {
177 readonly encoding: string;
178 encode(input?: string): Uint8Array;
179 encodeInto(input: string, output: Uint8Array): EncodeIntoResult;
180 }
181
182 namespace promisify {
183 const custom: unique symbol;
184 }
185}