UNPKG

11.3 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 a third party module instead. */
6 function log(string: string): void;
7 function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
8 function inspect(object: any, options: InspectOptions): string;
9 namespace inspect {
10 let colors: {
11 [color: string]: [number, number] | undefined
12 };
13 let styles: {
14 [style: string]: string | undefined
15 };
16 let defaultOptions: InspectOptions;
17 /**
18 * Allows changing inspect settings from the repl.
19 */
20 let replDefaults: InspectOptions;
21 }
22 /** @deprecated since v4.0.0 - use `Array.isArray()` instead. */
23 function isArray(object: any): object is any[];
24 /** @deprecated since v4.0.0 - use `util.types.isRegExp()` instead. */
25 function isRegExp(object: any): object is RegExp;
26 /** @deprecated since v4.0.0 - use `util.types.isDate()` instead. */
27 function isDate(object: any): object is Date;
28 /** @deprecated since v4.0.0 - use `util.types.isNativeError()` instead. */
29 function isError(object: any): object is Error;
30 function inherits(constructor: any, superConstructor: any): void;
31 function debuglog(key: string): (msg: string, ...param: any[]) => void;
32 /** @deprecated since v4.0.0 - use `typeof value === 'boolean'` instead. */
33 function isBoolean(object: any): object is boolean;
34 /** @deprecated since v4.0.0 - use `Buffer.isBuffer()` instead. */
35 function isBuffer(object: any): object is Buffer;
36 /** @deprecated since v4.0.0 - use `typeof value === 'function'` instead. */
37 function isFunction(object: any): boolean;
38 /** @deprecated since v4.0.0 - use `value === null` instead. */
39 function isNull(object: any): object is null;
40 /** @deprecated since v4.0.0 - use `value === null || value === undefined` instead. */
41 function isNullOrUndefined(object: any): object is null | undefined;
42 /** @deprecated since v4.0.0 - use `typeof value === 'number'` instead. */
43 function isNumber(object: any): object is number;
44 /** @deprecated since v4.0.0 - use `value !== null && typeof value === 'object'` instead. */
45 function isObject(object: any): boolean;
46 /** @deprecated since v4.0.0 - use `(typeof value !== 'object' && typeof value !== 'function') || value === null` instead. */
47 function isPrimitive(object: any): boolean;
48 /** @deprecated since v4.0.0 - use `typeof value === 'string'` instead. */
49 function isString(object: any): object is string;
50 /** @deprecated since v4.0.0 - use `typeof value === 'symbol'` instead. */
51 function isSymbol(object: any): object is symbol;
52 /** @deprecated since v4.0.0 - use `value === undefined` instead. */
53 function isUndefined(object: any): object is undefined;
54 function deprecate<T extends Function>(fn: T, message: string): T;
55 function isDeepStrictEqual(val1: any, val2: any): boolean;
56
57 interface CustomPromisify<TCustom extends Function> extends Function {
58 __promisify__: TCustom;
59 }
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 function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
87 function promisify<TResult>(fn: (callback: (err: Error | null, result: TResult) => void) => void): () => Promise<TResult>;
88 function promisify(fn: (callback: (err?: Error | null) => void) => void): () => Promise<void>;
89 function promisify<T1, TResult>(fn: (arg1: T1, callback: (err: Error | null, result: TResult) => void) => void): (arg1: T1) => Promise<TResult>;
90 function promisify<T1>(fn: (arg1: T1, callback: (err?: Error | null) => void) => void): (arg1: T1) => Promise<void>;
91 function promisify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2, callback: (err: Error | null, result: TResult) => void) => void): (arg1: T1, arg2: T2) => Promise<TResult>;
92 function promisify<T1, T2>(fn: (arg1: T1, arg2: T2, callback: (err?: Error | null) => void) => void): (arg1: T1, arg2: T2) => Promise<void>;
93 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>;
94 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>;
95 function promisify<T1, T2, T3, T4, TResult>(
96 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: Error | null, result: TResult) => void) => void,
97 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
98 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>;
99 function promisify<T1, T2, T3, T4, T5, TResult>(
100 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: Error | null, result: TResult) => void) => void,
101 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
102 function promisify<T1, T2, T3, T4, T5>(
103 fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: Error | null) => void) => void,
104 ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
105 function promisify(fn: Function): Function;
106
107 namespace types {
108 function isAnyArrayBuffer(object: any): boolean;
109 function isArgumentsObject(object: any): object is IArguments;
110 function isArrayBuffer(object: any): object is ArrayBuffer;
111 function isAsyncFunction(object: any): boolean;
112 function isBooleanObject(object: any): object is Boolean;
113 function isBoxedPrimitive(object: any): object is (Number | Boolean | String | Symbol /* | Object(BigInt) | Object(Symbol) */);
114 function isDataView(object: any): object is DataView;
115 function isDate(object: any): object is Date;
116 function isExternal(object: any): boolean;
117 function isFloat32Array(object: any): object is Float32Array;
118 function isFloat64Array(object: any): object is Float64Array;
119 function isGeneratorFunction(object: any): boolean;
120 function isGeneratorObject(object: any): boolean;
121 function isInt8Array(object: any): object is Int8Array;
122 function isInt16Array(object: any): object is Int16Array;
123 function isInt32Array(object: any): object is Int32Array;
124 function isMap(object: any): boolean;
125 function isMapIterator(object: any): boolean;
126 function isModuleNamespaceObject(value: any): boolean;
127 function isNativeError(object: any): object is Error;
128 function isNumberObject(object: any): object is Number;
129 function isPromise(object: any): boolean;
130 function isProxy(object: any): boolean;
131 function isRegExp(object: any): object is RegExp;
132 function isSet(object: any): boolean;
133 function isSetIterator(object: any): boolean;
134 function isSharedArrayBuffer(object: any): boolean;
135 function isStringObject(object: any): boolean;
136 function isSymbolObject(object: any): boolean;
137 function isTypedArray(object: any): object is NodeJS.TypedArray;
138 function isUint8Array(object: any): object is Uint8Array;
139 function isUint8ClampedArray(object: any): object is Uint8ClampedArray;
140 function isUint16Array(object: any): object is Uint16Array;
141 function isUint32Array(object: any): object is Uint32Array;
142 function isWeakMap(object: any): boolean;
143 function isWeakSet(object: any): boolean;
144 function isWebAssemblyCompiledModule(object: any): boolean;
145 }
146
147 class TextDecoder {
148 readonly encoding: string;
149 readonly fatal: boolean;
150 readonly ignoreBOM: boolean;
151 constructor(
152 encoding?: string,
153 options?: { fatal?: boolean; ignoreBOM?: boolean }
154 );
155 decode(
156 input?: NodeJS.TypedArray | DataView | ArrayBuffer | null,
157 options?: { stream?: boolean }
158 ): string;
159 }
160
161 class TextEncoder {
162 readonly encoding: string;
163 encode(input?: string): Uint8Array;
164 }
165}