UNPKG

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