UNPKG

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