UNPKG

43.4 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(): void;
49 /**
50 * Decreases indentation of subsequent lines by two spaces.
51 */
52 groupEnd(): void;
53 /**
54 * The {@link console.info()} function is an alias for {@link console.log()}.
55 */
56 info(message?: any, ...optionalParams: any[]): void;
57 /**
58 * Prints to `stdout` with newline.
59 */
60 log(message?: any, ...optionalParams: any[]): void;
61 /**
62 * This method does not display anything unless used in the inspector.
63 * Prints to `stdout` the array `array` formatted as a table.
64 */
65 table(tabularData: any, properties?: ReadonlyArray<string>): void;
66 /**
67 * Starts a timer that can be used to compute the duration of an operation. Timers are identified by a unique `label`.
68 */
69 time(label?: string): void;
70 /**
71 * Stops a timer that was previously started by calling {@link console.time()} and prints the result to `stdout`.
72 */
73 timeEnd(label?: string): void;
74 /**
75 * For a timer that was previously started by calling {@link console.time()}, prints the elapsed time and other `data` arguments to `stdout`.
76 */
77 timeLog(label?: string, ...data: any[]): void;
78 /**
79 * Prints to `stderr` the string 'Trace :', followed by the {@link util.format()} formatted message and stack trace to the current position in the code.
80 */
81 trace(message?: any, ...optionalParams: any[]): void;
82 /**
83 * The {@link console.warn()} function is an alias for {@link console.error()}.
84 */
85 warn(message?: any, ...optionalParams: any[]): void;
86
87 // --- Inspector mode only ---
88 /**
89 * This method does not display anything unless used in the inspector.
90 * The console.markTimeline() method is the deprecated form of console.timeStamp().
91 *
92 * @deprecated Use console.timeStamp() instead.
93 */
94 markTimeline(label?: string): void;
95 /**
96 * This method does not display anything unless used in the inspector.
97 * Starts a JavaScript CPU profile with an optional label.
98 */
99 profile(label?: string): void;
100 /**
101 * This method does not display anything unless used in the inspector.
102 * Stops the current JavaScript CPU profiling session if one has been started and prints the report to the Profiles panel of the inspector.
103 */
104 profileEnd(label?: string): void;
105 /**
106 * This method does not display anything unless used in the inspector.
107 * Adds an event with the label `label` to the Timeline panel of the inspector.
108 */
109 timeStamp(label?: string): void;
110 /**
111 * This method does not display anything unless used in the inspector.
112 * The console.timeline() method is the deprecated form of console.time().
113 *
114 * @deprecated Use console.time() instead.
115 */
116 timeline(label?: string): void;
117 /**
118 * This method does not display anything unless used in the inspector.
119 * The console.timelineEnd() method is the deprecated form of console.timeEnd().
120 *
121 * @deprecated Use console.timeEnd() instead.
122 */
123 timelineEnd(label?: string): void;
124}
125
126interface Error {
127 stack?: string;
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 /** Returns a copy with leading whitespace removed. */
157 trimStart(): string;
158 /** Returns a copy with trailing whitespace removed. */
159 trimEnd(): string;
160}
161
162/*-----------------------------------------------*
163 * *
164 * GLOBAL *
165 * *
166 ------------------------------------------------*/
167declare var process: NodeJS.Process;
168declare var global: NodeJS.Global;
169declare var console: Console;
170
171declare var __filename: string;
172declare var __dirname: string;
173
174declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timeout;
175declare namespace setTimeout {
176 function __promisify__(ms: number): Promise<void>;
177 function __promisify__<T>(ms: number, value: T): Promise<T>;
178}
179declare function clearTimeout(timeoutId: NodeJS.Timeout): void;
180declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timeout;
181declare function clearInterval(intervalId: NodeJS.Timeout): void;
182declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): NodeJS.Immediate;
183declare namespace setImmediate {
184 function __promisify__(): Promise<void>;
185 function __promisify__<T>(value: T): Promise<T>;
186}
187declare function clearImmediate(immediateId: NodeJS.Immediate): void;
188
189// TODO: change to `type NodeRequireFunction = (id: string) => any;` in next mayor version.
190interface NodeRequireFunction {
191 (id: string): any;
192}
193
194interface NodeRequire extends NodeRequireFunction {
195 resolve: RequireResolve;
196 cache: any;
197 extensions: NodeExtensions;
198 main: NodeModule | undefined;
199}
200
201interface RequireResolve {
202 (id: string, options?: { paths?: string[]; }): string;
203 paths(request: string): string[] | null;
204}
205
206interface NodeExtensions {
207 '.js': (m: NodeModule, filename: string) => any;
208 '.json': (m: NodeModule, filename: string) => any;
209 '.node': (m: NodeModule, filename: string) => any;
210 [ext: string]: (m: NodeModule, filename: string) => any;
211}
212
213declare var require: NodeRequire;
214
215interface NodeModule {
216 exports: any;
217 require: NodeRequireFunction;
218 id: string;
219 filename: string;
220 loaded: boolean;
221 parent: NodeModule | null;
222 children: NodeModule[];
223 paths: string[];
224}
225
226declare var module: NodeModule;
227
228// Same as module.exports
229declare var exports: any;
230
231// Buffer class
232type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "latin1" | "binary" | "hex";
233interface Buffer extends Uint8Array {
234 constructor: typeof Buffer;
235 write(string: string, offset?: number, length?: number, encoding?: string): number;
236 toString(encoding?: string, start?: number, end?: number): string;
237 toJSON(): { type: 'Buffer', data: any[] };
238 equals(otherBuffer: Uint8Array): boolean;
239 compare(otherBuffer: Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number;
240 copy(targetBuffer: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
241 slice(start?: number, end?: number): Buffer;
242 writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
243 writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
244 writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
245 writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
246 readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
247 readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
248 readIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
249 readIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
250 readUInt8(offset: number, noAssert?: boolean): number;
251 readUInt16LE(offset: number, noAssert?: boolean): number;
252 readUInt16BE(offset: number, noAssert?: boolean): number;
253 readUInt32LE(offset: number, noAssert?: boolean): number;
254 readUInt32BE(offset: number, noAssert?: boolean): number;
255 readInt8(offset: number, noAssert?: boolean): number;
256 readInt16LE(offset: number, noAssert?: boolean): number;
257 readInt16BE(offset: number, noAssert?: boolean): number;
258 readInt32LE(offset: number, noAssert?: boolean): number;
259 readInt32BE(offset: number, noAssert?: boolean): number;
260 readFloatLE(offset: number, noAssert?: boolean): number;
261 readFloatBE(offset: number, noAssert?: boolean): number;
262 readDoubleLE(offset: number, noAssert?: boolean): number;
263 readDoubleBE(offset: number, noAssert?: boolean): number;
264 swap16(): Buffer;
265 swap32(): Buffer;
266 swap64(): Buffer;
267 writeUInt8(value: number, offset: number, noAssert?: boolean): number;
268 writeUInt16LE(value: number, offset: number, noAssert?: boolean): number;
269 writeUInt16BE(value: number, offset: number, noAssert?: boolean): number;
270 writeUInt32LE(value: number, offset: number, noAssert?: boolean): number;
271 writeUInt32BE(value: number, offset: number, noAssert?: boolean): number;
272 writeInt8(value: number, offset: number, noAssert?: boolean): number;
273 writeInt16LE(value: number, offset: number, noAssert?: boolean): number;
274 writeInt16BE(value: number, offset: number, noAssert?: boolean): number;
275 writeInt32LE(value: number, offset: number, noAssert?: boolean): number;
276 writeInt32BE(value: number, offset: number, noAssert?: boolean): number;
277 writeFloatLE(value: number, offset: number, noAssert?: boolean): number;
278 writeFloatBE(value: number, offset: number, noAssert?: boolean): number;
279 writeDoubleLE(value: number, offset: number, noAssert?: boolean): number;
280 writeDoubleBE(value: number, offset: number, noAssert?: boolean): number;
281 fill(value: any, offset?: number, end?: number): this;
282 indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: string): number;
283 lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: string): number;
284 entries(): IterableIterator<[number, number]>;
285 includes(value: string | number | Buffer, byteOffset?: number, encoding?: string): boolean;
286 keys(): IterableIterator<number>;
287 values(): IterableIterator<number>;
288}
289
290/**
291 * Raw data is stored in instances of the Buffer class.
292 * 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.
293 * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'
294 */
295declare const Buffer: {
296 /**
297 * Allocates a new buffer containing the given {str}.
298 *
299 * @param str String to store in buffer.
300 * @param encoding encoding to use, optional. Default is 'utf8'
301 * @deprecated since v10.0.0 - Use `Buffer.from(string[, encoding])` instead.
302 */
303 new(str: string, encoding?: string): Buffer;
304 /**
305 * Allocates a new buffer of {size} octets.
306 *
307 * @param size count of octets to allocate.
308 * @deprecated since v10.0.0 - Use `Buffer.alloc()` instead (also see `Buffer.allocUnsafe()`).
309 */
310 new(size: number): Buffer;
311 /**
312 * Allocates a new buffer containing the given {array} of octets.
313 *
314 * @param array The octets to store.
315 * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
316 */
317 new(array: Uint8Array): Buffer;
318 /**
319 * Produces a Buffer backed by the same allocated memory as
320 * the given {ArrayBuffer}/{SharedArrayBuffer}.
321 *
322 *
323 * @param arrayBuffer The ArrayBuffer with which to share memory.
324 * @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead.
325 */
326 new(arrayBuffer: ArrayBuffer | SharedArrayBuffer): Buffer;
327 /**
328 * Allocates a new buffer containing the given {array} of octets.
329 *
330 * @param array The octets to store.
331 * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
332 */
333 new(array: ReadonlyArray<any>): Buffer;
334 /**
335 * Copies the passed {buffer} data onto a new {Buffer} instance.
336 *
337 * @param buffer The buffer to copy.
338 * @deprecated since v10.0.0 - Use `Buffer.from(buffer)` instead.
339 */
340 new(buffer: Buffer): Buffer;
341 prototype: Buffer;
342 /**
343 * When passed a reference to the .buffer property of a TypedArray instance,
344 * the newly created Buffer will share the same allocated memory as the TypedArray.
345 * The optional {byteOffset} and {length} arguments specify a memory range
346 * within the {arrayBuffer} that will be shared by the Buffer.
347 *
348 * @param arrayBuffer The .buffer property of any TypedArray or a new ArrayBuffer()
349 */
350 from(arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): Buffer;
351 /**
352 * Creates a new Buffer using the passed {data}
353 * @param data data to create a new Buffer
354 */
355 from(data: ReadonlyArray<any>): Buffer;
356 from(data: Uint8Array): Buffer;
357 /**
358 * Creates a new buffer containing the coerced value of an object
359 * A `TypeError` will be thrown if {obj} has not mentioned methods or is not of other type appropriate for `Buffer.from()` variants.
360 * @param obj An object supporting `Symbol.toPrimitive` or `valueOf()`.
361 */
362 from(obj: { valueOf(): string | object } | { [Symbol.toPrimitive](hint: 'string'): string }, byteOffset?: number, length?: number): Buffer;
363 /**
364 * Creates a new Buffer containing the given JavaScript string {str}.
365 * If provided, the {encoding} parameter identifies the character encoding.
366 * If not provided, {encoding} defaults to 'utf8'.
367 */
368 from(str: string, encoding?: string): Buffer;
369 /**
370 * Creates a new Buffer using the passed {data}
371 * @param values to create a new Buffer
372 */
373 of(...items: number[]): Buffer;
374 /**
375 * Returns true if {obj} is a Buffer
376 *
377 * @param obj object to test.
378 */
379 isBuffer(obj: any): obj is Buffer;
380 /**
381 * Returns true if {encoding} is a valid encoding argument.
382 * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'
383 *
384 * @param encoding string to test.
385 */
386 isEncoding(encoding: string): boolean | undefined;
387 /**
388 * Gives the actual byte length of a string. encoding defaults to 'utf8'.
389 * This is not the same as String.prototype.length since that returns the number of characters in a string.
390 *
391 * @param string string to test.
392 * @param encoding encoding used to evaluate (defaults to 'utf8')
393 */
394 byteLength(string: string | NodeJS.TypedArray | DataView | ArrayBuffer | SharedArrayBuffer, encoding?: string): number;
395 /**
396 * Returns a buffer which is the result of concatenating all the buffers in the list together.
397 *
398 * If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer.
399 * If the list has exactly one item, then the first item of the list is returned.
400 * If the list has more than one item, then a new Buffer is created.
401 *
402 * @param list An array of Buffer objects to concatenate
403 * @param totalLength Total length of the buffers when concatenated.
404 * 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.
405 */
406 concat(list: ReadonlyArray<Uint8Array>, totalLength?: number): Buffer;
407 /**
408 * The same as buf1.compare(buf2).
409 */
410 compare(buf1: Uint8Array, buf2: Uint8Array): number;
411 /**
412 * Allocates a new buffer of {size} octets.
413 *
414 * @param size count of octets to allocate.
415 * @param fill if specified, buffer will be initialized by calling buf.fill(fill).
416 * If parameter is omitted, buffer will be filled with zeros.
417 * @param encoding encoding used for call to buf.fill while initalizing
418 */
419 alloc(size: number, fill?: string | Buffer | number, encoding?: string): Buffer;
420 /**
421 * Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents
422 * of the newly created Buffer are unknown and may contain sensitive data.
423 *
424 * @param size count of octets to allocate
425 */
426 allocUnsafe(size: number): Buffer;
427 /**
428 * Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents
429 * of the newly created Buffer are unknown and may contain sensitive data.
430 *
431 * @param size count of octets to allocate
432 */
433 allocUnsafeSlow(size: number): Buffer;
434 /**
435 * 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.
436 */
437 poolSize: number;
438};
439
440/*----------------------------------------------*
441* *
442* GLOBAL INTERFACES *
443* *
444*-----------------------------------------------*/
445declare namespace NodeJS {
446 interface InspectOptions {
447 showHidden?: boolean;
448 depth?: number | null;
449 colors?: boolean;
450 customInspect?: boolean;
451 showProxy?: boolean;
452 maxArrayLength?: number | null;
453 breakLength?: number;
454 compact?: boolean;
455 sorted?: boolean | ((a: string, b: string) => number);
456 }
457
458 interface ConsoleConstructorOptions {
459 stdout: WritableStream;
460 stderr?: WritableStream;
461 ignoreErrors?: boolean;
462 colorMode?: boolean | 'auto';
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 class 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: string): 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): void;
582 unshift(chunk: Buffer): void;
583 wrap(oldStream: ReadableStream): this;
584 [Symbol.asyncIterator](): AsyncIterableIterator<string | Buffer>;
585 }
586
587 interface WritableStream extends EventEmitter {
588 writable: boolean;
589 write(buffer: Buffer | string, cb?: Function): boolean;
590 write(str: string, encoding?: string, cb?: Function): boolean;
591 end(cb?: Function): void;
592 end(buffer: Buffer, cb?: Function): void;
593 end(str: string, cb?: Function): void;
594 end(str: string, encoding?: string, cb?: Function): void;
595 }
596
597 interface ReadWriteStream extends ReadableStream, WritableStream { }
598
599 interface Events extends EventEmitter { }
600
601 interface Domain extends Events {
602 run(fn: Function): void;
603 add(emitter: Events): void;
604 remove(emitter: Events): void;
605 bind(cb: (err: Error, data: any) => any): any;
606 intercept(cb: (data: any) => any): any;
607
608 addListener(event: string, listener: (...args: any[]) => void): this;
609 on(event: string, listener: (...args: any[]) => void): this;
610 once(event: string, listener: (...args: any[]) => void): this;
611 removeListener(event: string, listener: (...args: any[]) => void): this;
612 removeAllListeners(event?: string): this;
613 }
614
615 interface MemoryUsage {
616 rss: number;
617 heapTotal: number;
618 heapUsed: number;
619 external: number;
620 }
621
622 interface CpuUsage {
623 user: number;
624 system: number;
625 }
626
627 interface ProcessRelease {
628 name: string;
629 sourceUrl?: string;
630 headersUrl?: string;
631 libUrl?: string;
632 lts?: string;
633 }
634
635 interface ProcessVersions {
636 http_parser: string;
637 node: string;
638 v8: string;
639 ares: string;
640 uv: string;
641 zlib: string;
642 modules: string;
643 openssl: string;
644 }
645
646 type Platform = 'aix'
647 | 'android'
648 | 'darwin'
649 | 'freebsd'
650 | 'linux'
651 | 'openbsd'
652 | 'sunos'
653 | 'win32'
654 | 'cygwin';
655
656 type Signals =
657 "SIGABRT" | "SIGALRM" | "SIGBUS" | "SIGCHLD" | "SIGCONT" | "SIGFPE" | "SIGHUP" | "SIGILL" | "SIGINT" | "SIGIO" |
658 "SIGIOT" | "SIGKILL" | "SIGPIPE" | "SIGPOLL" | "SIGPROF" | "SIGPWR" | "SIGQUIT" | "SIGSEGV" | "SIGSTKFLT" |
659 "SIGSTOP" | "SIGSYS" | "SIGTERM" | "SIGTRAP" | "SIGTSTP" | "SIGTTIN" | "SIGTTOU" | "SIGUNUSED" | "SIGURG" |
660 "SIGUSR1" | "SIGUSR2" | "SIGVTALRM" | "SIGWINCH" | "SIGXCPU" | "SIGXFSZ" | "SIGBREAK" | "SIGLOST" | "SIGINFO";
661
662 type MultipleResolveType = 'resolve' | 'reject';
663
664 type BeforeExitListener = (code: number) => void;
665 type DisconnectListener = () => void;
666 type ExitListener = (code: number) => void;
667 type RejectionHandledListener = (promise: Promise<any>) => void;
668 type UncaughtExceptionListener = (error: Error) => void;
669 type UnhandledRejectionListener = (reason: {} | null | undefined, promise: Promise<any>) => void;
670 type WarningListener = (warning: Error) => void;
671 type MessageListener = (message: any, sendHandle: any) => void;
672 type SignalsListener = (signal: Signals) => void;
673 type NewListenerListener = (type: string | symbol, listener: (...args: any[]) => void) => void;
674 type RemoveListenerListener = (type: string | symbol, listener: (...args: any[]) => void) => void;
675 type MultipleResolveListener = (type: MultipleResolveType, promise: Promise<any>, value: any) => void;
676
677 interface Socket extends ReadWriteStream {
678 isTTY?: true;
679 }
680
681 interface ProcessEnv {
682 [key: string]: string | undefined;
683 }
684
685 interface WriteStream extends Socket {
686 readonly writableHighWaterMark: number;
687 readonly writableLength: number;
688 columns?: number;
689 rows?: number;
690 _write(chunk: any, encoding: string, callback: Function): void;
691 _destroy(err: Error | null, callback: Function): void;
692 _final(callback: Function): void;
693 setDefaultEncoding(encoding: string): this;
694 cork(): void;
695 uncork(): void;
696 destroy(error?: Error): void;
697 }
698 interface ReadStream extends Socket {
699 readonly readableFlowing: boolean | null;
700 readonly readableHighWaterMark: number;
701 readonly readableLength: number;
702 isRaw?: boolean;
703 setRawMode?(mode: boolean): void;
704 _read(size: number): void;
705 _destroy(err: Error | null, callback: Function): void;
706 push(chunk: any, encoding?: string): boolean;
707 destroy(error?: Error): void;
708 }
709
710 interface HRTime {
711 (time?: [number, number]): [number, number];
712 bigint(): bigint;
713 }
714
715 interface EmitWarningOptions {
716 /**
717 * When `warning` is a `string`, `type` is the name to use for the _type_ of warning being emitted.
718 *
719 * @default 'Warning'
720 */
721 type?: string;
722
723 /**
724 * A unique identifier for the warning instance being emitted.
725 */
726 code?: string;
727
728 /**
729 * When `warning` is a `string`, `ctor` is an optional function used to limit the generated stack trace.
730 *
731 * @default process.emitWarning
732 */
733 ctor?: Function;
734
735 /**
736 * Additional text to include with the error.
737 */
738 detail?: string;
739 }
740
741 interface Process extends EventEmitter {
742 stdout: WriteStream;
743 stderr: WriteStream;
744 stdin: ReadStream;
745 openStdin(): Socket;
746 argv: string[];
747 argv0: string;
748 execArgv: string[];
749 execPath: string;
750 abort(): never;
751 chdir(directory: string): void;
752 cwd(): string;
753 debugPort: number;
754
755 /**
756 * The `process.emitWarning()` method can be used to emit custom or application specific process warnings.
757 *
758 * These can be listened for by adding a handler to the `'warning'` event.
759 *
760 * @param warning The warning to emit.
761 * @param type When `warning` is a `string`, `type` is the name to use for the _type_ of warning being emitted. Default: `'Warning'`.
762 * @param code A unique identifier for the warning instance being emitted.
763 * @param ctor When `warning` is a `string`, `ctor` is an optional function used to limit the generated stack trace. Default: `process.emitWarning`.
764 */
765 emitWarning(warning: string | Error, ctor?: Function): void;
766 emitWarning(warning: string | Error, type?: string, ctor?: Function): void;
767 emitWarning(warning: string | Error, type?: string, code?: string, ctor?: Function): void;
768 emitWarning(warning: string | Error, options?: EmitWarningOptions): void;
769
770 env: ProcessEnv;
771 exit(code?: number): never;
772 exitCode?: number;
773 getgid(): number;
774 setgid(id: number | string): void;
775 getuid(): number;
776 setuid(id: number | string): void;
777 geteuid(): number;
778 seteuid(id: number | string): void;
779 getegid(): number;
780 setegid(id: number | string): void;
781 getgroups(): number[];
782 setgroups(groups: ReadonlyArray<string | number>): void;
783 setUncaughtExceptionCaptureCallback(cb: ((err: Error) => void) | null): void;
784 hasUncaughtExceptionCaptureCallback(): boolean;
785 version: string;
786 versions: ProcessVersions;
787 config: {
788 target_defaults: {
789 cflags: any[];
790 default_configuration: string;
791 defines: string[];
792 include_dirs: string[];
793 libraries: string[];
794 };
795 variables: {
796 clang: number;
797 host_arch: string;
798 node_install_npm: boolean;
799 node_install_waf: boolean;
800 node_prefix: string;
801 node_shared_openssl: boolean;
802 node_shared_v8: boolean;
803 node_shared_zlib: boolean;
804 node_use_dtrace: boolean;
805 node_use_etw: boolean;
806 node_use_openssl: boolean;
807 target_arch: string;
808 v8_no_strict_aliasing: number;
809 v8_use_snapshot: boolean;
810 visibility: string;
811 };
812 };
813 kill(pid: number, signal?: string | number): void;
814 pid: number;
815 ppid: number;
816 title: string;
817 arch: string;
818 platform: Platform;
819 mainModule?: NodeModule;
820 memoryUsage(): MemoryUsage;
821 cpuUsage(previousValue?: CpuUsage): CpuUsage;
822 nextTick(callback: Function, ...args: any[]): void;
823 release: ProcessRelease;
824 umask(mask?: number): number;
825 uptime(): number;
826 hrtime: HRTime;
827 domain: Domain;
828
829 // Worker
830 send?(message: any, sendHandle?: any): void;
831 disconnect(): void;
832 connected: boolean;
833
834 /**
835 * The `process.allowedNodeEnvironmentFlags` property is a special,
836 * read-only `Set` of flags allowable within the [`NODE_OPTIONS`][]
837 * environment variable.
838 */
839 allowedNodeEnvironmentFlags: ReadonlySet<string>;
840
841 /**
842 * EventEmitter
843 * 1. beforeExit
844 * 2. disconnect
845 * 3. exit
846 * 4. message
847 * 5. rejectionHandled
848 * 6. uncaughtException
849 * 7. unhandledRejection
850 * 8. warning
851 * 9. message
852 * 10. <All OS Signals>
853 * 11. newListener/removeListener inherited from EventEmitter
854 */
855 addListener(event: "beforeExit", listener: BeforeExitListener): this;
856 addListener(event: "disconnect", listener: DisconnectListener): this;
857 addListener(event: "exit", listener: ExitListener): this;
858 addListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
859 addListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
860 addListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
861 addListener(event: "warning", listener: WarningListener): this;
862 addListener(event: "message", listener: MessageListener): this;
863 addListener(event: Signals, listener: SignalsListener): this;
864 addListener(event: "newListener", listener: NewListenerListener): this;
865 addListener(event: "removeListener", listener: RemoveListenerListener): this;
866 addListener(event: "multipleResolves", listener: MultipleResolveListener): this;
867
868 emit(event: "beforeExit", code: number): boolean;
869 emit(event: "disconnect"): boolean;
870 emit(event: "exit", code: number): boolean;
871 emit(event: "rejectionHandled", promise: Promise<any>): boolean;
872 emit(event: "uncaughtException", error: Error): boolean;
873 emit(event: "unhandledRejection", reason: any, promise: Promise<any>): boolean;
874 emit(event: "warning", warning: Error): boolean;
875 emit(event: "message", message: any, sendHandle: any): this;
876 emit(event: Signals, signal: Signals): boolean;
877 emit(event: "newListener", eventName: string | symbol, listener: (...args: any[]) => void): this;
878 emit(event: "removeListener", eventName: string, listener: (...args: any[]) => void): this;
879 emit(event: "multipleResolves", listener: MultipleResolveListener): this;
880
881 on(event: "beforeExit", listener: BeforeExitListener): this;
882 on(event: "disconnect", listener: DisconnectListener): this;
883 on(event: "exit", listener: ExitListener): this;
884 on(event: "rejectionHandled", listener: RejectionHandledListener): this;
885 on(event: "uncaughtException", listener: UncaughtExceptionListener): this;
886 on(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
887 on(event: "warning", listener: WarningListener): this;
888 on(event: "message", listener: MessageListener): this;
889 on(event: Signals, listener: SignalsListener): this;
890 on(event: "newListener", listener: NewListenerListener): this;
891 on(event: "removeListener", listener: RemoveListenerListener): this;
892 on(event: "multipleResolves", listener: MultipleResolveListener): this;
893 on(event: string | symbol, listener: (...args: any[]) => void): this;
894
895 once(event: "beforeExit", listener: BeforeExitListener): this;
896 once(event: "disconnect", listener: DisconnectListener): this;
897 once(event: "exit", listener: ExitListener): this;
898 once(event: "rejectionHandled", listener: RejectionHandledListener): this;
899 once(event: "uncaughtException", listener: UncaughtExceptionListener): this;
900 once(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
901 once(event: "warning", listener: WarningListener): this;
902 once(event: "message", listener: MessageListener): this;
903 once(event: Signals, listener: SignalsListener): this;
904 once(event: "newListener", listener: NewListenerListener): this;
905 once(event: "removeListener", listener: RemoveListenerListener): this;
906 once(event: "multipleResolves", listener: MultipleResolveListener): this;
907
908 prependListener(event: "beforeExit", listener: BeforeExitListener): this;
909 prependListener(event: "disconnect", listener: DisconnectListener): this;
910 prependListener(event: "exit", listener: ExitListener): this;
911 prependListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
912 prependListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
913 prependListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
914 prependListener(event: "warning", listener: WarningListener): this;
915 prependListener(event: "message", listener: MessageListener): this;
916 prependListener(event: Signals, listener: SignalsListener): this;
917 prependListener(event: "newListener", listener: NewListenerListener): this;
918 prependListener(event: "removeListener", listener: RemoveListenerListener): this;
919 prependListener(event: "multipleResolves", listener: MultipleResolveListener): this;
920
921 prependOnceListener(event: "beforeExit", listener: BeforeExitListener): this;
922 prependOnceListener(event: "disconnect", listener: DisconnectListener): this;
923 prependOnceListener(event: "exit", listener: ExitListener): this;
924 prependOnceListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
925 prependOnceListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
926 prependOnceListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
927 prependOnceListener(event: "warning", listener: WarningListener): this;
928 prependOnceListener(event: "message", listener: MessageListener): this;
929 prependOnceListener(event: Signals, listener: SignalsListener): this;
930 prependOnceListener(event: "newListener", listener: NewListenerListener): this;
931 prependOnceListener(event: "removeListener", listener: RemoveListenerListener): this;
932 prependOnceListener(event: "multipleResolves", listener: MultipleResolveListener): this;
933
934 listeners(event: "beforeExit"): BeforeExitListener[];
935 listeners(event: "disconnect"): DisconnectListener[];
936 listeners(event: "exit"): ExitListener[];
937 listeners(event: "rejectionHandled"): RejectionHandledListener[];
938 listeners(event: "uncaughtException"): UncaughtExceptionListener[];
939 listeners(event: "unhandledRejection"): UnhandledRejectionListener[];
940 listeners(event: "warning"): WarningListener[];
941 listeners(event: "message"): MessageListener[];
942 listeners(event: Signals): SignalsListener[];
943 listeners(event: "newListener"): NewListenerListener[];
944 listeners(event: "removeListener"): RemoveListenerListener[];
945 listeners(event: "multipleResolves"): MultipleResolveListener[];
946 }
947
948 interface Global {
949 Array: typeof Array;
950 ArrayBuffer: typeof ArrayBuffer;
951 Boolean: typeof Boolean;
952 Buffer: typeof Buffer;
953 DataView: typeof DataView;
954 Date: typeof Date;
955 Error: typeof Error;
956 EvalError: typeof EvalError;
957 Float32Array: typeof Float32Array;
958 Float64Array: typeof Float64Array;
959 Function: typeof Function;
960 GLOBAL: Global;
961 Infinity: typeof Infinity;
962 Int16Array: typeof Int16Array;
963 Int32Array: typeof Int32Array;
964 Int8Array: typeof Int8Array;
965 Intl: typeof Intl;
966 JSON: typeof JSON;
967 Map: MapConstructor;
968 Math: typeof Math;
969 NaN: typeof NaN;
970 Number: typeof Number;
971 Object: typeof Object;
972 Promise: Function;
973 RangeError: typeof RangeError;
974 ReferenceError: typeof ReferenceError;
975 RegExp: typeof RegExp;
976 Set: SetConstructor;
977 String: typeof String;
978 Symbol: Function;
979 SyntaxError: typeof SyntaxError;
980 TypeError: typeof TypeError;
981 URIError: typeof URIError;
982 Uint16Array: typeof Uint16Array;
983 Uint32Array: typeof Uint32Array;
984 Uint8Array: typeof Uint8Array;
985 Uint8ClampedArray: Function;
986 WeakMap: WeakMapConstructor;
987 WeakSet: WeakSetConstructor;
988 clearImmediate: (immediateId: Immediate) => void;
989 clearInterval: (intervalId: Timeout) => void;
990 clearTimeout: (timeoutId: Timeout) => void;
991 console: typeof console;
992 decodeURI: typeof decodeURI;
993 decodeURIComponent: typeof decodeURIComponent;
994 encodeURI: typeof encodeURI;
995 encodeURIComponent: typeof encodeURIComponent;
996 escape: (str: string) => string;
997 eval: typeof eval;
998 global: Global;
999 isFinite: typeof isFinite;
1000 isNaN: typeof isNaN;
1001 parseFloat: typeof parseFloat;
1002 parseInt: typeof parseInt;
1003 process: Process;
1004 root: Global;
1005 setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => Immediate;
1006 setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => Timeout;
1007 setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => Timeout;
1008 undefined: typeof undefined;
1009 unescape: (str: string) => string;
1010 gc: () => void;
1011 v8debug?: any;
1012 }
1013
1014 interface Timer {
1015 ref(): this;
1016 refresh(): this;
1017 unref(): this;
1018 }
1019
1020 class Immediate {
1021 ref(): this;
1022 refresh(): this;
1023 unref(): this;
1024 _onImmediate: Function; // to distinguish it from the Timeout class
1025 }
1026
1027 class Timeout implements Timer {
1028 ref(): this;
1029 refresh(): this;
1030 unref(): this;
1031 }
1032
1033 class Module {
1034 static runMain(): void;
1035 static wrap(code: string): string;
1036 static createRequireFromPath(path: string): (path: string) => any;
1037 static builtinModules: string[];
1038
1039 static Module: typeof Module;
1040
1041 exports: any;
1042 require: NodeRequireFunction;
1043 id: string;
1044 filename: string;
1045 loaded: boolean;
1046 parent: Module | null;
1047 children: Module[];
1048 paths: string[];
1049
1050 constructor(id: string, parent?: Module);
1051 }
1052
1053 type TypedArray =
1054 | Uint8Array
1055 | Uint8ClampedArray
1056 | Uint16Array
1057 | Uint32Array
1058 | Int8Array
1059 | Int16Array
1060 | Int32Array
1061 | BigUint64Array
1062 | BigInt64Array
1063 | Float32Array
1064 | Float64Array;
1065 type ArrayBufferView = TypedArray | DataView;
1066}