UNPKG

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