UNPKG

11.9 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: string, ...param: any[]): string;
10 /** @deprecated since v0.11.3 - use a third party module instead. */
11 function log(string: string): void;
12 function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
13 function inspect(object: any, options: InspectOptions): string;
14 namespace inspect {
15 let colors: {
16 [color: string]: [number, number] | undefined
17 };
18 let styles: {
19 [K in Style]: string
20 };
21 let defaultOptions: InspectOptions;
22 /**
23 * Allows changing inspect settings from the repl.
24 */
25 let replDefaults: InspectOptions;
26 const custom: unique symbol;
27 }
28 /** @deprecated since v4.0.0 - use `Array.isArray()` instead. */
29 function isArray(object: any): object is any[];
30 /** @deprecated since v4.0.0 - use `util.types.isRegExp()` instead. */
31 function isRegExp(object: any): object is RegExp;
32 /** @deprecated since v4.0.0 - use `util.types.isDate()` instead. */
33 function isDate(object: any): object is Date;
34 /** @deprecated since v4.0.0 - use `util.types.isNativeError()` instead. */
35 function isError(object: any): object is Error;
36 function inherits(constructor: any, superConstructor: any): void;
37 function debuglog(key: string): (msg: string, ...param: any[]) => void;
38 /** @deprecated since v4.0.0 - use `typeof value === 'boolean'` instead. */
39 function isBoolean(object: any): object is boolean;
40 /** @deprecated since v4.0.0 - use `Buffer.isBuffer()` instead. */
41 function isBuffer(object: any): object is Buffer;
42 /** @deprecated since v4.0.0 - use `typeof value === 'function'` instead. */
43 function isFunction(object: any): boolean;
44 /** @deprecated since v4.0.0 - use `value === null` instead. */
45 function isNull(object: any): object is null;
46 /** @deprecated since v4.0.0 - use `value === null || value === undefined` instead. */
47 function isNullOrUndefined(object: any): object is null | undefined;
48 /** @deprecated since v4.0.0 - use `typeof value === 'number'` instead. */
49 function isNumber(object: any): object is number;
50 /** @deprecated since v4.0.0 - use `value !== null && typeof value === 'object'` instead. */
51 function isObject(object: any): boolean;
52 /** @deprecated since v4.0.0 - use `(typeof value !== 'object' && typeof value !== 'function') || value === null` instead. */
53 function isPrimitive(object: any): boolean;
54 /** @deprecated since v4.0.0 - use `typeof value === 'string'` instead. */
55 function isString(object: any): object is string;
56 /** @deprecated since v4.0.0 - use `typeof value === 'symbol'` instead. */
57 function isSymbol(object: any): object is symbol;
58 /** @deprecated since v4.0.0 - use `value === undefined` instead. */
59 function isUndefined(object: any): object is undefined;
60 function deprecate<T extends Function>(fn: T, message: string, code?: string): T;
61 function isDeepStrictEqual(val1: any, val2: any): boolean;
62
63 interface CustomPromisify<TCustom extends Function> extends Function {
64 __promisify__: TCustom;
65 }
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 function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
93 function promisify<TResult>(fn: (callback: (err: any, result: TResult) => void) => void): () => Promise<TResult>;
94 function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
95 function promisify<T1, TResult>(fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void): (arg1: T1) => Promise<TResult>;
96 function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
97 function promisify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void): (arg1: T1, arg2: T2) => Promise<TResult>;
98 function promisify<T1, T2>(fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2) => Promise<void>;
99 function promisify<T1, T2, T3, TResult>(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => void) => void):
100 (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>;
101 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>;
102 function promisify<T1, T2, T3, T4, TResult>(
103 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void,
104 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
105 function promisify<T1, T2, T3, T4>(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: any) => void) => void):
106 (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: any, 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?: any) => 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.ArrayBufferView | ArrayBuffer | null,
165 options?: { stream?: boolean }
166 ): string;
167 }
168
169 interface EncodeIntoResult {
170 /**
171 * The read Unicode code units of input.
172 */
173
174 read: number;
175 /**
176 * The written UTF-8 bytes of output.
177 */
178 written: number;
179 }
180
181 class TextEncoder {
182 readonly encoding: string;
183 encode(input?: string): Uint8Array;
184 encodeInto(input: string, output: Uint8Array): EncodeIntoResult;
185 }
186
187 namespace promisify {
188 const custom: unique symbol;
189 }
190}