UNPKG

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