1// This needs to be global to avoid TS2403 in case lib.dom.d.ts is present in the same build 2interface Console { 3 Console: NodeJS.ConsoleConstructor; 4 /** 5 * A simple assertion test that verifies whether `value` is truthy. 6 * If it is not, an `AssertionError` is thrown. 7 * If provided, the error `message` is formatted using `util.format()` and used as the error message. 8 */ 9 assert(value: any, message?: string, ...optionalParams: any[]): void; 10 /** 11 * When `stdout` is a TTY, calling `console.clear()` will attempt to clear the TTY. 12 * When `stdout` is not a TTY, this method does nothing. 13 */ 14 clear(): void; 15 /** 16 * Maintains an internal counter specific to `label` and outputs to `stdout` the number of times `console.count()` has been called with the given `label`. 17 */ 18 count(label?: string): void; 19 /** 20 * Resets the internal counter specific to `label`. 21 */ 22 countReset(label?: string): void; 23 /** 24 * The `console.debug()` function is an alias for {@link console.log()}. 25 */ 26 debug(message?: any, ...optionalParams: any[]): void; 27 /** 28 * Uses {@link util.inspect()} on `obj` and prints the resulting string to `stdout`. 29 * This function bypasses any custom `inspect()` function defined on `obj`. 30 */ 31 dir(obj: any, options?: NodeJS.InspectOptions): void; 32 /** 33 * This method calls {@link console.log()} passing it the arguments received. Please note that this method does not produce any XML formatting 34 */ 35 dirxml(...data: any[]): void; 36 /** 37 * Prints to `stderr` with newline. 38 */ 39 error(message?: any, ...optionalParams: any[]): void; 40 /** 41 * Increases indentation of subsequent lines by two spaces. 42 * If one or more `label`s are provided, those are printed first without the additional indentation. 43 */ 44 group(...label: any[]): void; 45 /** 46 * The `console.groupCollapsed()` function is an alias for {@link console.group()}. 47 */ 48 groupCollapsed(...label: any[]): void; 49 /** 50 * Decreases indentation of subsequent lines by two spaces. 51 */ 52 groupEnd(): void; 53 /** 54 * The {@link console.info()} function is an alias for {@link console.log()}. 55 */ 56 info(message?: any, ...optionalParams: any[]): void; 57 /** 58 * Prints to `stdout` with newline. 59 */ 60 log(message?: any, ...optionalParams: any[]): void; 61 /** 62 * This method does not display anything unless used in the inspector. 63 * Prints to `stdout` the array `array` formatted as a table. 64 */ 65 table(tabularData: any, properties?: string[]): void; 66 /** 67 * Starts a timer that can be used to compute the duration of an operation. Timers are identified by a unique `label`. 68 */ 69 time(label?: string): void; 70 /** 71 * Stops a timer that was previously started by calling {@link console.time()} and prints the result to `stdout`. 72 */ 73 timeEnd(label?: string): void; 74 /** 75 * For a timer that was previously started by calling {@link console.time()}, prints the elapsed time and other `data` arguments to `stdout`. 76 */ 77 timeLog(label?: string, ...data: any[]): void; 78 /** 79 * Prints to `stderr` the string 'Trace :', followed by the {@link util.format()} formatted message and stack trace to the current position in the code. 80 */ 81 trace(message?: any, ...optionalParams: any[]): void; 82 /** 83 * The {@link console.warn()} function is an alias for {@link console.error()}. 84 */ 85 warn(message?: any, ...optionalParams: any[]): void; 86 87 // --- Inspector mode only --- 88 /** 89 * This method does not display anything unless used in the inspector. 90 * The console.markTimeline() method is the deprecated form of console.timeStamp(). 91 * 92 * @deprecated Use console.timeStamp() instead. 93 */ 94 markTimeline(label?: string): void; 95 /** 96 * This method does not display anything unless used in the inspector. 97 * Starts a JavaScript CPU profile with an optional label. 98 */ 99 profile(label?: string): void; 100 /** 101 * This method does not display anything unless used in the inspector. 102 * Stops the current JavaScript CPU profiling session if one has been started and prints the report to the Profiles panel of the inspector. 103 */ 104 profileEnd(label?: string): void; 105 /** 106 * This method does not display anything unless used in the inspector. 107 * Adds an event with the label `label` to the Timeline panel of the inspector. 108 */ 109 timeStamp(label?: string): void; 110 /** 111 * This method does not display anything unless used in the inspector. 112 * The console.timeline() method is the deprecated form of console.time(). 113 * 114 * @deprecated Use console.time() instead. 115 */ 116 timeline(label?: string): void; 117 /** 118 * This method does not display anything unless used in the inspector. 119 * The console.timelineEnd() method is the deprecated form of console.timeEnd(). 120 * 121 * @deprecated Use console.timeEnd() instead. 122 */ 123 timelineEnd(label?: string): void; 124} 125 126interface Error { 127 stack?: string; 128} 129 130// Declare "static" methods in Error 131interface ErrorConstructor { 132 /** Create .stack property on a target object */ 133 captureStackTrace(targetObject: Object, constructorOpt?: Function): void; 134 135 /** 136 * Optional override for formatting stack traces 137 * 138 * @see https://github.com/v8/v8/wiki/Stack%20Trace%20API#customizing-stack-traces 139 */ 140 prepareStackTrace?: (err: Error, stackTraces: NodeJS.CallSite[]) => any; 141 142 stackTraceLimit: number; 143} 144 145interface SymbolConstructor { 146 readonly observable: symbol; 147} 148 149// Node.js ESNEXT support 150interface String { 151 /** Removes whitespace from the left end of a string. */ 152 trimLeft(): string; 153 /** Removes whitespace from the right end of a string. */ 154 trimRight(): string; 155} 156 157interface ImportMeta { 158 url: string; 159} 160 161/*-----------------------------------------------* 162 * * 163 * GLOBAL * 164 * * 165 ------------------------------------------------*/ 166declare var process: NodeJS.Process; 167declare var console: Console; 168 169declare var __filename: string; 170declare var __dirname: string; 171 172declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timeout; 173declare namespace setTimeout { 174 function __promisify__(ms: number): Promise<void>; 175 function __promisify__<T>(ms: number, value: T): Promise<T>; 176} 177declare function clearTimeout(timeoutId: NodeJS.Timeout): void; 178declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timeout; 179declare function clearInterval(intervalId: NodeJS.Timeout): void; 180declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): NodeJS.Immediate; 181declare namespace setImmediate { 182 function __promisify__(): Promise<void>; 183 function __promisify__<T>(value: T): Promise<T>; 184} 185declare function clearImmediate(immediateId: NodeJS.Immediate): void; 186 187declare function queueMicrotask(callback: () => void): void; 188 189// TODO: change to `type NodeRequireFunction = (id: string) => any;` in next mayor version. 190interface NodeRequireFunction { 191 /* tslint:disable-next-line:callable-types */ 192 (id: string): any; 193} 194 195interface NodeRequireCache { 196 [path: string]: NodeModule; 197} 198 199interface NodeRequire extends NodeRequireFunction { 200 resolve: RequireResolve; 201 cache: NodeRequireCache; 202 /** 203 * @deprecated 204 */ 205 extensions: NodeExtensions; 206 main: NodeModule | undefined; 207} 208 209interface RequireResolve { 210 (id: string, options?: { paths?: string[]; }): string; 211 paths(request: string): string[] | null; 212} 213 214interface NodeExtensions { 215 '.js': (m: NodeModule, filename: string) => any; 216 '.json': (m: NodeModule, filename: string) => any; 217 '.node': (m: NodeModule, filename: string) => any; 218 [ext: string]: (m: NodeModule, filename: string) => any; 219} 220 221declare var require: NodeRequire; 222 223interface NodeModule { 224 exports: any; 225 require: NodeRequireFunction; 226 id: string; 227 filename: string; 228 loaded: boolean; 229 parent: NodeModule | null; 230 children: NodeModule[]; 231 paths: string[]; 232} 233 234declare var module: NodeModule; 235 236// Same as module.exports 237declare var exports: any; 238 239// Buffer class 240type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"; 241 242interface Buffer { 243 constructor: typeof Buffer; 244} 245 246/** 247 * Raw data is stored in instances of the Buffer class. 248 * A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. 249 * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 250 */ 251declare class Buffer extends Uint8Array { 252 /** 253 * Allocates a new buffer containing the given {str}. 254 * 255 * @param str String to store in buffer. 256 * @param encoding encoding to use, optional. Default is 'utf8' 257 * @deprecated since v10.0.0 - Use `Buffer.from(string[, encoding])` instead. 258 */ 259 constructor(str: string, encoding?: BufferEncoding); 260 /** 261 * Allocates a new buffer of {size} octets. 262 * 263 * @param size count of octets to allocate. 264 * @deprecated since v10.0.0 - Use `Buffer.alloc()` instead (also see `Buffer.allocUnsafe()`). 265 */ 266 constructor(size: number); 267 /** 268 * Allocates a new buffer containing the given {array} of octets. 269 * 270 * @param array The octets to store. 271 * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead. 272 */ 273 constructor(array: Uint8Array); 274 /** 275 * Produces a Buffer backed by the same allocated memory as 276 * the given {ArrayBuffer}/{SharedArrayBuffer}. 277 * 278 * 279 * @param arrayBuffer The ArrayBuffer with which to share memory. 280 * @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead. 281 */ 282 constructor(arrayBuffer: ArrayBuffer | SharedArrayBuffer); 283 /** 284 * Allocates a new buffer containing the given {array} of octets. 285 * 286 * @param array The octets to store. 287 * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead. 288 */ 289 constructor(array: any[]); 290 /** 291 * Copies the passed {buffer} data onto a new {Buffer} instance. 292 * 293 * @param buffer The buffer to copy. 294 * @deprecated since v10.0.0 - Use `Buffer.from(buffer)` instead. 295 */ 296 constructor(buffer: Buffer); 297 /** 298 * When passed a reference to the .buffer property of a TypedArray instance, 299 * the newly created Buffer will share the same allocated memory as the TypedArray. 300 * The optional {byteOffset} and {length} arguments specify a memory range 301 * within the {arrayBuffer} that will be shared by the Buffer. 302 * 303 * @param arrayBuffer The .buffer property of any TypedArray or a new ArrayBuffer() 304 */ 305 static from(arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): Buffer; 306 /** 307 * Creates a new Buffer using the passed {data} 308 * @param data data to create a new Buffer 309 */ 310 static from(data: number[]): Buffer; 311 static from(data: Uint8Array): Buffer; 312 /** 313 * Creates a new buffer containing the coerced value of an object 314 * A `TypeError` will be thrown if {obj} has not mentioned methods or is not of other type appropriate for `Buffer.from()` variants. 315 * @param obj An object supporting `Symbol.toPrimitive` or `valueOf()`. 316 */ 317 static from(obj: { valueOf(): string | object } | { [Symbol.toPrimitive](hint: 'string'): string }, byteOffset?: number, length?: number): Buffer; 318 /** 319 * Creates a new Buffer containing the given JavaScript string {str}. 320 * If provided, the {encoding} parameter identifies the character encoding. 321 * If not provided, {encoding} defaults to 'utf8'. 322 */ 323 static from(str: string, encoding?: BufferEncoding): Buffer; 324 /** 325 * Creates a new Buffer using the passed {data} 326 * @param values to create a new Buffer 327 */ 328 static of(...items: number[]): Buffer; 329 /** 330 * Returns true if {obj} is a Buffer 331 * 332 * @param obj object to test. 333 */ 334 static isBuffer(obj: any): obj is Buffer; 335 /** 336 * Returns true if {encoding} is a valid encoding argument. 337 * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 338 * 339 * @param encoding string to test. 340 */ 341 static isEncoding(encoding: string): encoding is BufferEncoding; 342 /** 343 * Gives the actual byte length of a string. encoding defaults to 'utf8'. 344 * This is not the same as String.prototype.length since that returns the number of characters in a string. 345 * 346 * @param string string to test. 347 * @param encoding encoding used to evaluate (defaults to 'utf8') 348 */ 349 static byteLength( 350 string: string | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer, 351 encoding?: BufferEncoding 352 ): number; 353 /** 354 * Returns a buffer which is the result of concatenating all the buffers in the list together. 355 * 356 * If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer. 357 * If the list has exactly one item, then the first item of the list is returned. 358 * If the list has more than one item, then a new Buffer is created. 359 * 360 * @param list An array of Buffer objects to concatenate 361 * @param totalLength Total length of the buffers when concatenated. 362 * If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly. 363 */ 364 static concat(list: Uint8Array[], totalLength?: number): Buffer; 365 /** 366 * The same as buf1.compare(buf2). 367 */ 368 static compare(buf1: Uint8Array, buf2: Uint8Array): number; 369 /** 370 * Allocates a new buffer of {size} octets. 371 * 372 * @param size count of octets to allocate. 373 * @param fill if specified, buffer will be initialized by calling buf.fill(fill). 374 * If parameter is omitted, buffer will be filled with zeros. 375 * @param encoding encoding used for call to buf.fill while initalizing 376 */ 377 static alloc(size: number, fill?: string | Buffer | number, encoding?: BufferEncoding): Buffer; 378 /** 379 * Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents 380 * of the newly created Buffer are unknown and may contain sensitive data. 381 * 382 * @param size count of octets to allocate 383 */ 384 static allocUnsafe(size: number): Buffer; 385 /** 386 * Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents 387 * of the newly created Buffer are unknown and may contain sensitive data. 388 * 389 * @param size count of octets to allocate 390 */ 391 static allocUnsafeSlow(size: number): Buffer; 392 /** 393 * This is the number of bytes used to determine the size of pre-allocated, internal Buffer instances used for pooling. This value may be modified. 394 */ 395 static poolSize: number; 396 397 write(string: string, encoding?: BufferEncoding): number; 398 write(string: string, offset: number, encoding?: BufferEncoding): number; 399 write(string: string, offset: number, length: number, encoding?: BufferEncoding): number; 400 toString(encoding?: string, start?: number, end?: number): string; 401 toJSON(): { type: 'Buffer'; data: number[] }; 402 equals(otherBuffer: Uint8Array): boolean; 403 compare( 404 otherBuffer: Uint8Array, 405 targetStart?: number, 406 targetEnd?: number, 407 sourceStart?: number, 408 sourceEnd?: number 409 ): number; 410 copy(targetBuffer: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; 411 /** 412 * Returns a new `Buffer` that references **the same memory as the original**, but offset and cropped by the start and end indices. 413 * 414 * This method is incompatible with `Uint8Array#slice()`, which returns a copy of the original memory. 415 * 416 * @param begin Where the new `Buffer` will start. Default: `0`. 417 * @param end Where the new `Buffer` will end (not inclusive). Default: `buf.length`. 418 */ 419 slice(begin?: number, end?: number): Buffer; 420 /** 421 * Returns a new `Buffer` that references **the same memory as the original**, but offset and cropped by the start and end indices. 422 * 423 * This method is compatible with `Uint8Array#subarray()`. 424 * 425 * @param begin Where the new `Buffer` will start. Default: `0`. 426 * @param end Where the new `Buffer` will end (not inclusive). Default: `buf.length`. 427 */ 428 subarray(begin?: number, end?: number): Buffer; 429 writeUIntLE(value: number, offset: number, byteLength: number): number; 430 writeUIntBE(value: number, offset: number, byteLength: number): number; 431 writeIntLE(value: number, offset: number, byteLength: number): number; 432 writeIntBE(value: number, offset: number, byteLength: number): number; 433 readUIntLE(offset: number, byteLength: number): number; 434 readUIntBE(offset: number, byteLength: number): number; 435 readIntLE(offset: number, byteLength: number): number; 436 readIntBE(offset: number, byteLength: number): number; 437 readUInt8(offset: number): number; 438 readUInt16LE(offset: number): number; 439 readUInt16BE(offset: number): number; 440 readUInt32LE(offset: number): number; 441 readUInt32BE(offset: number): number; 442 readInt8(offset: number): number; 443 readInt16LE(offset: number): number; 444 readInt16BE(offset: number): number; 445 readInt32LE(offset: number): number; 446 readInt32BE(offset: number): number; 447 readFloatLE(offset: number): number; 448 readFloatBE(offset: number): number; 449 readDoubleLE(offset: number): number; 450 readDoubleBE(offset: number): number; 451 reverse(): this; 452 swap16(): Buffer; 453 swap32(): Buffer; 454 swap64(): Buffer; 455 writeUInt8(value: number, offset: number): number; 456 writeUInt16LE(value: number, offset: number): number; 457 writeUInt16BE(value: number, offset: number): number; 458 writeUInt32LE(value: number, offset: number): number; 459 writeUInt32BE(value: number, offset: number): number; 460 writeInt8(value: number, offset: number): number; 461 writeInt16LE(value: number, offset: number): number; 462 writeInt16BE(value: number, offset: number): number; 463 writeInt32LE(value: number, offset: number): number; 464 writeInt32BE(value: number, offset: number): number; 465 writeFloatLE(value: number, offset: number): number; 466 writeFloatBE(value: number, offset: number): number; 467 writeDoubleLE(value: number, offset: number): number; 468 writeDoubleBE(value: number, offset: number): number; 469 470 fill(value: string | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): this; 471 472 indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number; 473 lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number; 474 entries(): IterableIterator<[number, number]>; 475 includes(value: string | number | Buffer, byteOffset?: number, encoding?: BufferEncoding): boolean; 476 keys(): IterableIterator<number>; 477 values(): IterableIterator<number>; 478} 479 480/*----------------------------------------------* 481* * 482* GLOBAL INTERFACES * 483* * 484*-----------------------------------------------*/ 485declare namespace NodeJS { 486 interface InspectOptions { 487 /** 488 * If set to `true`, getters are going to be 489 * inspected as well. If set to `'get'` only getters without setter are going 490 * to be inspected. If set to `'set'` only getters having a corresponding 491 * setter are going to be inspected. This might cause side effects depending on 492 * the getter function. 493 * @default `false` 494 */ 495 getters?: 'get' | 'set' | boolean; 496 showHidden?: boolean; 497 /** 498 * @default 2 499 */ 500 depth?: number | null; 501 colors?: boolean; 502 customInspect?: boolean; 503 showProxy?: boolean; 504 maxArrayLength?: number | null; 505 breakLength?: number; 506 /** 507 * Setting this to `false` causes each object key 508 * to be displayed on a new line. It will also add new lines to text that is 509 * longer than `breakLength`. If set to a number, the most `n` inner elements 510 * are united on a single line as long as all properties fit into 511 * `breakLength`. Short array elements are also grouped together. Note that no 512 * text will be reduced below 16 characters, no matter the `breakLength` size. 513 * For more information, see the example below. 514 * @default `true` 515 */ 516 compact?: boolean | number; 517 sorted?: boolean | ((a: string, b: string) => number); 518 } 519 520 interface ConsoleConstructorOptions { 521 stdout: WritableStream; 522 stderr?: WritableStream; 523 ignoreErrors?: boolean; 524 colorMode?: boolean | 'auto'; 525 inspectOptions?: InspectOptions; 526 } 527 528 interface ConsoleConstructor { 529 prototype: Console; 530 new(stdout: WritableStream, stderr?: WritableStream, ignoreErrors?: boolean): Console; 531 new(options: ConsoleConstructorOptions): Console; 532 } 533 534 interface CallSite { 535 /** 536 * Value of "this" 537 */ 538 getThis(): any; 539 540 /** 541 * Type of "this" as a string. 542 * This is the name of the function stored in the constructor field of 543 * "this", if available. Otherwise the object's [[Class]] internal 544 * property. 545 */ 546 getTypeName(): string | null; 547 548 /** 549 * Current function 550 */ 551 getFunction(): Function | undefined; 552 553 /** 554 * Name of the current function, typically its name property. 555 * If a name property is not available an attempt will be made to try 556 * to infer a name from the function's context. 557 */ 558 getFunctionName(): string | null; 559 560 /** 561 * Name of the property [of "this" or one of its prototypes] that holds 562 * the current function 563 */ 564 getMethodName(): string | null; 565 566 /** 567 * Name of the script [if this function was defined in a script] 568 */ 569 getFileName(): string | null; 570 571 /** 572 * Current line number [if this function was defined in a script] 573 */ 574 getLineNumber(): number | null; 575 576 /** 577 * Current column number [if this function was defined in a script] 578 */ 579 getColumnNumber(): number | null; 580 581 /** 582 * A call site object representing the location where eval was called 583 * [if this function was created using a call to eval] 584 */ 585 getEvalOrigin(): string | undefined; 586 587 /** 588 * Is this a toplevel invocation, that is, is "this" the global object? 589 */ 590 isToplevel(): boolean; 591 592 /** 593 * Does this call take place in code defined by a call to eval? 594 */ 595 isEval(): boolean; 596 597 /** 598 * Is this call in native V8 code? 599 */ 600 isNative(): boolean; 601 602 /** 603 * Is this a constructor call? 604 */ 605 isConstructor(): boolean; 606 } 607 608 interface ErrnoException extends Error { 609 errno?: number; 610 code?: string; 611 path?: string; 612 syscall?: string; 613 stack?: string; 614 } 615 616 class EventEmitter { 617 addListener(event: string | symbol, listener: (...args: any[]) => void): this; 618 on(event: string | symbol, listener: (...args: any[]) => void): this; 619 once(event: string | symbol, listener: (...args: any[]) => void): this; 620 removeListener(event: string | symbol, listener: (...args: any[]) => void): this; 621 off(event: string | symbol, listener: (...args: any[]) => void): this; 622 removeAllListeners(event?: string | symbol): this; 623 setMaxListeners(n: number): this; 624 getMaxListeners(): number; 625 listeners(event: string | symbol): Function[]; 626 rawListeners(event: string | symbol): Function[]; 627 emit(event: string | symbol, ...args: any[]): boolean; 628 listenerCount(type: string | symbol): number; 629 // Added in Node 6... 630 prependListener(event: string | symbol, listener: (...args: any[]) => void): this; 631 prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; 632 eventNames(): Array<string | symbol>; 633 } 634 635 interface ReadableStream extends EventEmitter { 636 readable: boolean; 637 read(size?: number): string | Buffer; 638 setEncoding(encoding: string): this; 639 pause(): this; 640 resume(): this; 641 isPaused(): boolean; 642 pipe<T extends WritableStream>(destination: T, options?: { end?: boolean; }): T; 643 unpipe(destination?: WritableStream): this; 644 unshift(chunk: string | Uint8Array, encoding?: BufferEncoding): void; 645 wrap(oldStream: ReadableStream): this; 646 [Symbol.asyncIterator](): AsyncIterableIterator<string | Buffer>; 647 } 648 649 interface WritableStream extends EventEmitter { 650 writable: boolean; 651 write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean; 652 write(str: string, encoding?: string, cb?: (err?: Error | null) => void): boolean; 653 end(cb?: () => void): void; 654 end(data: string | Uint8Array, cb?: () => void): void; 655 end(str: string, encoding?: string, cb?: () => void): void; 656 } 657 658 interface ReadWriteStream extends ReadableStream, WritableStream { } 659 660 interface Domain extends EventEmitter { 661 run<T>(fn: (...args: any[]) => T, ...args: any[]): T; 662 add(emitter: EventEmitter | Timer): void; 663 remove(emitter: EventEmitter | Timer): void; 664 bind<T extends Function>(cb: T): T; 665 intercept<T extends Function>(cb: T): T; 666 667 addListener(event: string, listener: (...args: any[]) => void): this; 668 on(event: string, listener: (...args: any[]) => void): this; 669 once(event: string, listener: (...args: any[]) => void): this; 670 removeListener(event: string, listener: (...args: any[]) => void): this; 671 removeAllListeners(event?: string): this; 672 } 673 674 interface MemoryUsage { 675 rss: number; 676 heapTotal: number; 677 heapUsed: number; 678 external: number; 679 } 680 681 interface CpuUsage { 682 user: number; 683 system: number; 684 } 685 686 interface ProcessRelease { 687 name: string; 688 sourceUrl?: string; 689 headersUrl?: string; 690 libUrl?: string; 691 lts?: string; 692 } 693 694 interface ProcessVersions { 695 http_parser: string; 696 node: string; 697 v8: string; 698 ares: string; 699 uv: string; 700 zlib: string; 701 modules: string; 702 openssl: string; 703 } 704 705 type Platform = 'aix' 706 | 'android' 707 | 'darwin' 708 | 'freebsd' 709 | 'linux' 710 | 'openbsd' 711 | 'sunos' 712 | 'win32' 713 | 'cygwin' 714 | 'netbsd'; 715 716 type Signals = 717 "SIGABRT" | "SIGALRM" | "SIGBUS" | "SIGCHLD" | "SIGCONT" | "SIGFPE" | "SIGHUP" | "SIGILL" | "SIGINT" | "SIGIO" | 718 "SIGIOT" | "SIGKILL" | "SIGPIPE" | "SIGPOLL" | "SIGPROF" | "SIGPWR" | "SIGQUIT" | "SIGSEGV" | "SIGSTKFLT" | 719 "SIGSTOP" | "SIGSYS" | "SIGTERM" | "SIGTRAP" | "SIGTSTP" | "SIGTTIN" | "SIGTTOU" | "SIGUNUSED" | "SIGURG" | 720 "SIGUSR1" | "SIGUSR2" | "SIGVTALRM" | "SIGWINCH" | "SIGXCPU" | "SIGXFSZ" | "SIGBREAK" | "SIGLOST" | "SIGINFO"; 721 722 type MultipleResolveType = 'resolve' | 'reject'; 723 724 type BeforeExitListener = (code: number) => void; 725 type DisconnectListener = () => void; 726 type ExitListener = (code: number) => void; 727 type RejectionHandledListener = (promise: Promise<any>) => void; 728 type UncaughtExceptionListener = (error: Error) => void; 729 type UnhandledRejectionListener = (reason: {} | null | undefined, promise: Promise<any>) => void; 730 type WarningListener = (warning: Error) => void; 731 type MessageListener = (message: any, sendHandle: any) => void; 732 type SignalsListener = (signal: Signals) => void; 733 type NewListenerListener = (type: string | symbol, listener: (...args: any[]) => void) => void; 734 type RemoveListenerListener = (type: string | symbol, listener: (...args: any[]) => void) => void; 735 type MultipleResolveListener = (type: MultipleResolveType, promise: Promise<any>, value: any) => void; 736 737 interface Socket extends ReadWriteStream { 738 isTTY?: true; 739 } 740 741 interface ProcessEnv { 742 [key: string]: string | undefined; 743 } 744 745 interface HRTime { 746 (time?: [number, number]): [number, number]; 747 } 748 749 interface ProcessReport { 750 /** 751 * Directory where the report is written. 752 * working directory of the Node.js process. 753 * @default '' indicating that reports are written to the current 754 */ 755 directory: string; 756 757 /** 758 * Filename where the report is written. 759 * The default value is the empty string. 760 * @default '' the output filename will be comprised of a timestamp, 761 * PID, and sequence number. 762 */ 763 filename: string; 764 765 /** 766 * Returns a JSON-formatted diagnostic report for the running process. 767 * The report's JavaScript stack trace is taken from err, if present. 768 */ 769 getReport(err?: Error): string; 770 771 /** 772 * If true, a diagnostic report is generated on fatal errors, 773 * such as out of memory errors or failed C++ assertions. 774 * @default false 775 */ 776 reportOnFatalError: boolean; 777 778 /** 779 * If true, a diagnostic report is generated when the process 780 * receives the signal specified by process.report.signal. 781 * @defaul false 782 */ 783 reportOnSignal: boolean; 784 785 /** 786 * If true, a diagnostic report is generated on uncaught exception. 787 * @default false 788 */ 789 reportOnUncaughtException: boolean; 790 791 /** 792 * The signal used to trigger the creation of a diagnostic report. 793 * @default 'SIGUSR2' 794 */ 795 signal: Signals; 796 797 /** 798 * Writes a diagnostic report to a file. If filename is not provided, the default filename 799 * includes the date, time, PID, and a sequence number. 800 * The report's JavaScript stack trace is taken from err, if present. 801 * 802 * @param fileName Name of the file where the report is written. 803 * This should be a relative path, that will be appended to the directory specified in 804 * `process.report.directory`, or the current working directory of the Node.js process, 805 * if unspecified. 806 * @param error A custom error used for reporting the JavaScript stack. 807 * @return Filename of the generated report. 808 */ 809 writeReport(fileName?: string): string; 810 writeReport(error?: Error): string; 811 writeReport(fileName?: string, err?: Error): string; 812 } 813 814 interface ResourceUsage { 815 fsRead: number; 816 fsWrite: number; 817 involuntaryContextSwitches: number; 818 ipcReceived: number; 819 ipcSent: number; 820 majorPageFault: number; 821 maxRSS: number; 822 minorPageFault: number; 823 sharedMemorySize: number; 824 signalsCount: number; 825 swappedOut: number; 826 systemCPUTime: number; 827 unsharedDataSize: number; 828 unsharedStackSize: number; 829 userCPUTime: number; 830 voluntaryContextSwitches: number; 831 } 832 833 interface Process extends EventEmitter { 834 /** 835 * Can also be a tty.WriteStream, not typed due to limitation.s 836 */ 837 stdout: WriteStream; 838 /** 839 * Can also be a tty.WriteStream, not typed due to limitation.s 840 */ 841 stderr: WriteStream; 842 stdin: ReadStream; 843 openStdin(): Socket; 844 argv: string[]; 845 argv0: string; 846 execArgv: string[]; 847 execPath: string; 848 abort(): void; 849 chdir(directory: string): void; 850 cwd(): string; 851 debugPort: number; 852 emitWarning(warning: string | Error, name?: string, ctor?: Function): void; 853 env: ProcessEnv; 854 exit(code?: number): never; 855 exitCode?: number; 856 getgid(): number; 857 setgid(id: number | string): void; 858 getuid(): number; 859 setuid(id: number | string): void; 860 geteuid(): number; 861 seteuid(id: number | string): void; 862 getegid(): number; 863 setegid(id: number | string): void; 864 getgroups(): number[]; 865 setgroups(groups: Array<string | number>): void; 866 setUncaughtExceptionCaptureCallback(cb: ((err: Error) => void) | null): void; 867 hasUncaughtExceptionCaptureCallback(): boolean; 868 version: string; 869 versions: ProcessVersions; 870 config: { 871 target_defaults: { 872 cflags: any[]; 873 default_configuration: string; 874 defines: string[]; 875 include_dirs: string[]; 876 libraries: string[]; 877 }; 878 variables: { 879 clang: number; 880 host_arch: string; 881 node_install_npm: boolean; 882 node_install_waf: boolean; 883 node_prefix: string; 884 node_shared_openssl: boolean; 885 node_shared_v8: boolean; 886 node_shared_zlib: boolean; 887 node_use_dtrace: boolean; 888 node_use_etw: boolean; 889 node_use_openssl: boolean; 890 target_arch: string; 891 v8_no_strict_aliasing: number; 892 v8_use_snapshot: boolean; 893 visibility: string; 894 }; 895 }; 896 kill(pid: number, signal?: string | number): void; 897 pid: number; 898 ppid: number; 899 title: string; 900 arch: string; 901 platform: Platform; 902 mainModule?: NodeModule; 903 memoryUsage(): MemoryUsage; 904 cpuUsage(previousValue?: CpuUsage): CpuUsage; 905 nextTick(callback: Function, ...args: any[]): void; 906 release: ProcessRelease; 907 features: { 908 inspector: boolean; 909 debug: boolean; 910 uv: boolean; 911 ipv6: boolean; 912 tls_alpn: boolean; 913 tls_sni: boolean; 914 tls_ocsp: boolean; 915 tls: boolean; 916 }; 917 /** 918 * Can only be set if not in worker thread. 919 */ 920 umask(mask?: number): number; 921 uptime(): number; 922 hrtime: HRTime; 923 domain: Domain; 924 925 // Worker 926 send?(message: any, sendHandle?: any, options?: { swallowErrors?: boolean}, callback?: (error: Error | null) => void): boolean; 927 disconnect(): void; 928 connected: boolean; 929 930 /** 931 * The `process.allowedNodeEnvironmentFlags` property is a special, 932 * read-only `Set` of flags allowable within the [`NODE_OPTIONS`][] 933 * environment variable. 934 */ 935 allowedNodeEnvironmentFlags: ReadonlySet<string>; 936 937 /** 938 * Only available with `--experimental-report` 939 */ 940 report?: ProcessReport; 941 942 resourceUsage(): ResourceUsage; 943 944 /** 945 * EventEmitter 946 * 1. beforeExit 947 * 2. disconnect 948 * 3. exit 949 * 4. message 950 * 5. rejectionHandled 951 * 6. uncaughtException 952 * 7. unhandledRejection 953 * 8. warning 954 * 9. message 955 * 10. <All OS Signals> 956 * 11. newListener/removeListener inherited from EventEmitter 957 */ 958 addListener(event: "beforeExit", listener: BeforeExitListener): this; 959 addListener(event: "disconnect", listener: DisconnectListener): this; 960 addListener(event: "exit", listener: ExitListener): this; 961 addListener(event: "rejectionHandled", listener: RejectionHandledListener): this; 962 addListener(event: "uncaughtException", listener: UncaughtExceptionListener): this; 963 addListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this; 964 addListener(event: "warning", listener: WarningListener): this; 965 addListener(event: "message", listener: MessageListener): this; 966 addListener(event: Signals, listener: SignalsListener): this; 967 addListener(event: "newListener", listener: NewListenerListener): this; 968 addListener(event: "removeListener", listener: RemoveListenerListener): this; 969 addListener(event: "multipleResolves", listener: MultipleResolveListener): this; 970 971 emit(event: "beforeExit", code: number): boolean; 972 emit(event: "disconnect"): boolean; 973 emit(event: "exit", code: number): boolean; 974 emit(event: "rejectionHandled", promise: Promise<any>): boolean; 975 emit(event: "uncaughtException", error: Error): boolean; 976 emit(event: "unhandledRejection", reason: any, promise: Promise<any>): boolean; 977 emit(event: "warning", warning: Error): boolean; 978 emit(event: "message", message: any, sendHandle: any): this; 979 emit(event: Signals, signal: Signals): boolean; 980 emit(event: "newListener", eventName: string | symbol, listener: (...args: any[]) => void): this; 981 emit(event: "removeListener", eventName: string, listener: (...args: any[]) => void): this; 982 emit(event: "multipleResolves", listener: MultipleResolveListener): this; 983 984 on(event: "beforeExit", listener: BeforeExitListener): this; 985 on(event: "disconnect", listener: DisconnectListener): this; 986 on(event: "exit", listener: ExitListener): this; 987 on(event: "rejectionHandled", listener: RejectionHandledListener): this; 988 on(event: "uncaughtException", listener: UncaughtExceptionListener): this; 989 on(event: "unhandledRejection", listener: UnhandledRejectionListener): this; 990 on(event: "warning", listener: WarningListener): this; 991 on(event: "message", listener: MessageListener): this; 992 on(event: Signals, listener: SignalsListener): this; 993 on(event: "newListener", listener: NewListenerListener): this; 994 on(event: "removeListener", listener: RemoveListenerListener): this; 995 on(event: "multipleResolves", listener: MultipleResolveListener): this; 996 997 once(event: "beforeExit", listener: BeforeExitListener): this; 998 once(event: "disconnect", listener: DisconnectListener): this; 999 once(event: "exit", listener: ExitListener): this; 1000 once(event: "rejectionHandled", listener: RejectionHandledListener): this; 1001 once(event: "uncaughtException", listener: UncaughtExceptionListener): this; 1002 once(event: "unhandledRejection", listener: UnhandledRejectionListener): this; 1003 once(event: "warning", listener: WarningListener): this; 1004 once(event: "message", listener: MessageListener): this; 1005 once(event: Signals, listener: SignalsListener): this; 1006 once(event: "newListener", listener: NewListenerListener): this; 1007 once(event: "removeListener", listener: RemoveListenerListener): this; 1008 once(event: "multipleResolves", listener: MultipleResolveListener): this; 1009 1010 prependListener(event: "beforeExit", listener: BeforeExitListener): this; 1011 prependListener(event: "disconnect", listener: DisconnectListener): this; 1012 prependListener(event: "exit", listener: ExitListener): this; 1013 prependListener(event: "rejectionHandled", listener: RejectionHandledListener): this; 1014 prependListener(event: "uncaughtException", listener: UncaughtExceptionListener): this; 1015 prependListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this; 1016 prependListener(event: "warning", listener: WarningListener): this; 1017 prependListener(event: "message", listener: MessageListener): this; 1018 prependListener(event: Signals, listener: SignalsListener): this; 1019 prependListener(event: "newListener", listener: NewListenerListener): this; 1020 prependListener(event: "removeListener", listener: RemoveListenerListener): this; 1021 prependListener(event: "multipleResolves", listener: MultipleResolveListener): this; 1022 1023 prependOnceListener(event: "beforeExit", listener: BeforeExitListener): this; 1024 prependOnceListener(event: "disconnect", listener: DisconnectListener): this; 1025 prependOnceListener(event: "exit", listener: ExitListener): this; 1026 prependOnceListener(event: "rejectionHandled", listener: RejectionHandledListener): this; 1027 prependOnceListener(event: "uncaughtException", listener: UncaughtExceptionListener): this; 1028 prependOnceListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this; 1029 prependOnceListener(event: "warning", listener: WarningListener): this; 1030 prependOnceListener(event: "message", listener: MessageListener): this; 1031 prependOnceListener(event: Signals, listener: SignalsListener): this; 1032 prependOnceListener(event: "newListener", listener: NewListenerListener): this; 1033 prependOnceListener(event: "removeListener", listener: RemoveListenerListener): this; 1034 prependOnceListener(event: "multipleResolves", listener: MultipleResolveListener): this; 1035 1036 listeners(event: "beforeExit"): BeforeExitListener[]; 1037 listeners(event: "disconnect"): DisconnectListener[]; 1038 listeners(event: "exit"): ExitListener[]; 1039 listeners(event: "rejectionHandled"): RejectionHandledListener[]; 1040 listeners(event: "uncaughtException"): UncaughtExceptionListener[]; 1041 listeners(event: "unhandledRejection"): UnhandledRejectionListener[]; 1042 listeners(event: "warning"): WarningListener[]; 1043 listeners(event: "message"): MessageListener[]; 1044 listeners(event: Signals): SignalsListener[]; 1045 listeners(event: "newListener"): NewListenerListener[]; 1046 listeners(event: "removeListener"): RemoveListenerListener[]; 1047 listeners(event: "multipleResolves"): MultipleResolveListener[]; 1048 } 1049 1050 interface Global { 1051 Array: typeof Array; 1052 ArrayBuffer: typeof ArrayBuffer; 1053 Boolean: typeof Boolean; 1054 Buffer: typeof Buffer; 1055 DataView: typeof DataView; 1056 Date: typeof Date; 1057 Error: typeof Error; 1058 EvalError: typeof EvalError; 1059 Float32Array: typeof Float32Array; 1060 Float64Array: typeof Float64Array; 1061 Function: typeof Function; 1062 GLOBAL: Global; 1063 Infinity: typeof Infinity; 1064 Int16Array: typeof Int16Array; 1065 Int32Array: typeof Int32Array; 1066 Int8Array: typeof Int8Array; 1067 Intl: typeof Intl; 1068 JSON: typeof JSON; 1069 Map: MapConstructor; 1070 Math: typeof Math; 1071 NaN: typeof NaN; 1072 Number: typeof Number; 1073 Object: typeof Object; 1074 Promise: Function; 1075 RangeError: typeof RangeError; 1076 ReferenceError: typeof ReferenceError; 1077 RegExp: typeof RegExp; 1078 Set: SetConstructor; 1079 String: typeof String; 1080 Symbol: Function; 1081 SyntaxError: typeof SyntaxError; 1082 TypeError: typeof TypeError; 1083 URIError: typeof URIError; 1084 Uint16Array: typeof Uint16Array; 1085 Uint32Array: typeof Uint32Array; 1086 Uint8Array: typeof Uint8Array; 1087 Uint8ClampedArray: Function; 1088 WeakMap: WeakMapConstructor; 1089 WeakSet: WeakSetConstructor; 1090 clearImmediate: (immediateId: Immediate) => void; 1091 clearInterval: (intervalId: Timeout) => void; 1092 clearTimeout: (timeoutId: Timeout) => void; 1093 console: typeof console; 1094 decodeURI: typeof decodeURI; 1095 decodeURIComponent: typeof decodeURIComponent; 1096 encodeURI: typeof encodeURI; 1097 encodeURIComponent: typeof encodeURIComponent; 1098 escape: (str: string) => string; 1099 eval: typeof eval; 1100 global: Global; 1101 isFinite: typeof isFinite; 1102 isNaN: typeof isNaN; 1103 parseFloat: typeof parseFloat; 1104 parseInt: typeof parseInt; 1105 process: Process; 1106 root: Global; 1107 setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => Immediate; 1108 setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => Timeout; 1109 setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => Timeout; 1110 queueMicrotask: typeof queueMicrotask; 1111 undefined: typeof undefined; 1112 unescape: (str: string) => string; 1113 gc: () => void; 1114 v8debug?: any; 1115 } 1116 1117 // compatibility with older typings 1118 interface Timer { 1119 hasRef(): boolean; 1120 ref(): this; 1121 refresh(): this; 1122 unref(): this; 1123 } 1124 1125 class Immediate { 1126 hasRef(): boolean; 1127 ref(): this; 1128 unref(): this; 1129 _onImmediate: Function; // to distinguish it from the Timeout class 1130 } 1131 1132 class Timeout implements Timer { 1133 hasRef(): boolean; 1134 ref(): this; 1135 refresh(): this; 1136 unref(): this; 1137 } 1138 1139 class Module { 1140 static runMain(): void; 1141 static wrap(code: string): string; 1142 1143 /** 1144 * @deprecated Deprecated since: v12.2.0. Please use createRequire() instead. 1145 */ 1146 static createRequireFromPath(path: string): NodeRequire; 1147 static createRequire(path: string): NodeRequire; 1148 static builtinModules: string[]; 1149 1150 static Module: typeof Module; 1151 1152 exports: any; 1153 require: NodeRequireFunction; 1154 id: string; 1155 filename: string; 1156 loaded: boolean; 1157 parent: Module | null; 1158 children: Module[]; 1159 paths: string[]; 1160 1161 constructor(id: string, parent?: Module); 1162 } 1163 1164 type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array; 1165 type ArrayBufferView = TypedArray | DataView; 1166 1167 // The value type here is a "poor man's `unknown`". When these types support TypeScript 1168 // 3.0+, we can replace this with `unknown`. 1169 type PoorMansUnknown = {} | null | undefined; 1170} 1171