Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

globals.d.ts 44KB

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