UNPKG

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