UNPKG

41.8 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 Process extends EventEmitter {
716 stdout: WriteStream;
717 stderr: WriteStream;
718 stdin: ReadStream;
719 openStdin(): Socket;
720 argv: string[];
721 argv0: string;
722 execArgv: string[];
723 execPath: string;
724 abort(): never;
725 chdir(directory: string): void;
726 cwd(): string;
727 debugPort: number;
728 emitWarning(warning: string | Error, name?: string, ctor?: Function): void;
729 env: ProcessEnv;
730 exit(code?: number): never;
731 exitCode?: number;
732 getgid(): number;
733 setgid(id: number | string): void;
734 getuid(): number;
735 setuid(id: number | string): void;
736 geteuid(): number;
737 seteuid(id: number | string): void;
738 getegid(): number;
739 setegid(id: number | string): void;
740 getgroups(): number[];
741 setgroups(groups: ReadonlyArray<string | number>): void;
742 setUncaughtExceptionCaptureCallback(cb: ((err: Error) => void) | null): void;
743 hasUncaughtExceptionCaptureCallback(): boolean;
744 version: string;
745 versions: ProcessVersions;
746 config: {
747 target_defaults: {
748 cflags: any[];
749 default_configuration: string;
750 defines: string[];
751 include_dirs: string[];
752 libraries: string[];
753 };
754 variables: {
755 clang: number;
756 host_arch: string;
757 node_install_npm: boolean;
758 node_install_waf: boolean;
759 node_prefix: string;
760 node_shared_openssl: boolean;
761 node_shared_v8: boolean;
762 node_shared_zlib: boolean;
763 node_use_dtrace: boolean;
764 node_use_etw: boolean;
765 node_use_openssl: boolean;
766 target_arch: string;
767 v8_no_strict_aliasing: number;
768 v8_use_snapshot: boolean;
769 visibility: string;
770 };
771 };
772 kill(pid: number, signal?: string | number): void;
773 pid: number;
774 ppid: number;
775 title: string;
776 arch: string;
777 platform: Platform;
778 mainModule?: NodeModule;
779 memoryUsage(): MemoryUsage;
780 cpuUsage(previousValue?: CpuUsage): CpuUsage;
781 nextTick(callback: Function, ...args: any[]): void;
782 release: ProcessRelease;
783 umask(mask?: number): number;
784 uptime(): number;
785 hrtime: HRTime;
786 domain: Domain;
787
788 // Worker
789 send?(message: any, sendHandle?: any): void;
790 disconnect(): void;
791 connected: boolean;
792
793 /**
794 * The `process.allowedNodeEnvironmentFlags` property is a special,
795 * read-only `Set` of flags allowable within the [`NODE_OPTIONS`][]
796 * environment variable.
797 */
798 allowedNodeEnvironmentFlags: ReadonlySet<string>;
799
800 /**
801 * EventEmitter
802 * 1. beforeExit
803 * 2. disconnect
804 * 3. exit
805 * 4. message
806 * 5. rejectionHandled
807 * 6. uncaughtException
808 * 7. unhandledRejection
809 * 8. warning
810 * 9. message
811 * 10. <All OS Signals>
812 * 11. newListener/removeListener inherited from EventEmitter
813 */
814 addListener(event: "beforeExit", listener: BeforeExitListener): this;
815 addListener(event: "disconnect", listener: DisconnectListener): this;
816 addListener(event: "exit", listener: ExitListener): this;
817 addListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
818 addListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
819 addListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
820 addListener(event: "warning", listener: WarningListener): this;
821 addListener(event: "message", listener: MessageListener): this;
822 addListener(event: Signals, listener: SignalsListener): this;
823 addListener(event: "newListener", listener: NewListenerListener): this;
824 addListener(event: "removeListener", listener: RemoveListenerListener): this;
825 addListener(event: "multipleResolves", listener: MultipleResolveListener): this;
826
827 emit(event: "beforeExit", code: number): boolean;
828 emit(event: "disconnect"): boolean;
829 emit(event: "exit", code: number): boolean;
830 emit(event: "rejectionHandled", promise: Promise<any>): boolean;
831 emit(event: "uncaughtException", error: Error): boolean;
832 emit(event: "unhandledRejection", reason: any, promise: Promise<any>): boolean;
833 emit(event: "warning", warning: Error): boolean;
834 emit(event: "message", message: any, sendHandle: any): this;
835 emit(event: Signals, signal: Signals): boolean;
836 emit(event: "newListener", eventName: string | symbol, listener: (...args: any[]) => void): this;
837 emit(event: "removeListener", eventName: string, listener: (...args: any[]) => void): this;
838 emit(event: "multipleResolves", listener: MultipleResolveListener): this;
839
840 on(event: "beforeExit", listener: BeforeExitListener): this;
841 on(event: "disconnect", listener: DisconnectListener): this;
842 on(event: "exit", listener: ExitListener): this;
843 on(event: "rejectionHandled", listener: RejectionHandledListener): this;
844 on(event: "uncaughtException", listener: UncaughtExceptionListener): this;
845 on(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
846 on(event: "warning", listener: WarningListener): this;
847 on(event: "message", listener: MessageListener): this;
848 on(event: Signals, listener: SignalsListener): this;
849 on(event: "newListener", listener: NewListenerListener): this;
850 on(event: "removeListener", listener: RemoveListenerListener): this;
851 on(event: "multipleResolves", listener: MultipleResolveListener): this;
852 on(event: string | symbol, listener: (...args: any[]) => void): this;
853
854 once(event: "beforeExit", listener: BeforeExitListener): this;
855 once(event: "disconnect", listener: DisconnectListener): this;
856 once(event: "exit", listener: ExitListener): this;
857 once(event: "rejectionHandled", listener: RejectionHandledListener): this;
858 once(event: "uncaughtException", listener: UncaughtExceptionListener): this;
859 once(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
860 once(event: "warning", listener: WarningListener): this;
861 once(event: "message", listener: MessageListener): this;
862 once(event: Signals, listener: SignalsListener): this;
863 once(event: "newListener", listener: NewListenerListener): this;
864 once(event: "removeListener", listener: RemoveListenerListener): this;
865 once(event: "multipleResolves", listener: MultipleResolveListener): this;
866
867 prependListener(event: "beforeExit", listener: BeforeExitListener): this;
868 prependListener(event: "disconnect", listener: DisconnectListener): this;
869 prependListener(event: "exit", listener: ExitListener): this;
870 prependListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
871 prependListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
872 prependListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
873 prependListener(event: "warning", listener: WarningListener): this;
874 prependListener(event: "message", listener: MessageListener): this;
875 prependListener(event: Signals, listener: SignalsListener): this;
876 prependListener(event: "newListener", listener: NewListenerListener): this;
877 prependListener(event: "removeListener", listener: RemoveListenerListener): this;
878 prependListener(event: "multipleResolves", listener: MultipleResolveListener): this;
879
880 prependOnceListener(event: "beforeExit", listener: BeforeExitListener): this;
881 prependOnceListener(event: "disconnect", listener: DisconnectListener): this;
882 prependOnceListener(event: "exit", listener: ExitListener): this;
883 prependOnceListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
884 prependOnceListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
885 prependOnceListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
886 prependOnceListener(event: "warning", listener: WarningListener): this;
887 prependOnceListener(event: "message", listener: MessageListener): this;
888 prependOnceListener(event: Signals, listener: SignalsListener): this;
889 prependOnceListener(event: "newListener", listener: NewListenerListener): this;
890 prependOnceListener(event: "removeListener", listener: RemoveListenerListener): this;
891 prependOnceListener(event: "multipleResolves", listener: MultipleResolveListener): this;
892
893 listeners(event: "beforeExit"): BeforeExitListener[];
894 listeners(event: "disconnect"): DisconnectListener[];
895 listeners(event: "exit"): ExitListener[];
896 listeners(event: "rejectionHandled"): RejectionHandledListener[];
897 listeners(event: "uncaughtException"): UncaughtExceptionListener[];
898 listeners(event: "unhandledRejection"): UnhandledRejectionListener[];
899 listeners(event: "warning"): WarningListener[];
900 listeners(event: "message"): MessageListener[];
901 listeners(event: Signals): SignalsListener[];
902 listeners(event: "newListener"): NewListenerListener[];
903 listeners(event: "removeListener"): RemoveListenerListener[];
904 listeners(event: "multipleResolves"): MultipleResolveListener[];
905 }
906
907 interface Global {
908 Array: typeof Array;
909 ArrayBuffer: typeof ArrayBuffer;
910 Boolean: typeof Boolean;
911 Buffer: typeof Buffer;
912 DataView: typeof DataView;
913 Date: typeof Date;
914 Error: typeof Error;
915 EvalError: typeof EvalError;
916 Float32Array: typeof Float32Array;
917 Float64Array: typeof Float64Array;
918 Function: typeof Function;
919 GLOBAL: Global;
920 Infinity: typeof Infinity;
921 Int16Array: typeof Int16Array;
922 Int32Array: typeof Int32Array;
923 Int8Array: typeof Int8Array;
924 Intl: typeof Intl;
925 JSON: typeof JSON;
926 Map: MapConstructor;
927 Math: typeof Math;
928 NaN: typeof NaN;
929 Number: typeof Number;
930 Object: typeof Object;
931 Promise: Function;
932 RangeError: typeof RangeError;
933 ReferenceError: typeof ReferenceError;
934 RegExp: typeof RegExp;
935 Set: SetConstructor;
936 String: typeof String;
937 Symbol: Function;
938 SyntaxError: typeof SyntaxError;
939 TypeError: typeof TypeError;
940 URIError: typeof URIError;
941 Uint16Array: typeof Uint16Array;
942 Uint32Array: typeof Uint32Array;
943 Uint8Array: typeof Uint8Array;
944 Uint8ClampedArray: Function;
945 WeakMap: WeakMapConstructor;
946 WeakSet: WeakSetConstructor;
947 clearImmediate: (immediateId: Immediate) => void;
948 clearInterval: (intervalId: Timeout) => void;
949 clearTimeout: (timeoutId: Timeout) => void;
950 console: typeof console;
951 decodeURI: typeof decodeURI;
952 decodeURIComponent: typeof decodeURIComponent;
953 encodeURI: typeof encodeURI;
954 encodeURIComponent: typeof encodeURIComponent;
955 escape: (str: string) => string;
956 eval: typeof eval;
957 global: Global;
958 isFinite: typeof isFinite;
959 isNaN: typeof isNaN;
960 parseFloat: typeof parseFloat;
961 parseInt: typeof parseInt;
962 process: Process;
963 root: Global;
964 setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => Immediate;
965 setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => Timeout;
966 setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => Timeout;
967 undefined: typeof undefined;
968 unescape: (str: string) => string;
969 gc: () => void;
970 v8debug?: any;
971 }
972
973 interface Timer {
974 ref(): this;
975 refresh(): this;
976 unref(): this;
977 }
978
979 class Immediate {
980 ref(): this;
981 refresh(): this;
982 unref(): this;
983 _onImmediate: Function; // to distinguish it from the Timeout class
984 }
985
986 class Timeout implements Timer {
987 ref(): this;
988 refresh(): this;
989 unref(): this;
990 }
991
992 class Module {
993 static runMain(): void;
994 static wrap(code: string): string;
995 static createRequireFromPath(path: string): (path: string) => any;
996 static builtinModules: string[];
997
998 static Module: typeof Module;
999
1000 exports: any;
1001 require: NodeRequireFunction;
1002 id: string;
1003 filename: string;
1004 loaded: boolean;
1005 parent: Module | null;
1006 children: Module[];
1007 paths: string[];
1008
1009 constructor(id: string, parent?: Module);
1010 }
1011
1012 type TypedArray =
1013 | Uint8Array
1014 | Uint8ClampedArray
1015 | Uint16Array
1016 | Uint32Array
1017 | Int8Array
1018 | Int16Array
1019 | Int32Array
1020 | BigUint64Array
1021 | BigInt64Array
1022 | Float32Array
1023 | Float64Array;
1024 type ArrayBufferView = TypedArray | DataView;
1025}