UNPKG

11.7 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 let styles: {
22 [style: string]: string | undefined
23 };
24 let defaultOptions: InspectOptions;
25 /**
26 * Allows changing inspect settings from the repl.
27 */
28 let replDefaults: InspectOptions;
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): T;
63 function isDeepStrictEqual(val1: any, val2: any): boolean;
64
65 interface CustomPromisify<TCustom extends Function> extends Function {
66 __promisify__: TCustom;
67 }
68
69 function callbackify(fn: () => Promise<void>): (callback: (err: NodeJS.ErrnoException) => void) => void;
70 function callbackify<TResult>(fn: () => Promise<TResult>): (callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
71 function callbackify<T1>(fn: (arg1: T1) => Promise<void>): (arg1: T1, callback: (err: NodeJS.ErrnoException) => void) => void;
72 function callbackify<T1, TResult>(fn: (arg1: T1) => Promise<TResult>): (arg1: T1, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
73 function callbackify<T1, T2>(fn: (arg1: T1, arg2: T2) => Promise<void>): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException) => void) => void;
74 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;
75 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;
76 function callbackify<T1, T2, T3, TResult>(
77 fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
78 function callbackify<T1, T2, T3, T4>(
79 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;
80 function callbackify<T1, T2, T3, T4, TResult>(
81 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;
82 function callbackify<T1, T2, T3, T4, T5>(
83 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;
84 function callbackify<T1, T2, T3, T4, T5, TResult>(
85 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>,
86 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
87 function callbackify<T1, T2, T3, T4, T5, T6>(
88 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<void>,
89 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException) => void) => void;
90 function callbackify<T1, T2, T3, T4, T5, T6, TResult>(
91 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<TResult>
92 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
93
94 function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
95 function promisify<TResult>(fn: (callback: (err: Error | null, result: TResult) => void) => void): () => Promise<TResult>;
96 function promisify(fn: (callback: (err?: Error) => void) => void): () => Promise<void>;
97 function promisify<T1, TResult>(fn: (arg1: T1, callback: (err: Error | null, result: TResult) => void) => void): (arg1: T1) => Promise<TResult>;
98 function promisify<T1>(fn: (arg1: T1, callback: (err?: Error) => void) => void): (arg1: T1) => Promise<void>;
99 function promisify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2, callback: (err: Error | null, result: TResult) => void) => void): (arg1: T1, arg2: T2) => Promise<TResult>;
100 function promisify<T1, T2>(fn: (arg1: T1, arg2: T2, callback: (err?: Error) => void) => void): (arg1: T1, arg2: T2) => Promise<void>;
101 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>;
102 function promisify<T1, T2, T3>(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err?: Error) => void) => void): (arg1: T1, arg2: T2, arg3: T3) => Promise<void>;
103 function promisify<T1, T2, T3, T4, TResult>(
104 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: Error | null, result: TResult) => void) => void,
105 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
106 function promisify<T1, T2, T3, T4>(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: Error) => void) => void): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>;
107 function promisify<T1, T2, T3, T4, T5, TResult>(
108 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: Error | null, result: TResult) => void) => void,
109 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
110 function promisify<T1, T2, T3, T4, T5>(
111 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: Error) => void) => void,
112 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
113 function promisify(fn: Function): Function;
114
115 namespace types {
116 function isAnyArrayBuffer(object: any): boolean;
117 function isArgumentsObject(object: any): object is IArguments;
118 function isArrayBuffer(object: any): object is ArrayBuffer;
119 function isAsyncFunction(object: any): boolean;
120 function isBooleanObject(object: any): object is Boolean;
121 function isBoxedPrimitive(object: any): object is (Number | Boolean | String | Symbol /* | Object(BigInt) | Object(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): boolean;
128 function isGeneratorObject(object: any): boolean;
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(object: any): boolean;
133 function isMapIterator(object: any): boolean;
134 function isModuleNamespaceObject(value: any): boolean;
135 function isNativeError(object: any): object is Error;
136 function isNumberObject(object: any): object is Number;
137 function isPromise(object: any): boolean;
138 function isProxy(object: any): boolean;
139 function isRegExp(object: any): object is RegExp;
140 function isSet(object: any): boolean;
141 function isSetIterator(object: any): boolean;
142 function isSharedArrayBuffer(object: any): boolean;
143 function isStringObject(object: any): boolean;
144 function isSymbolObject(object: any): boolean;
145 function isTypedArray(object: any): object is NodeJS.TypedArray;
146 function isUint8Array(object: any): object is Uint8Array;
147 function isUint8ClampedArray(object: any): object is Uint8ClampedArray;
148 function isUint16Array(object: any): object is Uint16Array;
149 function isUint32Array(object: any): object is Uint32Array;
150 function isWeakMap(object: any): boolean;
151 function isWeakSet(object: any): boolean;
152 function isWebAssemblyCompiledModule(object: any): boolean;
153 }
154
155 class TextDecoder {
156 readonly encoding: string;
157 readonly fatal: boolean;
158 readonly ignoreBOM: boolean;
159 constructor(
160 encoding?: string,
161 options?: { fatal?: boolean; ignoreBOM?: boolean }
162 );
163 decode(
164 input?: NodeJS.TypedArray | DataView | ArrayBuffer | null,
165 options?: { stream?: boolean }
166 ): string;
167 }
168
169 class TextEncoder {
170 readonly encoding: string;
171 encode(input?: string): Uint8Array;
172 }
173}