UNPKG

12.2 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 function callbackify(fn: () => Promise<void>): (callback: (err: NodeJS.ErrnoException) => void) => void;
64 function callbackify<TResult>(fn: () => Promise<TResult>): (callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
65 function callbackify<T1>(fn: (arg1: T1) => Promise<void>): (arg1: T1, callback: (err: NodeJS.ErrnoException) => void) => void;
66 function callbackify<T1, TResult>(fn: (arg1: T1) => Promise<TResult>): (arg1: T1, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
67 function callbackify<T1, T2>(fn: (arg1: T1, arg2: T2) => Promise<void>): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException) => void) => void;
68 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;
69 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;
70 function callbackify<T1, T2, T3, TResult>(
71 fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
72 function callbackify<T1, T2, T3, T4>(
73 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;
74 function callbackify<T1, T2, T3, T4, TResult>(
75 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;
76 function callbackify<T1, T2, T3, T4, T5>(
77 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;
78 function callbackify<T1, T2, T3, T4, T5, TResult>(
79 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>,
80 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
81 function callbackify<T1, T2, T3, T4, T5, T6>(
82 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<void>,
83 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException) => void) => void;
84 function callbackify<T1, T2, T3, T4, T5, T6, TResult>(
85 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<TResult>
86 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
87
88 interface CustomPromisifyLegacy<TCustom extends Function> extends Function {
89 __promisify__: TCustom;
90 }
91
92 interface CustomPromisifySymbol<TCustom extends Function> extends Function {
93 [promisify.custom]: TCustom;
94 }
95
96 type CustomPromisify<TCustom extends Function> = CustomPromisifySymbol<TCustom> | CustomPromisifyLegacy<TCustom>;
97
98 function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
99 function promisify<TResult>(fn: (callback: (err: any, result: TResult) => void) => void): () => Promise<TResult>;
100 function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
101 function promisify<T1, TResult>(fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void): (arg1: T1) => Promise<TResult>;
102 function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
103 function promisify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void): (arg1: T1, arg2: T2) => Promise<TResult>;
104 function promisify<T1, T2>(fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2) => Promise<void>;
105 function promisify<T1, T2, T3, TResult>(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => void) => void):
106 (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>;
107 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>;
108 function promisify<T1, T2, T3, T4, TResult>(
109 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void,
110 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
111 function promisify<T1, T2, T3, T4>(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: any) => void) => void):
112 (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>;
113 function promisify<T1, T2, T3, T4, T5, TResult>(
114 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => void) => void,
115 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
116 function promisify<T1, T2, T3, T4, T5>(
117 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void,
118 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
119 function promisify(fn: Function): Function;
120 namespace promisify {
121 const custom: unique symbol;
122 }
123
124 namespace types {
125 function isAnyArrayBuffer(object: any): boolean;
126 function isArgumentsObject(object: any): object is IArguments;
127 function isArrayBuffer(object: any): object is ArrayBuffer;
128 function isAsyncFunction(object: any): boolean;
129 function isBooleanObject(object: any): object is Boolean;
130 function isBoxedPrimitive(object: any): object is (Number | Boolean | String | Symbol /* | Object(BigInt) | Object(Symbol) */);
131 function isDataView(object: any): object is DataView;
132 function isDate(object: any): object is Date;
133 function isExternal(object: any): boolean;
134 function isFloat32Array(object: any): object is Float32Array;
135 function isFloat64Array(object: any): object is Float64Array;
136 function isGeneratorFunction(object: any): boolean;
137 function isGeneratorObject(object: any): boolean;
138 function isInt8Array(object: any): object is Int8Array;
139 function isInt16Array(object: any): object is Int16Array;
140 function isInt32Array(object: any): object is Int32Array;
141 function isMap(object: any): boolean;
142 function isMapIterator(object: any): boolean;
143 function isModuleNamespaceObject(value: any): boolean;
144 function isNativeError(object: any): object is Error;
145 function isNumberObject(object: any): object is Number;
146 function isPromise(object: any): boolean;
147 function isProxy(object: any): boolean;
148 function isRegExp(object: any): object is RegExp;
149 function isSet(object: any): boolean;
150 function isSetIterator(object: any): boolean;
151 function isSharedArrayBuffer(object: any): boolean;
152 function isStringObject(object: any): boolean;
153 function isSymbolObject(object: any): boolean;
154 function isTypedArray(object: any): object is NodeJS.TypedArray;
155 function isUint8Array(object: any): object is Uint8Array;
156 function isUint8ClampedArray(object: any): object is Uint8ClampedArray;
157 function isUint16Array(object: any): object is Uint16Array;
158 function isUint32Array(object: any): object is Uint32Array;
159 function isWeakMap(object: any): boolean;
160 function isWeakSet(object: any): boolean;
161 function isWebAssemblyCompiledModule(object: any): boolean;
162 }
163
164 class TextDecoder {
165 readonly encoding: string;
166 readonly fatal: boolean;
167 readonly ignoreBOM: boolean;
168 constructor(
169 encoding?: string,
170 options?: { fatal?: boolean; ignoreBOM?: boolean }
171 );
172 decode(
173 input?: NodeJS.ArrayBufferView | ArrayBuffer | null,
174 options?: { stream?: boolean }
175 ): string;
176 }
177
178 interface EncodeIntoResult {
179 /**
180 * The read Unicode code units of input.
181 */
182
183 read: number;
184 /**
185 * The written UTF-8 bytes of output.
186 */
187 written: number;
188 }
189
190 class TextEncoder {
191 readonly encoding: string;
192 encode(input?: string): Uint8Array;
193 encodeInto(input: string, output: Uint8Array): EncodeIntoResult;
194 }
195}