UNPKG

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