UNPKG

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