UNPKG

45 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?: string, 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 breakLength?: number;
436 /**
437 * Setting this to `false` causes each object key
438 * to be displayed on a new line. It will also add new lines to text that is
439 * longer than `breakLength`. If set to a number, the most `n` inner elements
440 * are united on a single line as long as all properties fit into
441 * `breakLength`. Short array elements are also grouped together. Note that no
442 * text will be reduced below 16 characters, no matter the `breakLength` size.
443 * For more information, see the example below.
444 * @default `true`
445 */
446 compact?: boolean | number;
447 sorted?: boolean | ((a: string, b: string) => number);
448 }
449
450 interface ConsoleConstructorOptions {
451 stdout: WritableStream;
452 stderr?: WritableStream;
453 ignoreErrors?: boolean;
454 colorMode?: boolean | 'auto';
455 inspectOptions?: InspectOptions;
456 }
457
458 interface ConsoleConstructor {
459 prototype: Console;
460 new(stdout: WritableStream, stderr?: WritableStream, ignoreErrors?: boolean): Console;
461 new(options: ConsoleConstructorOptions): Console;
462 }
463
464 interface CallSite {
465 /**
466 * Value of "this"
467 */
468 getThis(): any;
469
470 /**
471 * Type of "this" as a string.
472 * This is the name of the function stored in the constructor field of
473 * "this", if available. Otherwise the object's [[Class]] internal
474 * property.
475 */
476 getTypeName(): string | null;
477
478 /**
479 * Current function
480 */
481 getFunction(): Function | undefined;
482
483 /**
484 * Name of the current function, typically its name property.
485 * If a name property is not available an attempt will be made to try
486 * to infer a name from the function's context.
487 */
488 getFunctionName(): string | null;
489
490 /**
491 * Name of the property [of "this" or one of its prototypes] that holds
492 * the current function
493 */
494 getMethodName(): string | null;
495
496 /**
497 * Name of the script [if this function was defined in a script]
498 */
499 getFileName(): string | null;
500
501 /**
502 * Current line number [if this function was defined in a script]
503 */
504 getLineNumber(): number | null;
505
506 /**
507 * Current column number [if this function was defined in a script]
508 */
509 getColumnNumber(): number | null;
510
511 /**
512 * A call site object representing the location where eval was called
513 * [if this function was created using a call to eval]
514 */
515 getEvalOrigin(): string | undefined;
516
517 /**
518 * Is this a toplevel invocation, that is, is "this" the global object?
519 */
520 isToplevel(): boolean;
521
522 /**
523 * Does this call take place in code defined by a call to eval?
524 */
525 isEval(): boolean;
526
527 /**
528 * Is this call in native V8 code?
529 */
530 isNative(): boolean;
531
532 /**
533 * Is this a constructor call?
534 */
535 isConstructor(): boolean;
536 }
537
538 interface ErrnoException extends Error {
539 errno?: number;
540 code?: string;
541 path?: string;
542 syscall?: string;
543 stack?: string;
544 }
545
546 interface EventEmitter {
547 addListener(event: string | symbol, listener: (...args: any[]) => void): this;
548 on(event: string | symbol, listener: (...args: any[]) => void): this;
549 once(event: string | symbol, listener: (...args: any[]) => void): this;
550 removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
551 off(event: string | symbol, listener: (...args: any[]) => void): this;
552 removeAllListeners(event?: string | symbol): this;
553 setMaxListeners(n: number): this;
554 getMaxListeners(): number;
555 listeners(event: string | symbol): Function[];
556 rawListeners(event: string | symbol): Function[];
557 emit(event: string | symbol, ...args: any[]): boolean;
558 listenerCount(type: string | symbol): number;
559 // Added in Node 6...
560 prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
561 prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
562 eventNames(): Array<string | symbol>;
563 }
564
565 interface ReadableStream extends EventEmitter {
566 readable: boolean;
567 read(size?: number): string | Buffer;
568 setEncoding(encoding: string): this;
569 pause(): this;
570 resume(): this;
571 isPaused(): boolean;
572 pipe<T extends WritableStream>(destination: T, options?: { end?: boolean; }): T;
573 unpipe(destination?: WritableStream): this;
574 unshift(chunk: string | Uint8Array, encoding?: BufferEncoding): void;
575 wrap(oldStream: ReadableStream): this;
576 [Symbol.asyncIterator](): AsyncIterableIterator<string | Buffer>;
577 }
578
579 interface WritableStream extends EventEmitter {
580 writable: boolean;
581 write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
582 write(str: string, encoding?: string, cb?: (err?: Error | null) => void): boolean;
583 end(cb?: () => void): void;
584 end(data: string | Uint8Array, cb?: () => void): void;
585 end(str: string, encoding?: string, cb?: () => void): void;
586 }
587
588 interface ReadWriteStream extends ReadableStream, WritableStream { }
589
590 interface Domain extends EventEmitter {
591 run<T>(fn: (...args: any[]) => T, ...args: any[]): T;
592 add(emitter: EventEmitter | Timer): void;
593 remove(emitter: EventEmitter | Timer): void;
594 bind<T extends Function>(cb: T): T;
595 intercept<T extends Function>(cb: T): T;
596
597 addListener(event: string, listener: (...args: any[]) => void): this;
598 on(event: string, listener: (...args: any[]) => void): this;
599 once(event: string, listener: (...args: any[]) => void): this;
600 removeListener(event: string, listener: (...args: any[]) => void): this;
601 removeAllListeners(event?: string): this;
602 }
603
604 interface MemoryUsage {
605 rss: number;
606 heapTotal: number;
607 heapUsed: number;
608 external: number;
609 }
610
611 interface CpuUsage {
612 user: number;
613 system: number;
614 }
615
616 interface ProcessRelease {
617 name: string;
618 sourceUrl?: string;
619 headersUrl?: string;
620 libUrl?: string;
621 lts?: string;
622 }
623
624 interface ProcessVersions {
625 http_parser: string;
626 node: string;
627 v8: string;
628 ares: string;
629 uv: string;
630 zlib: string;
631 modules: string;
632 openssl: string;
633 }
634
635 type Platform = 'aix'
636 | 'android'
637 | 'darwin'
638 | 'freebsd'
639 | 'linux'
640 | 'openbsd'
641 | 'sunos'
642 | 'win32'
643 | 'cygwin'
644 | 'netbsd';
645
646 type Signals =
647 "SIGABRT" | "SIGALRM" | "SIGBUS" | "SIGCHLD" | "SIGCONT" | "SIGFPE" | "SIGHUP" | "SIGILL" | "SIGINT" | "SIGIO" |
648 "SIGIOT" | "SIGKILL" | "SIGPIPE" | "SIGPOLL" | "SIGPROF" | "SIGPWR" | "SIGQUIT" | "SIGSEGV" | "SIGSTKFLT" |
649 "SIGSTOP" | "SIGSYS" | "SIGTERM" | "SIGTRAP" | "SIGTSTP" | "SIGTTIN" | "SIGTTOU" | "SIGUNUSED" | "SIGURG" |
650 "SIGUSR1" | "SIGUSR2" | "SIGVTALRM" | "SIGWINCH" | "SIGXCPU" | "SIGXFSZ" | "SIGBREAK" | "SIGLOST" | "SIGINFO";
651
652 type MultipleResolveType = 'resolve' | 'reject';
653
654 type BeforeExitListener = (code: number) => void;
655 type DisconnectListener = () => void;
656 type ExitListener = (code: number) => void;
657 type RejectionHandledListener = (promise: Promise<any>) => void;
658 type UncaughtExceptionListener = (error: Error) => void;
659 type UnhandledRejectionListener = (reason: {} | null | undefined, promise: Promise<any>) => void;
660 type WarningListener = (warning: Error) => void;
661 type MessageListener = (message: any, sendHandle: any) => void;
662 type SignalsListener = (signal: Signals) => void;
663 type NewListenerListener = (type: string | symbol, listener: (...args: any[]) => void) => void;
664 type RemoveListenerListener = (type: string | symbol, listener: (...args: any[]) => void) => void;
665 type MultipleResolveListener = (type: MultipleResolveType, promise: Promise<any>, value: any) => void;
666
667 interface Socket extends ReadWriteStream {
668 isTTY?: true;
669 }
670
671 interface ProcessEnv {
672 [key: string]: string | undefined;
673 }
674
675 interface HRTime {
676 (time?: [number, number]): [number, number];
677 }
678
679 interface ProcessReport {
680 /**
681 * Directory where the report is written.
682 * working directory of the Node.js process.
683 * @default '' indicating that reports are written to the current
684 */
685 directory: string;
686
687 /**
688 * Filename where the report is written.
689 * The default value is the empty string.
690 * @default '' the output filename will be comprised of a timestamp,
691 * PID, and sequence number.
692 */
693 filename: string;
694
695 /**
696 * Returns a JSON-formatted diagnostic report for the running process.
697 * The report's JavaScript stack trace is taken from err, if present.
698 */
699 getReport(err?: Error): string;
700
701 /**
702 * If true, a diagnostic report is generated on fatal errors,
703 * such as out of memory errors or failed C++ assertions.
704 * @default false
705 */
706 reportOnFatalError: boolean;
707
708 /**
709 * If true, a diagnostic report is generated when the process
710 * receives the signal specified by process.report.signal.
711 * @defaul false
712 */
713 reportOnSignal: boolean;
714
715 /**
716 * If true, a diagnostic report is generated on uncaught exception.
717 * @default false
718 */
719 reportOnUncaughtException: boolean;
720
721 /**
722 * The signal used to trigger the creation of a diagnostic report.
723 * @default 'SIGUSR2'
724 */
725 signal: Signals;
726
727 /**
728 * Writes a diagnostic report to a file. If filename is not provided, the default filename
729 * includes the date, time, PID, and a sequence number.
730 * The report's JavaScript stack trace is taken from err, if present.
731 *
732 * @param fileName Name of the file where the report is written.
733 * This should be a relative path, that will be appended to the directory specified in
734 * `process.report.directory`, or the current working directory of the Node.js process,
735 * if unspecified.
736 * @param error A custom error used for reporting the JavaScript stack.
737 * @return Filename of the generated report.
738 */
739 writeReport(fileName?: string): string;
740 writeReport(error?: Error): string;
741 writeReport(fileName?: string, err?: Error): string;
742 }
743
744 interface ResourceUsage {
745 fsRead: number;
746 fsWrite: number;
747 involuntaryContextSwitches: number;
748 ipcReceived: number;
749 ipcSent: number;
750 majorPageFault: number;
751 maxRSS: number;
752 minorPageFault: number;
753 sharedMemorySize: number;
754 signalsCount: number;
755 swappedOut: number;
756 systemCPUTime: number;
757 unsharedDataSize: number;
758 unsharedStackSize: number;
759 userCPUTime: number;
760 voluntaryContextSwitches: number;
761 }
762
763 interface Process extends EventEmitter {
764 /**
765 * Can also be a tty.WriteStream, not typed due to limitation.s
766 */
767 stdout: WriteStream;
768 /**
769 * Can also be a tty.WriteStream, not typed due to limitation.s
770 */
771 stderr: WriteStream;
772 stdin: ReadStream;
773 openStdin(): Socket;
774 argv: string[];
775 argv0: string;
776 execArgv: string[];
777 execPath: string;
778 abort(): void;
779 chdir(directory: string): void;
780 cwd(): string;
781 debugPort: number;
782 emitWarning(warning: string | Error, name?: string, ctor?: Function): void;
783 env: ProcessEnv;
784 exit(code?: number): never;
785 exitCode?: number;
786 getgid(): number;
787 setgid(id: number | string): void;
788 getuid(): number;
789 setuid(id: number | string): void;
790 geteuid(): number;
791 seteuid(id: number | string): void;
792 getegid(): number;
793 setegid(id: number | string): void;
794 getgroups(): number[];
795 setgroups(groups: Array<string | number>): void;
796 setUncaughtExceptionCaptureCallback(cb: ((err: Error) => void) | null): void;
797 hasUncaughtExceptionCaptureCallback(): boolean;
798 version: string;
799 versions: ProcessVersions;
800 config: {
801 target_defaults: {
802 cflags: any[];
803 default_configuration: string;
804 defines: string[];
805 include_dirs: string[];
806 libraries: string[];
807 };
808 variables: {
809 clang: number;
810 host_arch: string;
811 node_install_npm: boolean;
812 node_install_waf: boolean;
813 node_prefix: string;
814 node_shared_openssl: boolean;
815 node_shared_v8: boolean;
816 node_shared_zlib: boolean;
817 node_use_dtrace: boolean;
818 node_use_etw: boolean;
819 node_use_openssl: boolean;
820 target_arch: string;
821 v8_no_strict_aliasing: number;
822 v8_use_snapshot: boolean;
823 visibility: string;
824 };
825 };
826 kill(pid: number, signal?: string | number): void;
827 pid: number;
828 ppid: number;
829 title: string;
830 arch: string;
831 platform: Platform;
832 mainModule?: Module;
833 memoryUsage(): MemoryUsage;
834 cpuUsage(previousValue?: CpuUsage): CpuUsage;
835 nextTick(callback: Function, ...args: any[]): void;
836 release: ProcessRelease;
837 features: {
838 inspector: boolean;
839 debug: boolean;
840 uv: boolean;
841 ipv6: boolean;
842 tls_alpn: boolean;
843 tls_sni: boolean;
844 tls_ocsp: boolean;
845 tls: boolean;
846 };
847 /**
848 * Can only be set if not in worker thread.
849 */
850 umask(mask?: number): number;
851 uptime(): number;
852 hrtime: HRTime;
853 domain: Domain;
854
855 // Worker
856 send?(message: any, sendHandle?: any, options?: { swallowErrors?: boolean}, callback?: (error: Error | null) => void): boolean;
857 disconnect(): void;
858 connected: boolean;
859
860 /**
861 * The `process.allowedNodeEnvironmentFlags` property is a special,
862 * read-only `Set` of flags allowable within the [`NODE_OPTIONS`][]
863 * environment variable.
864 */
865 allowedNodeEnvironmentFlags: ReadonlySet<string>;
866
867 /**
868 * Only available with `--experimental-report`
869 */
870 report?: ProcessReport;
871
872 resourceUsage(): ResourceUsage;
873
874 /**
875 * EventEmitter
876 * 1. beforeExit
877 * 2. disconnect
878 * 3. exit
879 * 4. message
880 * 5. rejectionHandled
881 * 6. uncaughtException
882 * 7. unhandledRejection
883 * 8. warning
884 * 9. message
885 * 10. <All OS Signals>
886 * 11. newListener/removeListener inherited from EventEmitter
887 */
888 addListener(event: "beforeExit", listener: BeforeExitListener): this;
889 addListener(event: "disconnect", listener: DisconnectListener): this;
890 addListener(event: "exit", listener: ExitListener): this;
891 addListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
892 addListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
893 addListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
894 addListener(event: "warning", listener: WarningListener): this;
895 addListener(event: "message", listener: MessageListener): this;
896 addListener(event: Signals, listener: SignalsListener): this;
897 addListener(event: "newListener", listener: NewListenerListener): this;
898 addListener(event: "removeListener", listener: RemoveListenerListener): this;
899 addListener(event: "multipleResolves", listener: MultipleResolveListener): this;
900
901 emit(event: "beforeExit", code: number): boolean;
902 emit(event: "disconnect"): boolean;
903 emit(event: "exit", code: number): boolean;
904 emit(event: "rejectionHandled", promise: Promise<any>): boolean;
905 emit(event: "uncaughtException", error: Error): boolean;
906 emit(event: "unhandledRejection", reason: any, promise: Promise<any>): boolean;
907 emit(event: "warning", warning: Error): boolean;
908 emit(event: "message", message: any, sendHandle: any): this;
909 emit(event: Signals, signal: Signals): boolean;
910 emit(event: "newListener", eventName: string | symbol, listener: (...args: any[]) => void): this;
911 emit(event: "removeListener", eventName: string, listener: (...args: any[]) => void): this;
912 emit(event: "multipleResolves", listener: MultipleResolveListener): this;
913
914 on(event: "beforeExit", listener: BeforeExitListener): this;
915 on(event: "disconnect", listener: DisconnectListener): this;
916 on(event: "exit", listener: ExitListener): this;
917 on(event: "rejectionHandled", listener: RejectionHandledListener): this;
918 on(event: "uncaughtException", listener: UncaughtExceptionListener): this;
919 on(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
920 on(event: "warning", listener: WarningListener): this;
921 on(event: "message", listener: MessageListener): this;
922 on(event: Signals, listener: SignalsListener): this;
923 on(event: "newListener", listener: NewListenerListener): this;
924 on(event: "removeListener", listener: RemoveListenerListener): this;
925 on(event: "multipleResolves", listener: MultipleResolveListener): this;
926
927 once(event: "beforeExit", listener: BeforeExitListener): this;
928 once(event: "disconnect", listener: DisconnectListener): this;
929 once(event: "exit", listener: ExitListener): this;
930 once(event: "rejectionHandled", listener: RejectionHandledListener): this;
931 once(event: "uncaughtException", listener: UncaughtExceptionListener): this;
932 once(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
933 once(event: "warning", listener: WarningListener): this;
934 once(event: "message", listener: MessageListener): this;
935 once(event: Signals, listener: SignalsListener): this;
936 once(event: "newListener", listener: NewListenerListener): this;
937 once(event: "removeListener", listener: RemoveListenerListener): this;
938 once(event: "multipleResolves", listener: MultipleResolveListener): this;
939
940 prependListener(event: "beforeExit", listener: BeforeExitListener): this;
941 prependListener(event: "disconnect", listener: DisconnectListener): this;
942 prependListener(event: "exit", listener: ExitListener): this;
943 prependListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
944 prependListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
945 prependListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
946 prependListener(event: "warning", listener: WarningListener): this;
947 prependListener(event: "message", listener: MessageListener): this;
948 prependListener(event: Signals, listener: SignalsListener): this;
949 prependListener(event: "newListener", listener: NewListenerListener): this;
950 prependListener(event: "removeListener", listener: RemoveListenerListener): this;
951 prependListener(event: "multipleResolves", listener: MultipleResolveListener): this;
952
953 prependOnceListener(event: "beforeExit", listener: BeforeExitListener): this;
954 prependOnceListener(event: "disconnect", listener: DisconnectListener): this;
955 prependOnceListener(event: "exit", listener: ExitListener): this;
956 prependOnceListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
957 prependOnceListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
958 prependOnceListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
959 prependOnceListener(event: "warning", listener: WarningListener): this;
960 prependOnceListener(event: "message", listener: MessageListener): this;
961 prependOnceListener(event: Signals, listener: SignalsListener): this;
962 prependOnceListener(event: "newListener", listener: NewListenerListener): this;
963 prependOnceListener(event: "removeListener", listener: RemoveListenerListener): this;
964 prependOnceListener(event: "multipleResolves", listener: MultipleResolveListener): this;
965
966 listeners(event: "beforeExit"): BeforeExitListener[];
967 listeners(event: "disconnect"): DisconnectListener[];
968 listeners(event: "exit"): ExitListener[];
969 listeners(event: "rejectionHandled"): RejectionHandledListener[];
970 listeners(event: "uncaughtException"): 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 GLOBAL: Global;
993 Infinity: typeof Infinity;
994 Int16Array: typeof Int16Array;
995 Int32Array: typeof Int32Array;
996 Int8Array: typeof Int8Array;
997 Intl: typeof Intl;
998 JSON: typeof JSON;
999 Map: MapConstructor;
1000 Math: typeof Math;
1001 NaN: typeof NaN;
1002 Number: typeof Number;
1003 Object: typeof Object;
1004 Promise: typeof Promise;
1005 RangeError: typeof RangeError;
1006 ReferenceError: typeof ReferenceError;
1007 RegExp: typeof RegExp;
1008 Set: SetConstructor;
1009 String: typeof String;
1010 Symbol: Function;
1011 SyntaxError: typeof SyntaxError;
1012 TypeError: typeof TypeError;
1013 URIError: typeof URIError;
1014 Uint16Array: typeof Uint16Array;
1015 Uint32Array: typeof Uint32Array;
1016 Uint8Array: typeof Uint8Array;
1017 Uint8ClampedArray: typeof Uint8ClampedArray;
1018 WeakMap: WeakMapConstructor;
1019 WeakSet: WeakSetConstructor;
1020 clearImmediate: (immediateId: Immediate) => void;
1021 clearInterval: (intervalId: Timeout) => void;
1022 clearTimeout: (timeoutId: Timeout) => void;
1023 console: typeof console;
1024 decodeURI: typeof decodeURI;
1025 decodeURIComponent: typeof decodeURIComponent;
1026 encodeURI: typeof encodeURI;
1027 encodeURIComponent: typeof encodeURIComponent;
1028 escape: (str: string) => string;
1029 eval: typeof eval;
1030 global: Global;
1031 isFinite: typeof isFinite;
1032 isNaN: typeof isNaN;
1033 parseFloat: typeof parseFloat;
1034 parseInt: typeof parseInt;
1035 process: Process;
1036 /**
1037 * @deprecated Use `global`.
1038 */
1039 root: Global;
1040 setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => Immediate;
1041 setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => Timeout;
1042 setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => Timeout;
1043 queueMicrotask: typeof queueMicrotask;
1044 undefined: typeof undefined;
1045 unescape: (str: string) => string;
1046 gc: () => void;
1047 v8debug?: any;
1048 }
1049
1050 interface RefCounted {
1051 ref(): this;
1052 unref(): this;
1053 }
1054
1055 // compatibility with older typings
1056 interface Timer extends RefCounted {
1057 hasRef(): boolean;
1058 refresh(): this;
1059 }
1060
1061 interface Immediate extends RefCounted {
1062 hasRef(): boolean;
1063 _onImmediate: Function; // to distinguish it from the Timeout class
1064 }
1065
1066 interface Timeout extends Timer {
1067 hasRef(): boolean;
1068 refresh(): this;
1069 }
1070
1071 type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array;
1072 type ArrayBufferView = TypedArray | DataView;
1073
1074 interface NodeRequireCache {
1075 [path: string]: NodeModule;
1076 }
1077
1078 interface Require {
1079 /* tslint:disable-next-line:callable-types */
1080 (id: string): any;
1081 resolve: RequireResolve;
1082 cache: NodeRequireCache;
1083 /**
1084 * @deprecated
1085 */
1086 extensions: RequireExtensions;
1087 main: Module | undefined;
1088 }
1089
1090 interface RequireResolve {
1091 (id: string, options?: { paths?: string[]; }): string;
1092 paths(request: string): string[] | null;
1093 }
1094
1095 interface RequireExtensions {
1096 '.js': (m: Module, filename: string) => any;
1097 '.json': (m: Module, filename: string) => any;
1098 '.node': (m: Module, filename: string) => any;
1099 [ext: string]: (m: Module, filename: string) => any;
1100 }
1101 interface Module {
1102 exports: any;
1103 require: Require;
1104 id: string;
1105 filename: string;
1106 loaded: boolean;
1107 parent: Module | null;
1108 children: Module[];
1109 paths: string[];
1110 }
1111}