You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.d.ts 11KB

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