UNPKG

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