UNPKG

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