UNPKG

15.6 kBTypeScriptView Raw
1declare module 'util' {
2 import * as types from 'util/types';
3
4 export interface InspectOptions {
5 /**
6 * If set to `true`, getters are going to be
7 * inspected as well. If set to `'get'` only getters without setter are going
8 * to be inspected. If set to `'set'` only getters having a corresponding
9 * setter are going to be inspected. This might cause side effects depending on
10 * the getter function.
11 * @default `false`
12 */
13 getters?: 'get' | 'set' | boolean | undefined;
14 showHidden?: boolean | undefined;
15 /**
16 * @default 2
17 */
18 depth?: number | null | undefined;
19 colors?: boolean | undefined;
20 customInspect?: boolean | undefined;
21 showProxy?: boolean | undefined;
22 maxArrayLength?: number | null | undefined;
23 /**
24 * Specifies the maximum number of characters to
25 * include when formatting. Set to `null` or `Infinity` to show all elements.
26 * Set to `0` or negative to show no characters.
27 * @default 10000
28 */
29 maxStringLength?: number | null | undefined;
30 breakLength?: number | undefined;
31 /**
32 * Setting this to `false` causes each object key
33 * to be displayed on a new line. It will also add new lines to text that is
34 * longer than `breakLength`. If set to a number, the most `n` inner elements
35 * are united on a single line as long as all properties fit into
36 * `breakLength`. Short array elements are also grouped together. Note that no
37 * text will be reduced below 16 characters, no matter the `breakLength` size.
38 * For more information, see the example below.
39 * @default `true`
40 */
41 compact?: boolean | number | undefined;
42 sorted?: boolean | ((a: string, b: string) => number) | undefined;
43 }
44
45 export type Style = 'special' | 'number' | 'bigint' | 'boolean' | 'undefined' | 'null' | 'string' | 'symbol' | 'date' | 'regexp' | 'module';
46 export type CustomInspectFunction = (depth: number, options: InspectOptionsStylized) => string;
47 export interface InspectOptionsStylized extends InspectOptions {
48 stylize(text: string, styleType: Style): string;
49 }
50 export function format(format?: any, ...param: any[]): string;
51 export function formatWithOptions(inspectOptions: InspectOptions, format?: any, ...param: any[]): string;
52 export function getSystemErrorMap(): Map<number, [string, string]>;
53
54 /** @deprecated since v0.11.3 - use a third party module instead. */
55 export function log(string: string): void;
56 export function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
57 export function inspect(object: any, options: InspectOptions): string;
58 export namespace inspect {
59 let colors: NodeJS.Dict<[number, number]>;
60 let styles: {
61 [K in Style]: string
62 };
63 let defaultOptions: InspectOptions;
64 /**
65 * Allows changing inspect settings from the repl.
66 */
67 let replDefaults: InspectOptions;
68 const custom: unique symbol;
69 }
70 /** @deprecated since v4.0.0 - use `Array.isArray()` instead. */
71 export function isArray(object: unknown): object is unknown[];
72 /** @deprecated since v4.0.0 - use `util.types.isRegExp()` instead. */
73 export function isRegExp(object: unknown): object is RegExp;
74 /** @deprecated since v4.0.0 - use `util.types.isDate()` instead. */
75 export function isDate(object: unknown): object is Date;
76 /** @deprecated since v4.0.0 - use `util.types.isNativeError()` instead. */
77 export function isError(object: unknown): object is Error;
78 export function inherits(constructor: unknown, superConstructor: unknown): void;
79 export function debuglog(key: string): (msg: string, ...param: unknown[]) => void;
80 /** @deprecated since v4.0.0 - use `typeof value === 'boolean'` instead. */
81 export function isBoolean(object: unknown): object is boolean;
82 /** @deprecated since v4.0.0 - use `Buffer.isBuffer()` instead. */
83 export function isBuffer(object: unknown): object is Buffer;
84 /** @deprecated since v4.0.0 - use `typeof value === 'function'` instead. */
85 export function isFunction(object: unknown): boolean;
86 /** @deprecated since v4.0.0 - use `value === null` instead. */
87 export function isNull(object: unknown): object is null;
88 /** @deprecated since v4.0.0 - use `value === null || value === undefined` instead. */
89 export function isNullOrUndefined(object: unknown): object is null | undefined;
90 /** @deprecated since v4.0.0 - use `typeof value === 'number'` instead. */
91 export function isNumber(object: unknown): object is number;
92 /** @deprecated since v4.0.0 - use `value !== null && typeof value === 'object'` instead. */
93 export function isObject(object: unknown): boolean;
94 /** @deprecated since v4.0.0 - use `(typeof value !== 'object' && typeof value !== 'function') || value === null` instead. */
95 export function isPrimitive(object: unknown): boolean;
96 /** @deprecated since v4.0.0 - use `typeof value === 'string'` instead. */
97 export function isString(object: unknown): object is string;
98 /** @deprecated since v4.0.0 - use `typeof value === 'symbol'` instead. */
99 export function isSymbol(object: unknown): object is symbol;
100 /** @deprecated since v4.0.0 - use `value === undefined` instead. */
101 export function isUndefined(object: unknown): object is undefined;
102 export function deprecate<T extends Function>(fn: T, message: string, code?: string): T;
103 export function isDeepStrictEqual(val1: unknown, val2: unknown): boolean;
104
105 export function callbackify(fn: () => Promise<void>): (callback: (err: NodeJS.ErrnoException) => void) => void;
106 export function callbackify<TResult>(fn: () => Promise<TResult>): (callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
107 export function callbackify<T1>(fn: (arg1: T1) => Promise<void>): (arg1: T1, callback: (err: NodeJS.ErrnoException) => void) => void;
108 export function callbackify<T1, TResult>(fn: (arg1: T1) => Promise<TResult>): (arg1: T1, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
109 export function callbackify<T1, T2>(fn: (arg1: T1, arg2: T2) => Promise<void>): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException) => void) => void;
110 export 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;
111 export 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;
112 export function callbackify<T1, T2, T3, TResult>(
113 fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
114 export function callbackify<T1, T2, T3, T4>(
115 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;
116 export function callbackify<T1, T2, T3, T4, TResult>(
117 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;
118 export function callbackify<T1, T2, T3, T4, T5>(
119 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;
120 export function callbackify<T1, T2, T3, T4, T5, TResult>(
121 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>,
122 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
123 export function callbackify<T1, T2, T3, T4, T5, T6>(
124 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<void>,
125 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException) => void) => void;
126 export function callbackify<T1, T2, T3, T4, T5, T6, TResult>(
127 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<TResult>
128 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
129
130 export interface CustomPromisifyLegacy<TCustom extends Function> extends Function {
131 __promisify__: TCustom;
132 }
133
134 export interface CustomPromisifySymbol<TCustom extends Function> extends Function {
135 [promisify.custom]: TCustom;
136 }
137
138 export type CustomPromisify<TCustom extends Function> = CustomPromisifySymbol<TCustom> | CustomPromisifyLegacy<TCustom>;
139
140 export function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
141 export function promisify<TResult>(fn: (callback: (err: any, result: TResult) => void) => void): () => Promise<TResult>;
142 export function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
143 export function promisify<T1, TResult>(fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void): (arg1: T1) => Promise<TResult>;
144 export function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
145 export function promisify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void): (arg1: T1, arg2: T2) => Promise<TResult>;
146 export function promisify<T1, T2>(fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2) => Promise<void>;
147 export function promisify<T1, T2, T3, TResult>(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => void) => void):
148 (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>;
149 export 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>;
150 export function promisify<T1, T2, T3, T4, TResult>(
151 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void,
152 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
153 export function promisify<T1, T2, T3, T4>(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: any) => void) => void):
154 (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>;
155 export function promisify<T1, T2, T3, T4, T5, TResult>(
156 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => void) => void,
157 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
158 export function promisify<T1, T2, T3, T4, T5>(
159 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void,
160 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
161 export function promisify(fn: Function): Function;
162 export namespace promisify {
163 const custom: unique symbol;
164 }
165 export class TextDecoder {
166 readonly encoding: string;
167 readonly fatal: boolean;
168 readonly ignoreBOM: boolean;
169 constructor(
170 encoding?: string,
171 options?: { fatal?: boolean | undefined; ignoreBOM?: boolean | undefined }
172 );
173 decode(
174 input?: NodeJS.ArrayBufferView | ArrayBuffer | null,
175 options?: { stream?: boolean | undefined }
176 ): string;
177 }
178
179 export interface EncodeIntoResult {
180 /**
181 * The read Unicode code units of input.
182 */
183
184 read: number;
185 /**
186 * The written UTF-8 bytes of output.
187 */
188 written: number;
189 }
190
191 export { types };
192
193 export class TextEncoder {
194 readonly encoding: string;
195 encode(input?: string): Uint8Array;
196 encodeInto(input: string, output: Uint8Array): EncodeIntoResult;
197 }
198}
199
200declare module 'node:util' {
201 export * from 'util';
202}
203
204declare module 'util/types' {
205 import { KeyObject, webcrypto } from 'crypto';
206
207 function isAnyArrayBuffer(object: unknown): object is ArrayBufferLike;
208 function isArgumentsObject(object: unknown): object is IArguments;
209 function isArrayBuffer(object: unknown): object is ArrayBuffer;
210 function isArrayBufferView(object: unknown): object is NodeJS.ArrayBufferView;
211 function isAsyncFunction(object: unknown): boolean;
212 function isBigInt64Array(value: unknown): value is BigInt64Array;
213 function isBigUint64Array(value: unknown): value is BigUint64Array;
214 function isBooleanObject(object: unknown): object is Boolean;
215 function isBoxedPrimitive(object: unknown): object is String | Number | BigInt | Boolean | Symbol;
216 function isDataView(object: unknown): object is DataView;
217 function isDate(object: unknown): object is Date;
218 function isExternal(object: unknown): boolean;
219 function isFloat32Array(object: unknown): object is Float32Array;
220 function isFloat64Array(object: unknown): object is Float64Array;
221 function isGeneratorFunction(object: unknown): object is GeneratorFunction;
222 function isGeneratorObject(object: unknown): object is Generator;
223 function isInt8Array(object: unknown): object is Int8Array;
224 function isInt16Array(object: unknown): object is Int16Array;
225 function isInt32Array(object: unknown): object is Int32Array;
226 function isMap<T>(
227 object: T | {},
228 ): object is T extends ReadonlyMap<any, any>
229 ? unknown extends T
230 ? never
231 : ReadonlyMap<any, any>
232 : Map<unknown, unknown>;
233 function isMapIterator(object: unknown): boolean;
234 function isModuleNamespaceObject(value: unknown): boolean;
235 function isNativeError(object: unknown): object is Error;
236 function isNumberObject(object: unknown): object is Number;
237 function isPromise(object: unknown): object is Promise<unknown>;
238 function isProxy(object: unknown): boolean;
239 function isRegExp(object: unknown): object is RegExp;
240 function isSet<T>(
241 object: T | {},
242 ): object is T extends ReadonlySet<any>
243 ? unknown extends T
244 ? never
245 : ReadonlySet<any>
246 : Set<unknown>;
247 function isSetIterator(object: unknown): boolean;
248 function isSharedArrayBuffer(object: unknown): object is SharedArrayBuffer;
249 function isStringObject(object: unknown): object is String;
250 function isSymbolObject(object: unknown): object is Symbol;
251 function isTypedArray(object: unknown): object is NodeJS.TypedArray;
252 function isUint8Array(object: unknown): object is Uint8Array;
253 function isUint8ClampedArray(object: unknown): object is Uint8ClampedArray;
254 function isUint16Array(object: unknown): object is Uint16Array;
255 function isUint32Array(object: unknown): object is Uint32Array;
256 function isWeakMap(object: unknown): object is WeakMap<object, unknown>;
257 function isWeakSet(object: unknown): object is WeakSet<object>;
258 function isKeyObject(object: unknown): object is KeyObject;
259 function isCryptoKey(object: unknown): object is webcrypto.CryptoKey;
260}
261
262declare module 'node:util/types' {
263 export * from 'util/types';
264}