UNPKG

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