UNPKG

10.3 kBTypeScriptView Raw
1declare module 'util' {
2 import * as types from 'util/types';
3
4 export interface InspectOptions extends NodeJS.InspectOptions { }
5 export type Style = 'special' | 'number' | 'bigint' | 'boolean' | 'undefined' | 'null' | 'string' | 'symbol' | 'date' | 'regexp' | 'module';
6 export type CustomInspectFunction = (depth: number, options: InspectOptionsStylized) => string;
7 export interface InspectOptionsStylized extends InspectOptions {
8 stylize(text: string, styleType: Style): string;
9 }
10 export function format(format?: any, ...param: any[]): string;
11 export function formatWithOptions(inspectOptions: InspectOptions, format?: any, ...param: any[]): string;
12 /** @deprecated since v0.11.3 - use a third party module instead. */
13 export function log(string: string): void;
14 export function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
15 export function inspect(object: any, options: InspectOptions): string;
16 export namespace inspect {
17 let colors: NodeJS.Dict<[number, number]>;
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 export function isArray(object: any): object is any[];
30 /** @deprecated since v4.0.0 - use `util.types.isRegExp()` instead. */
31 export function isRegExp(object: any): object is RegExp;
32 /** @deprecated since v4.0.0 - use `util.types.isDate()` instead. */
33 export function isDate(object: any): object is Date;
34 /** @deprecated since v4.0.0 - use `util.types.isNativeError()` instead. */
35 export function isError(object: any): object is Error;
36 export function inherits(constructor: any, superConstructor: any): void;
37 export function debuglog(key: string): (msg: string, ...param: any[]) => void;
38 /** @deprecated since v4.0.0 - use `typeof value === 'boolean'` instead. */
39 export function isBoolean(object: any): object is boolean;
40 /** @deprecated since v4.0.0 - use `Buffer.isBuffer()` instead. */
41 export function isBuffer(object: any): object is Buffer;
42 /** @deprecated since v4.0.0 - use `typeof value === 'function'` instead. */
43 export function isFunction(object: any): boolean;
44 /** @deprecated since v4.0.0 - use `value === null` instead. */
45 export function isNull(object: any): object is null;
46 /** @deprecated since v4.0.0 - use `value === null || value === undefined` instead. */
47 export function isNullOrUndefined(object: any): object is null | undefined;
48 /** @deprecated since v4.0.0 - use `typeof value === 'number'` instead. */
49 export function isNumber(object: any): object is number;
50 /** @deprecated since v4.0.0 - use `value !== null && typeof value === 'object'` instead. */
51 export function isObject(object: any): boolean;
52 /** @deprecated since v4.0.0 - use `(typeof value !== 'object' && typeof value !== 'function') || value === null` instead. */
53 export function isPrimitive(object: any): boolean;
54 /** @deprecated since v4.0.0 - use `typeof value === 'string'` instead. */
55 export function isString(object: any): object is string;
56 /** @deprecated since v4.0.0 - use `typeof value === 'symbol'` instead. */
57 export function isSymbol(object: any): object is symbol;
58 /** @deprecated since v4.0.0 - use `value === undefined` instead. */
59 export function isUndefined(object: any): object is undefined;
60 export function deprecate<T extends Function>(fn: T, message: string, code?: string): T;
61 export function isDeepStrictEqual(val1: any, val2: any): boolean;
62
63 export function callbackify(fn: () => Promise<void>): (callback: (err: NodeJS.ErrnoException) => void) => void;
64 export function callbackify<TResult>(fn: () => Promise<TResult>): (callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
65 export function callbackify<T1>(fn: (arg1: T1) => Promise<void>): (arg1: T1, callback: (err: NodeJS.ErrnoException) => void) => void;
66 export function callbackify<T1, TResult>(fn: (arg1: T1) => Promise<TResult>): (arg1: T1, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
67 export function callbackify<T1, T2>(fn: (arg1: T1, arg2: T2) => Promise<void>): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException) => void) => void;
68 export 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 export 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 export 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 export 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 export 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 export 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 export 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 export 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 export 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 export interface CustomPromisifyLegacy<TCustom extends Function> extends Function {
89 __promisify__: TCustom;
90 }
91
92 export interface CustomPromisifySymbol<TCustom extends Function> extends Function {
93 [promisify.custom]: TCustom;
94 }
95
96 export type CustomPromisify<TCustom extends Function> = CustomPromisifySymbol<TCustom> | CustomPromisifyLegacy<TCustom>;
97
98 export function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
99 export function promisify<TResult>(fn: (callback: (err: any, result: TResult) => void) => void): () => Promise<TResult>;
100 export function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
101 export function promisify<T1, TResult>(fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void): (arg1: T1) => Promise<TResult>;
102 export function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
103 export function promisify<T1, T2, TResult>(fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void): (arg1: T1, arg2: T2) => Promise<TResult>;
104 export function promisify<T1, T2>(fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void): (arg1: T1, arg2: T2) => Promise<void>;
105 export 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 export 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 export 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 export 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 export 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 export 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 export function promisify(fn: Function): Function;
120 export namespace promisify {
121 const custom: unique symbol;
122 }
123 export class TextDecoder {
124 readonly encoding: string;
125 readonly fatal: boolean;
126 readonly ignoreBOM: boolean;
127 constructor(
128 encoding?: string,
129 options?: { fatal?: boolean; ignoreBOM?: boolean }
130 );
131 decode(
132 input?: NodeJS.ArrayBufferView | ArrayBuffer | null,
133 options?: { stream?: boolean }
134 ): string;
135 }
136
137 export interface EncodeIntoResult {
138 /**
139 * The read Unicode code units of input.
140 */
141
142 read: number;
143 /**
144 * The written UTF-8 bytes of output.
145 */
146 written: number;
147 }
148
149 export { types };
150
151 export class TextEncoder {
152 readonly encoding: string;
153 encode(input?: string): Uint8Array;
154 encodeInto(input: string, output: Uint8Array): EncodeIntoResult;
155 }
156}