090e686639c4a210717bd9c50c2431de181829d54cb30e7597d700061a2f99a7bf755bb16c8739655e8e80ad5507ff091fe03e5abc4ff9e03928dd900e8907 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311
  1. /**
  2. * The `node:util` module supports the needs of Node.js internal APIs. Many of the
  3. * utilities are useful for application and module developers as well. To access
  4. * it:
  5. *
  6. * ```js
  7. * import util from 'node:util';
  8. * ```
  9. * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/util.js)
  10. */
  11. declare module "util" {
  12. import * as types from "node:util/types";
  13. export interface InspectOptions {
  14. /**
  15. * If `true`, object's non-enumerable symbols and properties are included in the formatted result.
  16. * `WeakMap` and `WeakSet` entries are also included as well as user defined prototype properties (excluding method properties).
  17. * @default false
  18. */
  19. showHidden?: boolean | undefined;
  20. /**
  21. * Specifies the number of times to recurse while formatting object.
  22. * This is useful for inspecting large objects.
  23. * To recurse up to the maximum call stack size pass `Infinity` or `null`.
  24. * @default 2
  25. */
  26. depth?: number | null | undefined;
  27. /**
  28. * If `true`, the output is styled with ANSI color codes. Colors are customizable.
  29. */
  30. colors?: boolean | undefined;
  31. /**
  32. * If `false`, `[util.inspect.custom](depth, opts, inspect)` functions are not invoked.
  33. * @default true
  34. */
  35. customInspect?: boolean | undefined;
  36. /**
  37. * If `true`, `Proxy` inspection includes the target and handler objects.
  38. * @default false
  39. */
  40. showProxy?: boolean | undefined;
  41. /**
  42. * Specifies the maximum number of `Array`, `TypedArray`, `WeakMap`, and `WeakSet` elements
  43. * to include when formatting. Set to `null` or `Infinity` to show all elements.
  44. * Set to `0` or negative to show no elements.
  45. * @default 100
  46. */
  47. maxArrayLength?: number | null | undefined;
  48. /**
  49. * Specifies the maximum number of characters to
  50. * include when formatting. Set to `null` or `Infinity` to show all elements.
  51. * Set to `0` or negative to show no characters.
  52. * @default 10000
  53. */
  54. maxStringLength?: number | null | undefined;
  55. /**
  56. * The length at which input values are split across multiple lines.
  57. * Set to `Infinity` to format the input as a single line
  58. * (in combination with `compact` set to `true` or any number >= `1`).
  59. * @default 80
  60. */
  61. breakLength?: number | undefined;
  62. /**
  63. * Setting this to `false` causes each object key
  64. * to be displayed on a new line. It will also add new lines to text that is
  65. * longer than `breakLength`. If set to a number, the most `n` inner elements
  66. * are united on a single line as long as all properties fit into
  67. * `breakLength`. Short array elements are also grouped together. Note that no
  68. * text will be reduced below 16 characters, no matter the `breakLength` size.
  69. * For more information, see the example below.
  70. * @default true
  71. */
  72. compact?: boolean | number | undefined;
  73. /**
  74. * If set to `true` or a function, all properties of an object, and `Set` and `Map`
  75. * entries are sorted in the resulting string.
  76. * If set to `true` the default sort is used.
  77. * If set to a function, it is used as a compare function.
  78. */
  79. sorted?: boolean | ((a: string, b: string) => number) | undefined;
  80. /**
  81. * If set to `true`, getters are going to be
  82. * inspected as well. If set to `'get'` only getters without setter are going
  83. * to be inspected. If set to `'set'` only getters having a corresponding
  84. * setter are going to be inspected. This might cause side effects depending on
  85. * the getter function.
  86. * @default false
  87. */
  88. getters?: "get" | "set" | boolean | undefined;
  89. /**
  90. * If set to `true`, an underscore is used to separate every three digits in all bigints and numbers.
  91. * @default false
  92. */
  93. numericSeparator?: boolean | undefined;
  94. }
  95. export type Style =
  96. | "special"
  97. | "number"
  98. | "bigint"
  99. | "boolean"
  100. | "undefined"
  101. | "null"
  102. | "string"
  103. | "symbol"
  104. | "date"
  105. | "regexp"
  106. | "module";
  107. export type CustomInspectFunction = (depth: number, options: InspectOptionsStylized) => any; // TODO: , inspect: inspect
  108. export interface InspectOptionsStylized extends InspectOptions {
  109. stylize(text: string, styleType: Style): string;
  110. }
  111. export interface CallSiteObject {
  112. /**
  113. * Returns the name of the function associated with this call site.
  114. */
  115. functionName: string;
  116. /**
  117. * Returns the name of the resource that contains the script for the
  118. * function for this call site.
  119. */
  120. scriptName: string;
  121. /**
  122. * Returns the unique id of the script, as in Chrome DevTools protocol
  123. * [`Runtime.ScriptId`](https://chromedevtools.github.io/devtools-protocol/1-3/Runtime/#type-ScriptId).
  124. * @since v22.14.0
  125. */
  126. scriptId: string;
  127. /**
  128. * Returns the number, 1-based, of the line for the associate function call.
  129. */
  130. lineNumber: number;
  131. /**
  132. * Returns the 1-based column offset on the line for the associated function call.
  133. */
  134. columnNumber: number;
  135. }
  136. export type DiffEntry = [operation: -1 | 0 | 1, value: string];
  137. /**
  138. * `util.diff()` compares two string or array values and returns an array of difference entries.
  139. * It uses the Myers diff algorithm to compute minimal differences, which is the same algorithm
  140. * used internally by assertion error messages.
  141. *
  142. * If the values are equal, an empty array is returned.
  143. *
  144. * ```js
  145. * const { diff } = require('node:util');
  146. *
  147. * // Comparing strings
  148. * const actualString = '12345678';
  149. * const expectedString = '12!!5!7!';
  150. * console.log(diff(actualString, expectedString));
  151. * // [
  152. * // [0, '1'],
  153. * // [0, '2'],
  154. * // [1, '3'],
  155. * // [1, '4'],
  156. * // [-1, '!'],
  157. * // [-1, '!'],
  158. * // [0, '5'],
  159. * // [1, '6'],
  160. * // [-1, '!'],
  161. * // [0, '7'],
  162. * // [1, '8'],
  163. * // [-1, '!'],
  164. * // ]
  165. * // Comparing arrays
  166. * const actualArray = ['1', '2', '3'];
  167. * const expectedArray = ['1', '3', '4'];
  168. * console.log(diff(actualArray, expectedArray));
  169. * // [
  170. * // [0, '1'],
  171. * // [1, '2'],
  172. * // [0, '3'],
  173. * // [-1, '4'],
  174. * // ]
  175. * // Equal values return empty array
  176. * console.log(diff('same', 'same'));
  177. * // []
  178. * ```
  179. * @since v22.15.0
  180. * @experimental
  181. * @param actual The first value to compare
  182. * @param expected The second value to compare
  183. * @returns An array of difference entries. Each entry is an array with two elements:
  184. * * Index 0: `number` Operation code: `-1` for delete, `0` for no-op/unchanged, `1` for insert
  185. * * Index 1: `string` The value associated with the operation
  186. */
  187. export function diff(actual: string | readonly string[], expected: string | readonly string[]): DiffEntry[];
  188. /**
  189. * The `util.format()` method returns a formatted string using the first argument
  190. * as a `printf`-like format string which can contain zero or more format
  191. * specifiers. Each specifier is replaced with the converted value from the
  192. * corresponding argument. Supported specifiers are:
  193. *
  194. * If a specifier does not have a corresponding argument, it is not replaced:
  195. *
  196. * ```js
  197. * util.format('%s:%s', 'foo');
  198. * // Returns: 'foo:%s'
  199. * ```
  200. *
  201. * Values that are not part of the format string are formatted using `util.inspect()` if their type is not `string`.
  202. *
  203. * If there are more arguments passed to the `util.format()` method than the
  204. * number of specifiers, the extra arguments are concatenated to the returned
  205. * string, separated by spaces:
  206. *
  207. * ```js
  208. * util.format('%s:%s', 'foo', 'bar', 'baz');
  209. * // Returns: 'foo:bar baz'
  210. * ```
  211. *
  212. * If the first argument does not contain a valid format specifier, `util.format()` returns a string that is the concatenation of all arguments separated by spaces:
  213. *
  214. * ```js
  215. * util.format(1, 2, 3);
  216. * // Returns: '1 2 3'
  217. * ```
  218. *
  219. * If only one argument is passed to `util.format()`, it is returned as it is
  220. * without any formatting:
  221. *
  222. * ```js
  223. * util.format('%% %s');
  224. * // Returns: '%% %s'
  225. * ```
  226. *
  227. * `util.format()` is a synchronous method that is intended as a debugging tool.
  228. * Some input values can have a significant performance overhead that can block the
  229. * event loop. Use this function with care and never in a hot code path.
  230. * @since v0.5.3
  231. * @param format A `printf`-like format string.
  232. */
  233. export function format(format?: any, ...param: any[]): string;
  234. /**
  235. * This function is identical to {@link format}, except in that it takes
  236. * an `inspectOptions` argument which specifies options that are passed along to {@link inspect}.
  237. *
  238. * ```js
  239. * util.formatWithOptions({ colors: true }, 'See object %O', { foo: 42 });
  240. * // Returns 'See object { foo: 42 }', where `42` is colored as a number
  241. * // when printed to a terminal.
  242. * ```
  243. * @since v10.0.0
  244. */
  245. export function formatWithOptions(inspectOptions: InspectOptions, format?: any, ...param: any[]): string;
  246. interface GetCallSitesOptions {
  247. /**
  248. * Reconstruct the original location in the stacktrace from the source-map.
  249. * Enabled by default with the flag `--enable-source-maps`.
  250. */
  251. sourceMap?: boolean | undefined;
  252. }
  253. /**
  254. * Returns an array of call site objects containing the stack of
  255. * the caller function.
  256. *
  257. * ```js
  258. * import { getCallSites } from 'node:util';
  259. *
  260. * function exampleFunction() {
  261. * const callSites = getCallSites();
  262. *
  263. * console.log('Call Sites:');
  264. * callSites.forEach((callSite, index) => {
  265. * console.log(`CallSite ${index + 1}:`);
  266. * console.log(`Function Name: ${callSite.functionName}`);
  267. * console.log(`Script Name: ${callSite.scriptName}`);
  268. * console.log(`Line Number: ${callSite.lineNumber}`);
  269. * console.log(`Column Number: ${callSite.column}`);
  270. * });
  271. * // CallSite 1:
  272. * // Function Name: exampleFunction
  273. * // Script Name: /home/example.js
  274. * // Line Number: 5
  275. * // Column Number: 26
  276. *
  277. * // CallSite 2:
  278. * // Function Name: anotherFunction
  279. * // Script Name: /home/example.js
  280. * // Line Number: 22
  281. * // Column Number: 3
  282. *
  283. * // ...
  284. * }
  285. *
  286. * // A function to simulate another stack layer
  287. * function anotherFunction() {
  288. * exampleFunction();
  289. * }
  290. *
  291. * anotherFunction();
  292. * ```
  293. *
  294. * It is possible to reconstruct the original locations by setting the option `sourceMap` to `true`.
  295. * If the source map is not available, the original location will be the same as the current location.
  296. * When the `--enable-source-maps` flag is enabled, for example when using `--experimental-transform-types`,
  297. * `sourceMap` will be true by default.
  298. *
  299. * ```ts
  300. * import { getCallSites } from 'node:util';
  301. *
  302. * interface Foo {
  303. * foo: string;
  304. * }
  305. *
  306. * const callSites = getCallSites({ sourceMap: true });
  307. *
  308. * // With sourceMap:
  309. * // Function Name: ''
  310. * // Script Name: example.js
  311. * // Line Number: 7
  312. * // Column Number: 26
  313. *
  314. * // Without sourceMap:
  315. * // Function Name: ''
  316. * // Script Name: example.js
  317. * // Line Number: 2
  318. * // Column Number: 26
  319. * ```
  320. * @param frameCount Number of frames to capture as call site objects.
  321. * **Default:** `10`. Allowable range is between 1 and 200.
  322. * @return An array of call site objects
  323. * @since v22.9.0
  324. */
  325. export function getCallSites(frameCount?: number, options?: GetCallSitesOptions): CallSiteObject[];
  326. export function getCallSites(options: GetCallSitesOptions): CallSiteObject[];
  327. /**
  328. * Returns the string name for a numeric error code that comes from a Node.js API.
  329. * The mapping between error codes and error names is platform-dependent.
  330. * See `Common System Errors` for the names of common errors.
  331. *
  332. * ```js
  333. * fs.access('file/that/does/not/exist', (err) => {
  334. * const name = util.getSystemErrorName(err.errno);
  335. * console.error(name); // ENOENT
  336. * });
  337. * ```
  338. * @since v9.7.0
  339. */
  340. export function getSystemErrorName(err: number): string;
  341. /**
  342. * Returns a Map of all system error codes available from the Node.js API.
  343. * The mapping between error codes and error names is platform-dependent.
  344. * See `Common System Errors` for the names of common errors.
  345. *
  346. * ```js
  347. * fs.access('file/that/does/not/exist', (err) => {
  348. * const errorMap = util.getSystemErrorMap();
  349. * const name = errorMap.get(err.errno);
  350. * console.error(name); // ENOENT
  351. * });
  352. * ```
  353. * @since v16.0.0, v14.17.0
  354. */
  355. export function getSystemErrorMap(): Map<number, [string, string]>;
  356. /**
  357. * Returns the string message for a numeric error code that comes from a Node.js
  358. * API.
  359. * The mapping between error codes and string messages is platform-dependent.
  360. *
  361. * ```js
  362. * fs.access('file/that/does/not/exist', (err) => {
  363. * const message = util.getSystemErrorMessage(err.errno);
  364. * console.error(message); // no such file or directory
  365. * });
  366. * ```
  367. * @since v22.12.0
  368. */
  369. export function getSystemErrorMessage(err: number): string;
  370. /**
  371. * Returns the `string` after replacing any surrogate code points
  372. * (or equivalently, any unpaired surrogate code units) with the
  373. * Unicode "replacement character" U+FFFD.
  374. * @since v16.8.0, v14.18.0
  375. */
  376. export function toUSVString(string: string): string;
  377. /**
  378. * Creates and returns an `AbortController` instance whose `AbortSignal` is marked
  379. * as transferable and can be used with `structuredClone()` or `postMessage()`.
  380. * @since v18.11.0
  381. * @returns A transferable AbortController
  382. */
  383. export function transferableAbortController(): AbortController;
  384. /**
  385. * Marks the given `AbortSignal` as transferable so that it can be used with`structuredClone()` and `postMessage()`.
  386. *
  387. * ```js
  388. * const signal = transferableAbortSignal(AbortSignal.timeout(100));
  389. * const channel = new MessageChannel();
  390. * channel.port2.postMessage(signal, [signal]);
  391. * ```
  392. * @since v18.11.0
  393. * @param signal The AbortSignal
  394. * @returns The same AbortSignal
  395. */
  396. export function transferableAbortSignal(signal: AbortSignal): AbortSignal;
  397. /**
  398. * Listens to abort event on the provided `signal` and returns a promise that resolves when the `signal` is aborted.
  399. * If `resource` is provided, it weakly references the operation's associated object,
  400. * so if `resource` is garbage collected before the `signal` aborts,
  401. * then returned promise shall remain pending.
  402. * This prevents memory leaks in long-running or non-cancelable operations.
  403. *
  404. * ```js
  405. * import { aborted } from 'node:util';
  406. *
  407. * // Obtain an object with an abortable signal, like a custom resource or operation.
  408. * const dependent = obtainSomethingAbortable();
  409. *
  410. * // Pass `dependent` as the resource, indicating the promise should only resolve
  411. * // if `dependent` is still in memory when the signal is aborted.
  412. * aborted(dependent.signal, dependent).then(() => {
  413. * // This code runs when `dependent` is aborted.
  414. * console.log('Dependent resource was aborted.');
  415. * });
  416. *
  417. * // Simulate an event that triggers the abort.
  418. * dependent.on('event', () => {
  419. * dependent.abort(); // This will cause the `aborted` promise to resolve.
  420. * });
  421. * ```
  422. * @since v19.7.0
  423. * @param resource Any non-null object tied to the abortable operation and held weakly.
  424. * If `resource` is garbage collected before the `signal` aborts, the promise remains pending,
  425. * allowing Node.js to stop tracking it.
  426. * This helps prevent memory leaks in long-running or non-cancelable operations.
  427. */
  428. export function aborted(signal: AbortSignal, resource: any): Promise<void>;
  429. /**
  430. * The `util.inspect()` method returns a string representation of `object` that is
  431. * intended for debugging. The output of `util.inspect` may change at any time
  432. * and should not be depended upon programmatically. Additional `options` may be
  433. * passed that alter the result.
  434. * `util.inspect()` will use the constructor's name and/or `Symbol.toStringTag`
  435. * property to make an identifiable tag for an inspected value.
  436. *
  437. * ```js
  438. * class Foo {
  439. * get [Symbol.toStringTag]() {
  440. * return 'bar';
  441. * }
  442. * }
  443. *
  444. * class Bar {}
  445. *
  446. * const baz = Object.create(null, { [Symbol.toStringTag]: { value: 'foo' } });
  447. *
  448. * util.inspect(new Foo()); // 'Foo [bar] {}'
  449. * util.inspect(new Bar()); // 'Bar {}'
  450. * util.inspect(baz); // '[foo] {}'
  451. * ```
  452. *
  453. * Circular references point to their anchor by using a reference index:
  454. *
  455. * ```js
  456. * import { inspect } from 'node:util';
  457. *
  458. * const obj = {};
  459. * obj.a = [obj];
  460. * obj.b = {};
  461. * obj.b.inner = obj.b;
  462. * obj.b.obj = obj;
  463. *
  464. * console.log(inspect(obj));
  465. * // <ref *1> {
  466. * // a: [ [Circular *1] ],
  467. * // b: <ref *2> { inner: [Circular *2], obj: [Circular *1] }
  468. * // }
  469. * ```
  470. *
  471. * The following example inspects all properties of the `util` object:
  472. *
  473. * ```js
  474. * import util from 'node:util';
  475. *
  476. * console.log(util.inspect(util, { showHidden: true, depth: null }));
  477. * ```
  478. *
  479. * The following example highlights the effect of the `compact` option:
  480. *
  481. * ```js
  482. * import { inspect } from 'node:util';
  483. *
  484. * const o = {
  485. * a: [1, 2, [[
  486. * 'Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit, sed do ' +
  487. * 'eiusmod \ntempor incididunt ut labore et dolore magna aliqua.',
  488. * 'test',
  489. * 'foo']], 4],
  490. * b: new Map([['za', 1], ['zb', 'test']]),
  491. * };
  492. * console.log(inspect(o, { compact: true, depth: 5, breakLength: 80 }));
  493. *
  494. * // { a:
  495. * // [ 1,
  496. * // 2,
  497. * // [ [ 'Lorem ipsum dolor sit amet,\nconsectetur [...]', // A long line
  498. * // 'test',
  499. * // 'foo' ] ],
  500. * // 4 ],
  501. * // b: Map(2) { 'za' => 1, 'zb' => 'test' } }
  502. *
  503. * // Setting `compact` to false or an integer creates more reader friendly output.
  504. * console.log(inspect(o, { compact: false, depth: 5, breakLength: 80 }));
  505. *
  506. * // {
  507. * // a: [
  508. * // 1,
  509. * // 2,
  510. * // [
  511. * // [
  512. * // 'Lorem ipsum dolor sit amet,\n' +
  513. * // 'consectetur adipiscing elit, sed do eiusmod \n' +
  514. * // 'tempor incididunt ut labore et dolore magna aliqua.',
  515. * // 'test',
  516. * // 'foo'
  517. * // ]
  518. * // ],
  519. * // 4
  520. * // ],
  521. * // b: Map(2) {
  522. * // 'za' => 1,
  523. * // 'zb' => 'test'
  524. * // }
  525. * // }
  526. *
  527. * // Setting `breakLength` to e.g. 150 will print the "Lorem ipsum" text in a
  528. * // single line.
  529. * ```
  530. *
  531. * The `showHidden` option allows `WeakMap` and `WeakSet` entries to be
  532. * inspected. If there are more entries than `maxArrayLength`, there is no
  533. * guarantee which entries are displayed. That means retrieving the same
  534. * `WeakSet` entries twice may result in different output. Furthermore, entries
  535. * with no remaining strong references may be garbage collected at any time.
  536. *
  537. * ```js
  538. * import { inspect } from 'node:util';
  539. *
  540. * const obj = { a: 1 };
  541. * const obj2 = { b: 2 };
  542. * const weakSet = new WeakSet([obj, obj2]);
  543. *
  544. * console.log(inspect(weakSet, { showHidden: true }));
  545. * // WeakSet { { a: 1 }, { b: 2 } }
  546. * ```
  547. *
  548. * The `sorted` option ensures that an object's property insertion order does not
  549. * impact the result of `util.inspect()`.
  550. *
  551. * ```js
  552. * import { inspect } from 'node:util';
  553. * import assert from 'node:assert';
  554. *
  555. * const o1 = {
  556. * b: [2, 3, 1],
  557. * a: '`a` comes before `b`',
  558. * c: new Set([2, 3, 1]),
  559. * };
  560. * console.log(inspect(o1, { sorted: true }));
  561. * // { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set(3) { 1, 2, 3 } }
  562. * console.log(inspect(o1, { sorted: (a, b) => b.localeCompare(a) }));
  563. * // { c: Set(3) { 3, 2, 1 }, b: [ 2, 3, 1 ], a: '`a` comes before `b`' }
  564. *
  565. * const o2 = {
  566. * c: new Set([2, 1, 3]),
  567. * a: '`a` comes before `b`',
  568. * b: [2, 3, 1],
  569. * };
  570. * assert.strict.equal(
  571. * inspect(o1, { sorted: true }),
  572. * inspect(o2, { sorted: true }),
  573. * );
  574. * ```
  575. *
  576. * The `numericSeparator` option adds an underscore every three digits to all
  577. * numbers.
  578. *
  579. * ```js
  580. * import { inspect } from 'node:util';
  581. *
  582. * const thousand = 1000;
  583. * const million = 1000000;
  584. * const bigNumber = 123456789n;
  585. * const bigDecimal = 1234.12345;
  586. *
  587. * console.log(inspect(thousand, { numericSeparator: true }));
  588. * // 1_000
  589. * console.log(inspect(million, { numericSeparator: true }));
  590. * // 1_000_000
  591. * console.log(inspect(bigNumber, { numericSeparator: true }));
  592. * // 123_456_789n
  593. * console.log(inspect(bigDecimal, { numericSeparator: true }));
  594. * // 1_234.123_45
  595. * ```
  596. *
  597. * `util.inspect()` is a synchronous method intended for debugging. Its maximum
  598. * output length is approximately 128 MiB. Inputs that result in longer output will
  599. * be truncated.
  600. * @since v0.3.0
  601. * @param object Any JavaScript primitive or `Object`.
  602. * @return The representation of `object`.
  603. */
  604. export function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
  605. export function inspect(object: any, options?: InspectOptions): string;
  606. export namespace inspect {
  607. let colors: NodeJS.Dict<[number, number]>;
  608. let styles: {
  609. [K in Style]: string;
  610. };
  611. let defaultOptions: InspectOptions;
  612. /**
  613. * Allows changing inspect settings from the repl.
  614. */
  615. let replDefaults: InspectOptions;
  616. /**
  617. * That can be used to declare custom inspect functions.
  618. */
  619. const custom: unique symbol;
  620. }
  621. /**
  622. * Alias for [`Array.isArray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray).
  623. *
  624. * Returns `true` if the given `object` is an `Array`. Otherwise, returns `false`.
  625. *
  626. * ```js
  627. * import util from 'node:util';
  628. *
  629. * util.isArray([]);
  630. * // Returns: true
  631. * util.isArray(new Array());
  632. * // Returns: true
  633. * util.isArray({});
  634. * // Returns: false
  635. * ```
  636. * @since v0.6.0
  637. * @deprecated Since v4.0.0 - Use `isArray` instead.
  638. */
  639. export function isArray(object: unknown): object is unknown[];
  640. /**
  641. * Usage of `util.inherits()` is discouraged. Please use the ES6 `class` and
  642. * `extends` keywords to get language level inheritance support. Also note
  643. * that the two styles are [semantically incompatible](https://github.com/nodejs/node/issues/4179).
  644. *
  645. * Inherit the prototype methods from one
  646. * [constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor) into another. The
  647. * prototype of `constructor` will be set to a new object created from
  648. * `superConstructor`.
  649. *
  650. * This mainly adds some input validation on top of
  651. * `Object.setPrototypeOf(constructor.prototype, superConstructor.prototype)`.
  652. * As an additional convenience, `superConstructor` will be accessible
  653. * through the `constructor.super_` property.
  654. *
  655. * ```js
  656. * const util = require('node:util');
  657. * const EventEmitter = require('node:events');
  658. *
  659. * function MyStream() {
  660. * EventEmitter.call(this);
  661. * }
  662. *
  663. * util.inherits(MyStream, EventEmitter);
  664. *
  665. * MyStream.prototype.write = function(data) {
  666. * this.emit('data', data);
  667. * };
  668. *
  669. * const stream = new MyStream();
  670. *
  671. * console.log(stream instanceof EventEmitter); // true
  672. * console.log(MyStream.super_ === EventEmitter); // true
  673. *
  674. * stream.on('data', (data) => {
  675. * console.log(`Received data: "${data}"`);
  676. * });
  677. * stream.write('It works!'); // Received data: "It works!"
  678. * ```
  679. *
  680. * ES6 example using `class` and `extends`:
  681. *
  682. * ```js
  683. * import EventEmitter from 'node:events';
  684. *
  685. * class MyStream extends EventEmitter {
  686. * write(data) {
  687. * this.emit('data', data);
  688. * }
  689. * }
  690. *
  691. * const stream = new MyStream();
  692. *
  693. * stream.on('data', (data) => {
  694. * console.log(`Received data: "${data}"`);
  695. * });
  696. * stream.write('With ES6');
  697. * ```
  698. * @since v0.3.0
  699. * @legacy Use ES2015 class syntax and `extends` keyword instead.
  700. */
  701. export function inherits(constructor: unknown, superConstructor: unknown): void;
  702. export type DebugLoggerFunction = (msg: string, ...param: unknown[]) => void;
  703. export interface DebugLogger extends DebugLoggerFunction {
  704. /**
  705. * The `util.debuglog().enabled` getter is used to create a test that can be used
  706. * in conditionals based on the existence of the `NODE_DEBUG` environment variable.
  707. * If the `section` name appears within the value of that environment variable,
  708. * then the returned value will be `true`. If not, then the returned value will be
  709. * `false`.
  710. *
  711. * ```js
  712. * import { debuglog } from 'node:util';
  713. * const enabled = debuglog('foo').enabled;
  714. * if (enabled) {
  715. * console.log('hello from foo [%d]', 123);
  716. * }
  717. * ```
  718. *
  719. * If this program is run with `NODE_DEBUG=foo` in the environment, then it will
  720. * output something like:
  721. *
  722. * ```console
  723. * hello from foo [123]
  724. * ```
  725. */
  726. enabled: boolean;
  727. }
  728. /**
  729. * The `util.debuglog()` method is used to create a function that conditionally
  730. * writes debug messages to `stderr` based on the existence of the `NODE_DEBUG`
  731. * environment variable. If the `section` name appears within the value of that
  732. * environment variable, then the returned function operates similar to
  733. * `console.error()`. If not, then the returned function is a no-op.
  734. *
  735. * ```js
  736. * import { debuglog } from 'node:util';
  737. * const log = debuglog('foo');
  738. *
  739. * log('hello from foo [%d]', 123);
  740. * ```
  741. *
  742. * If this program is run with `NODE_DEBUG=foo` in the environment, then
  743. * it will output something like:
  744. *
  745. * ```console
  746. * FOO 3245: hello from foo [123]
  747. * ```
  748. *
  749. * where `3245` is the process id. If it is not run with that
  750. * environment variable set, then it will not print anything.
  751. *
  752. * The `section` supports wildcard also:
  753. *
  754. * ```js
  755. * import { debuglog } from 'node:util';
  756. * const log = debuglog('foo');
  757. *
  758. * log('hi there, it\'s foo-bar [%d]', 2333);
  759. * ```
  760. *
  761. * if it is run with `NODE_DEBUG=foo*` in the environment, then it will output
  762. * something like:
  763. *
  764. * ```console
  765. * FOO-BAR 3257: hi there, it's foo-bar [2333]
  766. * ```
  767. *
  768. * Multiple comma-separated `section` names may be specified in the `NODE_DEBUG`
  769. * environment variable: `NODE_DEBUG=fs,net,tls`.
  770. *
  771. * The optional `callback` argument can be used to replace the logging function
  772. * with a different function that doesn't have any initialization or
  773. * unnecessary wrapping.
  774. *
  775. * ```js
  776. * import { debuglog } from 'node:util';
  777. * let log = debuglog('internals', (debug) => {
  778. * // Replace with a logging function that optimizes out
  779. * // testing if the section is enabled
  780. * log = debug;
  781. * });
  782. * ```
  783. * @since v0.11.3
  784. * @param section A string identifying the portion of the application for which the `debuglog` function is being created.
  785. * @param callback A callback invoked the first time the logging function is called with a function argument that is a more optimized logging function.
  786. * @return The logging function
  787. */
  788. export function debuglog(section: string, callback?: (fn: DebugLoggerFunction) => void): DebugLogger;
  789. export { debuglog as debug };
  790. /**
  791. * The `util.deprecate()` method wraps `fn` (which may be a function or class) in
  792. * such a way that it is marked as deprecated.
  793. *
  794. * ```js
  795. * import { deprecate } from 'node:util';
  796. *
  797. * export const obsoleteFunction = deprecate(() => {
  798. * // Do something here.
  799. * }, 'obsoleteFunction() is deprecated. Use newShinyFunction() instead.');
  800. * ```
  801. *
  802. * When called, `util.deprecate()` will return a function that will emit a
  803. * `DeprecationWarning` using the `'warning'` event. The warning will
  804. * be emitted and printed to `stderr` the first time the returned function is
  805. * called. After the warning is emitted, the wrapped function is called without
  806. * emitting a warning.
  807. *
  808. * If the same optional `code` is supplied in multiple calls to `util.deprecate()`,
  809. * the warning will be emitted only once for that `code`.
  810. *
  811. * ```js
  812. * import { deprecate } from 'node:util';
  813. *
  814. * const fn1 = deprecate(
  815. * () => 'a value',
  816. * 'deprecation message',
  817. * 'DEP0001',
  818. * );
  819. * const fn2 = deprecate(
  820. * () => 'a different value',
  821. * 'other dep message',
  822. * 'DEP0001',
  823. * );
  824. * fn1(); // Emits a deprecation warning with code DEP0001
  825. * fn2(); // Does not emit a deprecation warning because it has the same code
  826. * ```
  827. *
  828. * If either the `--no-deprecation` or `--no-warnings` command-line flags are
  829. * used, or if the `process.noDeprecation` property is set to `true` _prior_ to
  830. * the first deprecation warning, the `util.deprecate()` method does nothing.
  831. *
  832. * If the `--trace-deprecation` or `--trace-warnings` command-line flags are set,
  833. * or the `process.traceDeprecation` property is set to `true`, a warning and a
  834. * stack trace are printed to `stderr` the first time the deprecated function is
  835. * called.
  836. *
  837. * If the `--throw-deprecation` command-line flag is set, or the
  838. * `process.throwDeprecation` property is set to `true`, then an exception will be
  839. * thrown when the deprecated function is called.
  840. *
  841. * The `--throw-deprecation` command-line flag and `process.throwDeprecation`
  842. * property take precedence over `--trace-deprecation` and
  843. * `process.traceDeprecation`.
  844. * @since v0.8.0
  845. * @param fn The function that is being deprecated.
  846. * @param msg A warning message to display when the deprecated function is invoked.
  847. * @param code A deprecation code. See the `list of deprecated APIs` for a list of codes.
  848. * @return The deprecated function wrapped to emit a warning.
  849. */
  850. export function deprecate<T extends Function>(fn: T, msg: string, code?: string): T;
  851. /**
  852. * Returns `true` if there is deep strict equality between `val1` and `val2`.
  853. * Otherwise, returns `false`.
  854. *
  855. * See `assert.deepStrictEqual()` for more information about deep strict
  856. * equality.
  857. * @since v9.0.0
  858. */
  859. export function isDeepStrictEqual(val1: unknown, val2: unknown): boolean;
  860. /**
  861. * Returns `str` with any ANSI escape codes removed.
  862. *
  863. * ```js
  864. * console.log(util.stripVTControlCharacters('\u001B[4mvalue\u001B[0m'));
  865. * // Prints "value"
  866. * ```
  867. * @since v16.11.0
  868. */
  869. export function stripVTControlCharacters(str: string): string;
  870. /**
  871. * Takes an `async` function (or a function that returns a `Promise`) and returns a
  872. * function following the error-first callback style, i.e. taking
  873. * an `(err, value) => ...` callback as the last argument. In the callback, the
  874. * first argument will be the rejection reason (or `null` if the `Promise`
  875. * resolved), and the second argument will be the resolved value.
  876. *
  877. * ```js
  878. * import { callbackify } from 'node:util';
  879. *
  880. * async function fn() {
  881. * return 'hello world';
  882. * }
  883. * const callbackFunction = callbackify(fn);
  884. *
  885. * callbackFunction((err, ret) => {
  886. * if (err) throw err;
  887. * console.log(ret);
  888. * });
  889. * ```
  890. *
  891. * Will print:
  892. *
  893. * ```text
  894. * hello world
  895. * ```
  896. *
  897. * The callback is executed asynchronously, and will have a limited stack trace.
  898. * If the callback throws, the process will emit an `'uncaughtException'`
  899. * event, and if not handled will exit.
  900. *
  901. * Since `null` has a special meaning as the first argument to a callback, if a
  902. * wrapped function rejects a `Promise` with a falsy value as a reason, the value
  903. * is wrapped in an `Error` with the original value stored in a field named
  904. * `reason`.
  905. *
  906. * ```js
  907. * function fn() {
  908. * return Promise.reject(null);
  909. * }
  910. * const callbackFunction = util.callbackify(fn);
  911. *
  912. * callbackFunction((err, ret) => {
  913. * // When the Promise was rejected with `null` it is wrapped with an Error and
  914. * // the original value is stored in `reason`.
  915. * err && Object.hasOwn(err, 'reason') && err.reason === null; // true
  916. * });
  917. * ```
  918. * @since v8.2.0
  919. * @param fn An `async` function
  920. * @return a callback style function
  921. */
  922. export function callbackify(fn: () => Promise<void>): (callback: (err: NodeJS.ErrnoException) => void) => void;
  923. export function callbackify<TResult>(
  924. fn: () => Promise<TResult>,
  925. ): (callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
  926. export function callbackify<T1>(
  927. fn: (arg1: T1) => Promise<void>,
  928. ): (arg1: T1, callback: (err: NodeJS.ErrnoException) => void) => void;
  929. export function callbackify<T1, TResult>(
  930. fn: (arg1: T1) => Promise<TResult>,
  931. ): (arg1: T1, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
  932. export function callbackify<T1, T2>(
  933. fn: (arg1: T1, arg2: T2) => Promise<void>,
  934. ): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException) => void) => void;
  935. export function callbackify<T1, T2, TResult>(
  936. fn: (arg1: T1, arg2: T2) => Promise<TResult>,
  937. ): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
  938. export function callbackify<T1, T2, T3>(
  939. fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<void>,
  940. ): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException) => void) => void;
  941. export function callbackify<T1, T2, T3, TResult>(
  942. fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>,
  943. ): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
  944. export function callbackify<T1, T2, T3, T4>(
  945. fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>,
  946. ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException) => void) => void;
  947. export function callbackify<T1, T2, T3, T4, TResult>(
  948. fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>,
  949. ): (
  950. arg1: T1,
  951. arg2: T2,
  952. arg3: T3,
  953. arg4: T4,
  954. callback: (err: NodeJS.ErrnoException | null, result: TResult) => void,
  955. ) => void;
  956. export function callbackify<T1, T2, T3, T4, T5>(
  957. fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>,
  958. ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException) => void) => void;
  959. export function callbackify<T1, T2, T3, T4, T5, TResult>(
  960. fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>,
  961. ): (
  962. arg1: T1,
  963. arg2: T2,
  964. arg3: T3,
  965. arg4: T4,
  966. arg5: T5,
  967. callback: (err: NodeJS.ErrnoException | null, result: TResult) => void,
  968. ) => void;
  969. export function callbackify<T1, T2, T3, T4, T5, T6>(
  970. fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<void>,
  971. ): (
  972. arg1: T1,
  973. arg2: T2,
  974. arg3: T3,
  975. arg4: T4,
  976. arg5: T5,
  977. arg6: T6,
  978. callback: (err: NodeJS.ErrnoException) => void,
  979. ) => void;
  980. export function callbackify<T1, T2, T3, T4, T5, T6, TResult>(
  981. fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<TResult>,
  982. ): (
  983. arg1: T1,
  984. arg2: T2,
  985. arg3: T3,
  986. arg4: T4,
  987. arg5: T5,
  988. arg6: T6,
  989. callback: (err: NodeJS.ErrnoException | null, result: TResult) => void,
  990. ) => void;
  991. export interface CustomPromisifyLegacy<TCustom extends Function> extends Function {
  992. __promisify__: TCustom;
  993. }
  994. export interface CustomPromisifySymbol<TCustom extends Function> extends Function {
  995. [promisify.custom]: TCustom;
  996. }
  997. export type CustomPromisify<TCustom extends Function> =
  998. | CustomPromisifySymbol<TCustom>
  999. | CustomPromisifyLegacy<TCustom>;
  1000. /**
  1001. * Takes a function following the common error-first callback style, i.e. taking
  1002. * an `(err, value) => ...` callback as the last argument, and returns a version
  1003. * that returns promises.
  1004. *
  1005. * ```js
  1006. * import { promisify } from 'node:util';
  1007. * import { stat } from 'node:fs';
  1008. *
  1009. * const promisifiedStat = promisify(stat);
  1010. * promisifiedStat('.').then((stats) => {
  1011. * // Do something with `stats`
  1012. * }).catch((error) => {
  1013. * // Handle the error.
  1014. * });
  1015. * ```
  1016. *
  1017. * Or, equivalently using `async function`s:
  1018. *
  1019. * ```js
  1020. * import { promisify } from 'node:util';
  1021. * import { stat } from 'node:fs';
  1022. *
  1023. * const promisifiedStat = promisify(stat);
  1024. *
  1025. * async function callStat() {
  1026. * const stats = await promisifiedStat('.');
  1027. * console.log(`This directory is owned by ${stats.uid}`);
  1028. * }
  1029. *
  1030. * callStat();
  1031. * ```
  1032. *
  1033. * If there is an `original[util.promisify.custom]` property present, `promisify`
  1034. * will return its value, see [Custom promisified functions](https://nodejs.org/docs/latest-v24.x/api/util.html#custom-promisified-functions).
  1035. *
  1036. * `promisify()` assumes that `original` is a function taking a callback as its
  1037. * final argument in all cases. If `original` is not a function, `promisify()`
  1038. * will throw an error. If `original` is a function but its last argument is not
  1039. * an error-first callback, it will still be passed an error-first
  1040. * callback as its last argument.
  1041. *
  1042. * Using `promisify()` on class methods or other methods that use `this` may not
  1043. * work as expected unless handled specially:
  1044. *
  1045. * ```js
  1046. * import { promisify } from 'node:util';
  1047. *
  1048. * class Foo {
  1049. * constructor() {
  1050. * this.a = 42;
  1051. * }
  1052. *
  1053. * bar(callback) {
  1054. * callback(null, this.a);
  1055. * }
  1056. * }
  1057. *
  1058. * const foo = new Foo();
  1059. *
  1060. * const naiveBar = promisify(foo.bar);
  1061. * // TypeError: Cannot read properties of undefined (reading 'a')
  1062. * // naiveBar().then(a => console.log(a));
  1063. *
  1064. * naiveBar.call(foo).then((a) => console.log(a)); // '42'
  1065. *
  1066. * const bindBar = naiveBar.bind(foo);
  1067. * bindBar().then((a) => console.log(a)); // '42'
  1068. * ```
  1069. * @since v8.0.0
  1070. */
  1071. export function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
  1072. export function promisify<TResult>(
  1073. fn: (callback: (err: any, result: TResult) => void) => void,
  1074. ): () => Promise<TResult>;
  1075. export function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
  1076. export function promisify<T1, TResult>(
  1077. fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void,
  1078. ): (arg1: T1) => Promise<TResult>;
  1079. export function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
  1080. export function promisify<T1, T2, TResult>(
  1081. fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void,
  1082. ): (arg1: T1, arg2: T2) => Promise<TResult>;
  1083. export function promisify<T1, T2>(
  1084. fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void,
  1085. ): (arg1: T1, arg2: T2) => Promise<void>;
  1086. export function promisify<T1, T2, T3, TResult>(
  1087. fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => void) => void,
  1088. ): (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>;
  1089. export function promisify<T1, T2, T3>(
  1090. fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err?: any) => void) => void,
  1091. ): (arg1: T1, arg2: T2, arg3: T3) => Promise<void>;
  1092. export function promisify<T1, T2, T3, T4, TResult>(
  1093. fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void,
  1094. ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
  1095. export function promisify<T1, T2, T3, T4>(
  1096. fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: any) => void) => void,
  1097. ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>;
  1098. export function promisify<T1, T2, T3, T4, T5, TResult>(
  1099. fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => void) => void,
  1100. ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
  1101. export function promisify<T1, T2, T3, T4, T5>(
  1102. fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void,
  1103. ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
  1104. export function promisify(fn: Function): Function;
  1105. export namespace promisify {
  1106. /**
  1107. * That can be used to declare custom promisified variants of functions.
  1108. */
  1109. const custom: unique symbol;
  1110. }
  1111. /**
  1112. * Stability: 1.1 - Active development
  1113. * Given an example `.env` file:
  1114. *
  1115. * ```js
  1116. * import { parseEnv } from 'node:util';
  1117. *
  1118. * parseEnv('HELLO=world\nHELLO=oh my\n');
  1119. * // Returns: { HELLO: 'oh my' }
  1120. * ```
  1121. * @param content The raw contents of a `.env` file.
  1122. * @since v20.12.0
  1123. */
  1124. export function parseEnv(content: string): NodeJS.Dict<string>;
  1125. // https://nodejs.org/docs/latest/api/util.html#foreground-colors
  1126. type ForegroundColors =
  1127. | "black"
  1128. | "blackBright"
  1129. | "blue"
  1130. | "blueBright"
  1131. | "cyan"
  1132. | "cyanBright"
  1133. | "gray"
  1134. | "green"
  1135. | "greenBright"
  1136. | "grey"
  1137. | "magenta"
  1138. | "magentaBright"
  1139. | "red"
  1140. | "redBright"
  1141. | "white"
  1142. | "whiteBright"
  1143. | "yellow"
  1144. | "yellowBright";
  1145. // https://nodejs.org/docs/latest/api/util.html#background-colors
  1146. type BackgroundColors =
  1147. | "bgBlack"
  1148. | "bgBlackBright"
  1149. | "bgBlue"
  1150. | "bgBlueBright"
  1151. | "bgCyan"
  1152. | "bgCyanBright"
  1153. | "bgGray"
  1154. | "bgGreen"
  1155. | "bgGreenBright"
  1156. | "bgGrey"
  1157. | "bgMagenta"
  1158. | "bgMagentaBright"
  1159. | "bgRed"
  1160. | "bgRedBright"
  1161. | "bgWhite"
  1162. | "bgWhiteBright"
  1163. | "bgYellow"
  1164. | "bgYellowBright";
  1165. // https://nodejs.org/docs/latest/api/util.html#modifiers
  1166. type Modifiers =
  1167. | "blink"
  1168. | "bold"
  1169. | "dim"
  1170. | "doubleunderline"
  1171. | "framed"
  1172. | "hidden"
  1173. | "inverse"
  1174. | "italic"
  1175. | "none"
  1176. | "overlined"
  1177. | "reset"
  1178. | "strikethrough"
  1179. | "underline";
  1180. export interface StyleTextOptions {
  1181. /**
  1182. * When true, `stream` is checked to see if it can handle colors.
  1183. * @default true
  1184. */
  1185. validateStream?: boolean | undefined;
  1186. /**
  1187. * A stream that will be validated if it can be colored.
  1188. * @default process.stdout
  1189. */
  1190. stream?: NodeJS.WritableStream | undefined;
  1191. }
  1192. /**
  1193. * This function returns a formatted text considering the `format` passed
  1194. * for printing in a terminal. It is aware of the terminal's capabilities
  1195. * and acts according to the configuration set via `NO_COLOR`,
  1196. * `NODE_DISABLE_COLORS` and `FORCE_COLOR` environment variables.
  1197. *
  1198. * ```js
  1199. * import { styleText } from 'node:util';
  1200. * import { stderr } from 'node:process';
  1201. *
  1202. * const successMessage = styleText('green', 'Success!');
  1203. * console.log(successMessage);
  1204. *
  1205. * const errorMessage = styleText(
  1206. * 'red',
  1207. * 'Error! Error!',
  1208. * // Validate if process.stderr has TTY
  1209. * { stream: stderr },
  1210. * );
  1211. * console.error(errorMessage);
  1212. * ```
  1213. *
  1214. * `util.inspect.colors` also provides text formats such as `italic`, and
  1215. * `underline` and you can combine both:
  1216. *
  1217. * ```js
  1218. * console.log(
  1219. * util.styleText(['underline', 'italic'], 'My italic underlined message'),
  1220. * );
  1221. * ```
  1222. *
  1223. * When passing an array of formats, the order of the format applied
  1224. * is left to right so the following style might overwrite the previous one.
  1225. *
  1226. * ```js
  1227. * console.log(
  1228. * util.styleText(['red', 'green'], 'text'), // green
  1229. * );
  1230. * ```
  1231. *
  1232. * The special format value `none` applies no additional styling to the text.
  1233. *
  1234. * The full list of formats can be found in [modifiers](https://nodejs.org/docs/latest-v24.x/api/util.html#modifiers).
  1235. * @param format A text format or an Array of text formats defined in `util.inspect.colors`.
  1236. * @param text The text to to be formatted.
  1237. * @since v20.12.0
  1238. */
  1239. export function styleText(
  1240. format:
  1241. | ForegroundColors
  1242. | BackgroundColors
  1243. | Modifiers
  1244. | Array<ForegroundColors | BackgroundColors | Modifiers>,
  1245. text: string,
  1246. options?: StyleTextOptions,
  1247. ): string;
  1248. /**
  1249. * An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextDecoder` API.
  1250. *
  1251. * ```js
  1252. * const decoder = new TextDecoder();
  1253. * const u8arr = new Uint8Array([72, 101, 108, 108, 111]);
  1254. * console.log(decoder.decode(u8arr)); // Hello
  1255. * ```
  1256. * @since v8.3.0
  1257. */
  1258. export class TextDecoder {
  1259. /**
  1260. * The encoding supported by the `TextDecoder` instance.
  1261. */
  1262. readonly encoding: string;
  1263. /**
  1264. * The value will be `true` if decoding errors result in a `TypeError` being
  1265. * thrown.
  1266. */
  1267. readonly fatal: boolean;
  1268. /**
  1269. * The value will be `true` if the decoding result will include the byte order
  1270. * mark.
  1271. */
  1272. readonly ignoreBOM: boolean;
  1273. constructor(
  1274. encoding?: string,
  1275. options?: {
  1276. fatal?: boolean | undefined;
  1277. ignoreBOM?: boolean | undefined;
  1278. },
  1279. );
  1280. /**
  1281. * Decodes the `input` and returns a string. If `options.stream` is `true`, any
  1282. * incomplete byte sequences occurring at the end of the `input` are buffered
  1283. * internally and emitted after the next call to `textDecoder.decode()`.
  1284. *
  1285. * If `textDecoder.fatal` is `true`, decoding errors that occur will result in a `TypeError` being thrown.
  1286. * @param input An `ArrayBuffer`, `DataView`, or `TypedArray` instance containing the encoded data.
  1287. */
  1288. decode(
  1289. input?: NodeJS.ArrayBufferView | ArrayBuffer | null,
  1290. options?: {
  1291. stream?: boolean | undefined;
  1292. },
  1293. ): string;
  1294. }
  1295. export interface EncodeIntoResult {
  1296. /**
  1297. * The read Unicode code units of input.
  1298. */
  1299. read: number;
  1300. /**
  1301. * The written UTF-8 bytes of output.
  1302. */
  1303. written: number;
  1304. }
  1305. export { types };
  1306. //// TextEncoder/Decoder
  1307. /**
  1308. * An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextEncoder` API. All
  1309. * instances of `TextEncoder` only support UTF-8 encoding.
  1310. *
  1311. * ```js
  1312. * const encoder = new TextEncoder();
  1313. * const uint8array = encoder.encode('this is some data');
  1314. * ```
  1315. *
  1316. * The `TextEncoder` class is also available on the global object.
  1317. * @since v8.3.0
  1318. */
  1319. export class TextEncoder {
  1320. /**
  1321. * The encoding supported by the `TextEncoder` instance. Always set to `'utf-8'`.
  1322. */
  1323. readonly encoding: string;
  1324. /**
  1325. * UTF-8 encodes the `input` string and returns a `Uint8Array` containing the
  1326. * encoded bytes.
  1327. * @param [input='an empty string'] The text to encode.
  1328. */
  1329. encode(input?: string): Uint8Array;
  1330. /**
  1331. * UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object
  1332. * containing the read Unicode code units and written UTF-8 bytes.
  1333. *
  1334. * ```js
  1335. * const encoder = new TextEncoder();
  1336. * const src = 'this is some data';
  1337. * const dest = new Uint8Array(10);
  1338. * const { read, written } = encoder.encodeInto(src, dest);
  1339. * ```
  1340. * @param src The text to encode.
  1341. * @param dest The array to hold the encode result.
  1342. */
  1343. encodeInto(src: string, dest: Uint8Array): EncodeIntoResult;
  1344. }
  1345. import { TextDecoder as _TextDecoder, TextEncoder as _TextEncoder } from "util";
  1346. global {
  1347. /**
  1348. * `TextDecoder` class is a global reference for `import { TextDecoder } from 'node:util'`
  1349. * https://nodejs.org/api/globals.html#textdecoder
  1350. * @since v11.0.0
  1351. */
  1352. var TextDecoder: typeof globalThis extends {
  1353. onmessage: any;
  1354. TextDecoder: infer TextDecoder;
  1355. } ? TextDecoder
  1356. : typeof _TextDecoder;
  1357. /**
  1358. * `TextEncoder` class is a global reference for `import { TextEncoder } from 'node:util'`
  1359. * https://nodejs.org/api/globals.html#textencoder
  1360. * @since v11.0.0
  1361. */
  1362. var TextEncoder: typeof globalThis extends {
  1363. onmessage: any;
  1364. TextEncoder: infer TextEncoder;
  1365. } ? TextEncoder
  1366. : typeof _TextEncoder;
  1367. }
  1368. //// parseArgs
  1369. /**
  1370. * Provides a higher level API for command-line argument parsing than interacting
  1371. * with `process.argv` directly. Takes a specification for the expected arguments
  1372. * and returns a structured object with the parsed options and positionals.
  1373. *
  1374. * ```js
  1375. * import { parseArgs } from 'node:util';
  1376. * const args = ['-f', '--bar', 'b'];
  1377. * const options = {
  1378. * foo: {
  1379. * type: 'boolean',
  1380. * short: 'f',
  1381. * },
  1382. * bar: {
  1383. * type: 'string',
  1384. * },
  1385. * };
  1386. * const {
  1387. * values,
  1388. * positionals,
  1389. * } = parseArgs({ args, options });
  1390. * console.log(values, positionals);
  1391. * // Prints: [Object: null prototype] { foo: true, bar: 'b' } []
  1392. * ```
  1393. * @since v18.3.0, v16.17.0
  1394. * @param config Used to provide arguments for parsing and to configure the parser. `config` supports the following properties:
  1395. * @return The parsed command line arguments:
  1396. */
  1397. export function parseArgs<T extends ParseArgsConfig>(config?: T): ParsedResults<T>;
  1398. /**
  1399. * Type of argument used in {@link parseArgs}.
  1400. */
  1401. export type ParseArgsOptionsType = "boolean" | "string";
  1402. export interface ParseArgsOptionDescriptor {
  1403. /**
  1404. * Type of argument.
  1405. */
  1406. type: ParseArgsOptionsType;
  1407. /**
  1408. * Whether this option can be provided multiple times.
  1409. * If `true`, all values will be collected in an array.
  1410. * If `false`, values for the option are last-wins.
  1411. * @default false.
  1412. */
  1413. multiple?: boolean | undefined;
  1414. /**
  1415. * A single character alias for the option.
  1416. */
  1417. short?: string | undefined;
  1418. /**
  1419. * The value to assign to
  1420. * the option if it does not appear in the arguments to be parsed. The value
  1421. * must match the type specified by the `type` property. If `multiple` is
  1422. * `true`, it must be an array. No default value is applied when the option
  1423. * does appear in the arguments to be parsed, even if the provided value
  1424. * is falsy.
  1425. * @since v18.11.0
  1426. */
  1427. default?: string | boolean | string[] | boolean[] | undefined;
  1428. }
  1429. export interface ParseArgsOptionsConfig {
  1430. [longOption: string]: ParseArgsOptionDescriptor;
  1431. }
  1432. export interface ParseArgsConfig {
  1433. /**
  1434. * Array of argument strings.
  1435. */
  1436. args?: string[] | undefined;
  1437. /**
  1438. * Used to describe arguments known to the parser.
  1439. */
  1440. options?: ParseArgsOptionsConfig | undefined;
  1441. /**
  1442. * Should an error be thrown when unknown arguments are encountered,
  1443. * or when arguments are passed that do not match the `type` configured in `options`.
  1444. * @default true
  1445. */
  1446. strict?: boolean | undefined;
  1447. /**
  1448. * Whether this command accepts positional arguments.
  1449. */
  1450. allowPositionals?: boolean | undefined;
  1451. /**
  1452. * If `true`, allows explicitly setting boolean options to `false` by prefixing the option name with `--no-`.
  1453. * @default false
  1454. * @since v22.4.0
  1455. */
  1456. allowNegative?: boolean | undefined;
  1457. /**
  1458. * Return the parsed tokens. This is useful for extending the built-in behavior,
  1459. * from adding additional checks through to reprocessing the tokens in different ways.
  1460. * @default false
  1461. */
  1462. tokens?: boolean | undefined;
  1463. }
  1464. /*
  1465. IfDefaultsTrue and IfDefaultsFalse are helpers to handle default values for missing boolean properties.
  1466. TypeScript does not have exact types for objects: https://github.com/microsoft/TypeScript/issues/12936
  1467. This means it is impossible to distinguish between "field X is definitely not present" and "field X may or may not be present".
  1468. But we expect users to generally provide their config inline or `as const`, which means TS will always know whether a given field is present.
  1469. So this helper treats "not definitely present" (i.e., not `extends boolean`) as being "definitely not present", i.e. it should have its default value.
  1470. This is technically incorrect but is a much nicer UX for the common case.
  1471. The IfDefaultsTrue version is for things which default to true; the IfDefaultsFalse version is for things which default to false.
  1472. */
  1473. type IfDefaultsTrue<T, IfTrue, IfFalse> = T extends true ? IfTrue
  1474. : T extends false ? IfFalse
  1475. : IfTrue;
  1476. // we put the `extends false` condition first here because `undefined` compares like `any` when `strictNullChecks: false`
  1477. type IfDefaultsFalse<T, IfTrue, IfFalse> = T extends false ? IfFalse
  1478. : T extends true ? IfTrue
  1479. : IfFalse;
  1480. type ExtractOptionValue<T extends ParseArgsConfig, O extends ParseArgsOptionDescriptor> = IfDefaultsTrue<
  1481. T["strict"],
  1482. O["type"] extends "string" ? string : O["type"] extends "boolean" ? boolean : string | boolean,
  1483. string | boolean
  1484. >;
  1485. type ApplyOptionalModifiers<O extends ParseArgsOptionsConfig, V extends Record<keyof O, unknown>> = (
  1486. & { -readonly [LongOption in keyof O]?: V[LongOption] }
  1487. & { [LongOption in keyof O as O[LongOption]["default"] extends {} ? LongOption : never]: V[LongOption] }
  1488. ) extends infer P ? { [K in keyof P]: P[K] } : never; // resolve intersection to object
  1489. type ParsedValues<T extends ParseArgsConfig> =
  1490. & IfDefaultsTrue<T["strict"], unknown, { [longOption: string]: undefined | string | boolean }>
  1491. & (T["options"] extends ParseArgsOptionsConfig ? ApplyOptionalModifiers<
  1492. T["options"],
  1493. {
  1494. [LongOption in keyof T["options"]]: IfDefaultsFalse<
  1495. T["options"][LongOption]["multiple"],
  1496. Array<ExtractOptionValue<T, T["options"][LongOption]>>,
  1497. ExtractOptionValue<T, T["options"][LongOption]>
  1498. >;
  1499. }
  1500. >
  1501. : {});
  1502. type ParsedPositionals<T extends ParseArgsConfig> = IfDefaultsTrue<
  1503. T["strict"],
  1504. IfDefaultsFalse<T["allowPositionals"], string[], []>,
  1505. IfDefaultsTrue<T["allowPositionals"], string[], []>
  1506. >;
  1507. type PreciseTokenForOptions<
  1508. K extends string,
  1509. O extends ParseArgsOptionDescriptor,
  1510. > = O["type"] extends "string" ? {
  1511. kind: "option";
  1512. index: number;
  1513. name: K;
  1514. rawName: string;
  1515. value: string;
  1516. inlineValue: boolean;
  1517. }
  1518. : O["type"] extends "boolean" ? {
  1519. kind: "option";
  1520. index: number;
  1521. name: K;
  1522. rawName: string;
  1523. value: undefined;
  1524. inlineValue: undefined;
  1525. }
  1526. : OptionToken & { name: K };
  1527. type TokenForOptions<
  1528. T extends ParseArgsConfig,
  1529. K extends keyof T["options"] = keyof T["options"],
  1530. > = K extends unknown
  1531. ? T["options"] extends ParseArgsOptionsConfig ? PreciseTokenForOptions<K & string, T["options"][K]>
  1532. : OptionToken
  1533. : never;
  1534. type ParsedOptionToken<T extends ParseArgsConfig> = IfDefaultsTrue<T["strict"], TokenForOptions<T>, OptionToken>;
  1535. type ParsedPositionalToken<T extends ParseArgsConfig> = IfDefaultsTrue<
  1536. T["strict"],
  1537. IfDefaultsFalse<T["allowPositionals"], { kind: "positional"; index: number; value: string }, never>,
  1538. IfDefaultsTrue<T["allowPositionals"], { kind: "positional"; index: number; value: string }, never>
  1539. >;
  1540. type ParsedTokens<T extends ParseArgsConfig> = Array<
  1541. ParsedOptionToken<T> | ParsedPositionalToken<T> | { kind: "option-terminator"; index: number }
  1542. >;
  1543. type PreciseParsedResults<T extends ParseArgsConfig> = IfDefaultsFalse<
  1544. T["tokens"],
  1545. {
  1546. values: ParsedValues<T>;
  1547. positionals: ParsedPositionals<T>;
  1548. tokens: ParsedTokens<T>;
  1549. },
  1550. {
  1551. values: ParsedValues<T>;
  1552. positionals: ParsedPositionals<T>;
  1553. }
  1554. >;
  1555. type OptionToken =
  1556. | { kind: "option"; index: number; name: string; rawName: string; value: string; inlineValue: boolean }
  1557. | {
  1558. kind: "option";
  1559. index: number;
  1560. name: string;
  1561. rawName: string;
  1562. value: undefined;
  1563. inlineValue: undefined;
  1564. };
  1565. type Token =
  1566. | OptionToken
  1567. | { kind: "positional"; index: number; value: string }
  1568. | { kind: "option-terminator"; index: number };
  1569. // If ParseArgsConfig extends T, then the user passed config constructed elsewhere.
  1570. // So we can't rely on the `"not definitely present" implies "definitely not present"` assumption mentioned above.
  1571. type ParsedResults<T extends ParseArgsConfig> = ParseArgsConfig extends T ? {
  1572. values: {
  1573. [longOption: string]: undefined | string | boolean | Array<string | boolean>;
  1574. };
  1575. positionals: string[];
  1576. tokens?: Token[];
  1577. }
  1578. : PreciseParsedResults<T>;
  1579. /**
  1580. * An implementation of [the MIMEType class](https://bmeck.github.io/node-proposal-mime-api/).
  1581. *
  1582. * In accordance with browser conventions, all properties of `MIMEType` objects
  1583. * are implemented as getters and setters on the class prototype, rather than as
  1584. * data properties on the object itself.
  1585. *
  1586. * A MIME string is a structured string containing multiple meaningful
  1587. * components. When parsed, a `MIMEType` object is returned containing
  1588. * properties for each of these components.
  1589. * @since v19.1.0, v18.13.0
  1590. */
  1591. export class MIMEType {
  1592. /**
  1593. * Creates a new MIMEType object by parsing the input.
  1594. *
  1595. * A `TypeError` will be thrown if the `input` is not a valid MIME.
  1596. * Note that an effort will be made to coerce the given values into strings.
  1597. * @param input The input MIME to parse.
  1598. */
  1599. constructor(input: string | { toString: () => string });
  1600. /**
  1601. * Gets and sets the type portion of the MIME.
  1602. *
  1603. * ```js
  1604. * import { MIMEType } from 'node:util';
  1605. *
  1606. * const myMIME = new MIMEType('text/javascript');
  1607. * console.log(myMIME.type);
  1608. * // Prints: text
  1609. * myMIME.type = 'application';
  1610. * console.log(myMIME.type);
  1611. * // Prints: application
  1612. * console.log(String(myMIME));
  1613. * // Prints: application/javascript
  1614. * ```
  1615. */
  1616. type: string;
  1617. /**
  1618. * Gets and sets the subtype portion of the MIME.
  1619. *
  1620. * ```js
  1621. * import { MIMEType } from 'node:util';
  1622. *
  1623. * const myMIME = new MIMEType('text/ecmascript');
  1624. * console.log(myMIME.subtype);
  1625. * // Prints: ecmascript
  1626. * myMIME.subtype = 'javascript';
  1627. * console.log(myMIME.subtype);
  1628. * // Prints: javascript
  1629. * console.log(String(myMIME));
  1630. * // Prints: text/javascript
  1631. * ```
  1632. */
  1633. subtype: string;
  1634. /**
  1635. * Gets the essence of the MIME. This property is read only.
  1636. * Use `mime.type` or `mime.subtype` to alter the MIME.
  1637. *
  1638. * ```js
  1639. * import { MIMEType } from 'node:util';
  1640. *
  1641. * const myMIME = new MIMEType('text/javascript;key=value');
  1642. * console.log(myMIME.essence);
  1643. * // Prints: text/javascript
  1644. * myMIME.type = 'application';
  1645. * console.log(myMIME.essence);
  1646. * // Prints: application/javascript
  1647. * console.log(String(myMIME));
  1648. * // Prints: application/javascript;key=value
  1649. * ```
  1650. */
  1651. readonly essence: string;
  1652. /**
  1653. * Gets the `MIMEParams` object representing the
  1654. * parameters of the MIME. This property is read-only. See `MIMEParams` documentation for details.
  1655. */
  1656. readonly params: MIMEParams;
  1657. /**
  1658. * The `toString()` method on the `MIMEType` object returns the serialized MIME.
  1659. *
  1660. * Because of the need for standard compliance, this method does not allow users
  1661. * to customize the serialization process of the MIME.
  1662. */
  1663. toString(): string;
  1664. }
  1665. /**
  1666. * The `MIMEParams` API provides read and write access to the parameters of a `MIMEType`.
  1667. * @since v19.1.0, v18.13.0
  1668. */
  1669. export class MIMEParams {
  1670. /**
  1671. * Remove all name-value pairs whose name is `name`.
  1672. */
  1673. delete(name: string): void;
  1674. /**
  1675. * Returns an iterator over each of the name-value pairs in the parameters.
  1676. * Each item of the iterator is a JavaScript `Array`. The first item of the array
  1677. * is the `name`, the second item of the array is the `value`.
  1678. */
  1679. entries(): NodeJS.Iterator<[name: string, value: string]>;
  1680. /**
  1681. * Returns the value of the first name-value pair whose name is `name`. If there
  1682. * are no such pairs, `null` is returned.
  1683. * @return or `null` if there is no name-value pair with the given `name`.
  1684. */
  1685. get(name: string): string | null;
  1686. /**
  1687. * Returns `true` if there is at least one name-value pair whose name is `name`.
  1688. */
  1689. has(name: string): boolean;
  1690. /**
  1691. * Returns an iterator over the names of each name-value pair.
  1692. *
  1693. * ```js
  1694. * import { MIMEType } from 'node:util';
  1695. *
  1696. * const { params } = new MIMEType('text/plain;foo=0;bar=1');
  1697. * for (const name of params.keys()) {
  1698. * console.log(name);
  1699. * }
  1700. * // Prints:
  1701. * // foo
  1702. * // bar
  1703. * ```
  1704. */
  1705. keys(): NodeJS.Iterator<string>;
  1706. /**
  1707. * Sets the value in the `MIMEParams` object associated with `name` to `value`. If there are any pre-existing name-value pairs whose names are `name`,
  1708. * set the first such pair's value to `value`.
  1709. *
  1710. * ```js
  1711. * import { MIMEType } from 'node:util';
  1712. *
  1713. * const { params } = new MIMEType('text/plain;foo=0;bar=1');
  1714. * params.set('foo', 'def');
  1715. * params.set('baz', 'xyz');
  1716. * console.log(params.toString());
  1717. * // Prints: foo=def;bar=1;baz=xyz
  1718. * ```
  1719. */
  1720. set(name: string, value: string): void;
  1721. /**
  1722. * Returns an iterator over the values of each name-value pair.
  1723. */
  1724. values(): NodeJS.Iterator<string>;
  1725. /**
  1726. * Returns an iterator over each of the name-value pairs in the parameters.
  1727. */
  1728. [Symbol.iterator](): NodeJS.Iterator<[name: string, value: string]>;
  1729. }
  1730. }
  1731. declare module "util/types" {
  1732. import { KeyObject, webcrypto } from "node:crypto";
  1733. /**
  1734. * Returns `true` if the value is a built-in [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) or
  1735. * [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instance.
  1736. *
  1737. * See also `util.types.isArrayBuffer()` and `util.types.isSharedArrayBuffer()`.
  1738. *
  1739. * ```js
  1740. * util.types.isAnyArrayBuffer(new ArrayBuffer()); // Returns true
  1741. * util.types.isAnyArrayBuffer(new SharedArrayBuffer()); // Returns true
  1742. * ```
  1743. * @since v10.0.0
  1744. */
  1745. function isAnyArrayBuffer(object: unknown): object is ArrayBufferLike;
  1746. /**
  1747. * Returns `true` if the value is an `arguments` object.
  1748. *
  1749. * ```js
  1750. * function foo() {
  1751. * util.types.isArgumentsObject(arguments); // Returns true
  1752. * }
  1753. * ```
  1754. * @since v10.0.0
  1755. */
  1756. function isArgumentsObject(object: unknown): object is IArguments;
  1757. /**
  1758. * Returns `true` if the value is a built-in [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) instance.
  1759. * This does _not_ include [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instances. Usually, it is
  1760. * desirable to test for both; See `util.types.isAnyArrayBuffer()` for that.
  1761. *
  1762. * ```js
  1763. * util.types.isArrayBuffer(new ArrayBuffer()); // Returns true
  1764. * util.types.isArrayBuffer(new SharedArrayBuffer()); // Returns false
  1765. * ```
  1766. * @since v10.0.0
  1767. */
  1768. function isArrayBuffer(object: unknown): object is ArrayBuffer;
  1769. /**
  1770. * Returns `true` if the value is an instance of one of the [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) views, such as typed
  1771. * array objects or [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView). Equivalent to
  1772. * [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
  1773. *
  1774. * ```js
  1775. * util.types.isArrayBufferView(new Int8Array()); // true
  1776. * util.types.isArrayBufferView(Buffer.from('hello world')); // true
  1777. * util.types.isArrayBufferView(new DataView(new ArrayBuffer(16))); // true
  1778. * util.types.isArrayBufferView(new ArrayBuffer()); // false
  1779. * ```
  1780. * @since v10.0.0
  1781. */
  1782. function isArrayBufferView(object: unknown): object is NodeJS.ArrayBufferView;
  1783. /**
  1784. * Returns `true` if the value is an [async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function).
  1785. * This only reports back what the JavaScript engine is seeing;
  1786. * in particular, the return value may not match the original source code if
  1787. * a transpilation tool was used.
  1788. *
  1789. * ```js
  1790. * util.types.isAsyncFunction(function foo() {}); // Returns false
  1791. * util.types.isAsyncFunction(async function foo() {}); // Returns true
  1792. * ```
  1793. * @since v10.0.0
  1794. */
  1795. function isAsyncFunction(object: unknown): boolean;
  1796. /**
  1797. * Returns `true` if the value is a `BigInt64Array` instance.
  1798. *
  1799. * ```js
  1800. * util.types.isBigInt64Array(new BigInt64Array()); // Returns true
  1801. * util.types.isBigInt64Array(new BigUint64Array()); // Returns false
  1802. * ```
  1803. * @since v10.0.0
  1804. */
  1805. function isBigInt64Array(value: unknown): value is BigInt64Array;
  1806. /**
  1807. * Returns `true` if the value is a BigInt object, e.g. created
  1808. * by `Object(BigInt(123))`.
  1809. *
  1810. * ```js
  1811. * util.types.isBigIntObject(Object(BigInt(123))); // Returns true
  1812. * util.types.isBigIntObject(BigInt(123)); // Returns false
  1813. * util.types.isBigIntObject(123); // Returns false
  1814. * ```
  1815. * @since v10.4.0
  1816. */
  1817. function isBigIntObject(object: unknown): object is BigInt;
  1818. /**
  1819. * Returns `true` if the value is a `BigUint64Array` instance.
  1820. *
  1821. * ```js
  1822. * util.types.isBigUint64Array(new BigInt64Array()); // Returns false
  1823. * util.types.isBigUint64Array(new BigUint64Array()); // Returns true
  1824. * ```
  1825. * @since v10.0.0
  1826. */
  1827. function isBigUint64Array(value: unknown): value is BigUint64Array;
  1828. /**
  1829. * Returns `true` if the value is a boolean object, e.g. created
  1830. * by `new Boolean()`.
  1831. *
  1832. * ```js
  1833. * util.types.isBooleanObject(false); // Returns false
  1834. * util.types.isBooleanObject(true); // Returns false
  1835. * util.types.isBooleanObject(new Boolean(false)); // Returns true
  1836. * util.types.isBooleanObject(new Boolean(true)); // Returns true
  1837. * util.types.isBooleanObject(Boolean(false)); // Returns false
  1838. * util.types.isBooleanObject(Boolean(true)); // Returns false
  1839. * ```
  1840. * @since v10.0.0
  1841. */
  1842. function isBooleanObject(object: unknown): object is Boolean;
  1843. /**
  1844. * Returns `true` if the value is any boxed primitive object, e.g. created
  1845. * by `new Boolean()`, `new String()` or `Object(Symbol())`.
  1846. *
  1847. * For example:
  1848. *
  1849. * ```js
  1850. * util.types.isBoxedPrimitive(false); // Returns false
  1851. * util.types.isBoxedPrimitive(new Boolean(false)); // Returns true
  1852. * util.types.isBoxedPrimitive(Symbol('foo')); // Returns false
  1853. * util.types.isBoxedPrimitive(Object(Symbol('foo'))); // Returns true
  1854. * util.types.isBoxedPrimitive(Object(BigInt(5))); // Returns true
  1855. * ```
  1856. * @since v10.11.0
  1857. */
  1858. function isBoxedPrimitive(object: unknown): object is String | Number | BigInt | Boolean | Symbol;
  1859. /**
  1860. * Returns `true` if the value is a built-in [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) instance.
  1861. *
  1862. * ```js
  1863. * const ab = new ArrayBuffer(20);
  1864. * util.types.isDataView(new DataView(ab)); // Returns true
  1865. * util.types.isDataView(new Float64Array()); // Returns false
  1866. * ```
  1867. *
  1868. * See also [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
  1869. * @since v10.0.0
  1870. */
  1871. function isDataView(object: unknown): object is DataView;
  1872. /**
  1873. * Returns `true` if the value is a built-in [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance.
  1874. *
  1875. * ```js
  1876. * util.types.isDate(new Date()); // Returns true
  1877. * ```
  1878. * @since v10.0.0
  1879. */
  1880. function isDate(object: unknown): object is Date;
  1881. /**
  1882. * Returns `true` if the value is a native `External` value.
  1883. *
  1884. * A native `External` value is a special type of object that contains a
  1885. * raw C++ pointer (`void*`) for access from native code, and has no other
  1886. * properties. Such objects are created either by Node.js internals or native
  1887. * addons. In JavaScript, they are
  1888. * [frozen](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) objects with a
  1889. * `null` prototype.
  1890. *
  1891. * ```c
  1892. * #include <js_native_api.h>
  1893. * #include <stdlib.h>
  1894. * napi_value result;
  1895. * static napi_value MyNapi(napi_env env, napi_callback_info info) {
  1896. * int* raw = (int*) malloc(1024);
  1897. * napi_status status = napi_create_external(env, (void*) raw, NULL, NULL, &result);
  1898. * if (status != napi_ok) {
  1899. * napi_throw_error(env, NULL, "napi_create_external failed");
  1900. * return NULL;
  1901. * }
  1902. * return result;
  1903. * }
  1904. * ...
  1905. * DECLARE_NAPI_PROPERTY("myNapi", MyNapi)
  1906. * ...
  1907. * ```
  1908. *
  1909. * ```js
  1910. * import native from 'napi_addon.node';
  1911. * import { types } from 'node:util';
  1912. *
  1913. * const data = native.myNapi();
  1914. * types.isExternal(data); // returns true
  1915. * types.isExternal(0); // returns false
  1916. * types.isExternal(new String('foo')); // returns false
  1917. * ```
  1918. *
  1919. * For further information on `napi_create_external`, refer to
  1920. * [`napi_create_external()`](https://nodejs.org/docs/latest-v24.x/api/n-api.html#napi_create_external).
  1921. * @since v10.0.0
  1922. */
  1923. function isExternal(object: unknown): boolean;
  1924. /**
  1925. * Returns `true` if the value is a built-in [`Float16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array) instance.
  1926. *
  1927. * ```js
  1928. * util.types.isFloat16Array(new ArrayBuffer()); // Returns false
  1929. * util.types.isFloat16Array(new Float16Array()); // Returns true
  1930. * util.types.isFloat16Array(new Float32Array()); // Returns false
  1931. * ```
  1932. * @since v24.0.0
  1933. */
  1934. function isFloat16Array(object: unknown): object is Float16Array;
  1935. /**
  1936. * Returns `true` if the value is a built-in [`Float32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array) instance.
  1937. *
  1938. * ```js
  1939. * util.types.isFloat32Array(new ArrayBuffer()); // Returns false
  1940. * util.types.isFloat32Array(new Float32Array()); // Returns true
  1941. * util.types.isFloat32Array(new Float64Array()); // Returns false
  1942. * ```
  1943. * @since v10.0.0
  1944. */
  1945. function isFloat32Array(object: unknown): object is Float32Array;
  1946. /**
  1947. * Returns `true` if the value is a built-in [`Float64Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array) instance.
  1948. *
  1949. * ```js
  1950. * util.types.isFloat64Array(new ArrayBuffer()); // Returns false
  1951. * util.types.isFloat64Array(new Uint8Array()); // Returns false
  1952. * util.types.isFloat64Array(new Float64Array()); // Returns true
  1953. * ```
  1954. * @since v10.0.0
  1955. */
  1956. function isFloat64Array(object: unknown): object is Float64Array;
  1957. /**
  1958. * Returns `true` if the value is a generator function.
  1959. * This only reports back what the JavaScript engine is seeing;
  1960. * in particular, the return value may not match the original source code if
  1961. * a transpilation tool was used.
  1962. *
  1963. * ```js
  1964. * util.types.isGeneratorFunction(function foo() {}); // Returns false
  1965. * util.types.isGeneratorFunction(function* foo() {}); // Returns true
  1966. * ```
  1967. * @since v10.0.0
  1968. */
  1969. function isGeneratorFunction(object: unknown): object is GeneratorFunction;
  1970. /**
  1971. * Returns `true` if the value is a generator object as returned from a
  1972. * built-in generator function.
  1973. * This only reports back what the JavaScript engine is seeing;
  1974. * in particular, the return value may not match the original source code if
  1975. * a transpilation tool was used.
  1976. *
  1977. * ```js
  1978. * function* foo() {}
  1979. * const generator = foo();
  1980. * util.types.isGeneratorObject(generator); // Returns true
  1981. * ```
  1982. * @since v10.0.0
  1983. */
  1984. function isGeneratorObject(object: unknown): object is Generator;
  1985. /**
  1986. * Returns `true` if the value is a built-in [`Int8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array) instance.
  1987. *
  1988. * ```js
  1989. * util.types.isInt8Array(new ArrayBuffer()); // Returns false
  1990. * util.types.isInt8Array(new Int8Array()); // Returns true
  1991. * util.types.isInt8Array(new Float64Array()); // Returns false
  1992. * ```
  1993. * @since v10.0.0
  1994. */
  1995. function isInt8Array(object: unknown): object is Int8Array;
  1996. /**
  1997. * Returns `true` if the value is a built-in [`Int16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array) instance.
  1998. *
  1999. * ```js
  2000. * util.types.isInt16Array(new ArrayBuffer()); // Returns false
  2001. * util.types.isInt16Array(new Int16Array()); // Returns true
  2002. * util.types.isInt16Array(new Float64Array()); // Returns false
  2003. * ```
  2004. * @since v10.0.0
  2005. */
  2006. function isInt16Array(object: unknown): object is Int16Array;
  2007. /**
  2008. * Returns `true` if the value is a built-in [`Int32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array) instance.
  2009. *
  2010. * ```js
  2011. * util.types.isInt32Array(new ArrayBuffer()); // Returns false
  2012. * util.types.isInt32Array(new Int32Array()); // Returns true
  2013. * util.types.isInt32Array(new Float64Array()); // Returns false
  2014. * ```
  2015. * @since v10.0.0
  2016. */
  2017. function isInt32Array(object: unknown): object is Int32Array;
  2018. /**
  2019. * Returns `true` if the value is a built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instance.
  2020. *
  2021. * ```js
  2022. * util.types.isMap(new Map()); // Returns true
  2023. * ```
  2024. * @since v10.0.0
  2025. */
  2026. function isMap<T>(
  2027. object: T | {},
  2028. ): object is T extends ReadonlyMap<any, any> ? (unknown extends T ? never : ReadonlyMap<any, any>)
  2029. : Map<unknown, unknown>;
  2030. /**
  2031. * Returns `true` if the value is an iterator returned for a built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instance.
  2032. *
  2033. * ```js
  2034. * const map = new Map();
  2035. * util.types.isMapIterator(map.keys()); // Returns true
  2036. * util.types.isMapIterator(map.values()); // Returns true
  2037. * util.types.isMapIterator(map.entries()); // Returns true
  2038. * util.types.isMapIterator(map[Symbol.iterator]()); // Returns true
  2039. * ```
  2040. * @since v10.0.0
  2041. */
  2042. function isMapIterator(object: unknown): boolean;
  2043. /**
  2044. * Returns `true` if the value is an instance of a [Module Namespace Object](https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects).
  2045. *
  2046. * ```js
  2047. * import * as ns from './a.js';
  2048. *
  2049. * util.types.isModuleNamespaceObject(ns); // Returns true
  2050. * ```
  2051. * @since v10.0.0
  2052. */
  2053. function isModuleNamespaceObject(value: unknown): boolean;
  2054. /**
  2055. * Returns `true` if the value was returned by the constructor of a
  2056. * [built-in `Error` type](https://tc39.es/ecma262/#sec-error-objects).
  2057. *
  2058. * ```js
  2059. * console.log(util.types.isNativeError(new Error())); // true
  2060. * console.log(util.types.isNativeError(new TypeError())); // true
  2061. * console.log(util.types.isNativeError(new RangeError())); // true
  2062. * ```
  2063. *
  2064. * Subclasses of the native error types are also native errors:
  2065. *
  2066. * ```js
  2067. * class MyError extends Error {}
  2068. * console.log(util.types.isNativeError(new MyError())); // true
  2069. * ```
  2070. *
  2071. * A value being `instanceof` a native error class is not equivalent to `isNativeError()`
  2072. * returning `true` for that value. `isNativeError()` returns `true` for errors
  2073. * which come from a different [realm](https://tc39.es/ecma262/#realm) while `instanceof Error` returns `false`
  2074. * for these errors:
  2075. *
  2076. * ```js
  2077. * import { createContext, runInContext } from 'node:vm';
  2078. * import { types } from 'node:util';
  2079. *
  2080. * const context = createContext({});
  2081. * const myError = runInContext('new Error()', context);
  2082. * console.log(types.isNativeError(myError)); // true
  2083. * console.log(myError instanceof Error); // false
  2084. * ```
  2085. *
  2086. * Conversely, `isNativeError()` returns `false` for all objects which were not
  2087. * returned by the constructor of a native error. That includes values
  2088. * which are `instanceof` native errors:
  2089. *
  2090. * ```js
  2091. * const myError = { __proto__: Error.prototype };
  2092. * console.log(util.types.isNativeError(myError)); // false
  2093. * console.log(myError instanceof Error); // true
  2094. * ```
  2095. * @since v10.0.0
  2096. * @deprecated The `util.types.isNativeError` API is deprecated. Please use `Error.isError` instead.
  2097. */
  2098. function isNativeError(object: unknown): object is Error;
  2099. /**
  2100. * Returns `true` if the value is a number object, e.g. created
  2101. * by `new Number()`.
  2102. *
  2103. * ```js
  2104. * util.types.isNumberObject(0); // Returns false
  2105. * util.types.isNumberObject(new Number(0)); // Returns true
  2106. * ```
  2107. * @since v10.0.0
  2108. */
  2109. function isNumberObject(object: unknown): object is Number;
  2110. /**
  2111. * Returns `true` if the value is a built-in [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
  2112. *
  2113. * ```js
  2114. * util.types.isPromise(Promise.resolve(42)); // Returns true
  2115. * ```
  2116. * @since v10.0.0
  2117. */
  2118. function isPromise(object: unknown): object is Promise<unknown>;
  2119. /**
  2120. * Returns `true` if the value is a [`Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) instance.
  2121. *
  2122. * ```js
  2123. * const target = {};
  2124. * const proxy = new Proxy(target, {});
  2125. * util.types.isProxy(target); // Returns false
  2126. * util.types.isProxy(proxy); // Returns true
  2127. * ```
  2128. * @since v10.0.0
  2129. */
  2130. function isProxy(object: unknown): boolean;
  2131. /**
  2132. * Returns `true` if the value is a regular expression object.
  2133. *
  2134. * ```js
  2135. * util.types.isRegExp(/abc/); // Returns true
  2136. * util.types.isRegExp(new RegExp('abc')); // Returns true
  2137. * ```
  2138. * @since v10.0.0
  2139. */
  2140. function isRegExp(object: unknown): object is RegExp;
  2141. /**
  2142. * Returns `true` if the value is a built-in [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instance.
  2143. *
  2144. * ```js
  2145. * util.types.isSet(new Set()); // Returns true
  2146. * ```
  2147. * @since v10.0.0
  2148. */
  2149. function isSet<T>(
  2150. object: T | {},
  2151. ): object is T extends ReadonlySet<any> ? (unknown extends T ? never : ReadonlySet<any>) : Set<unknown>;
  2152. /**
  2153. * Returns `true` if the value is an iterator returned for a built-in [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instance.
  2154. *
  2155. * ```js
  2156. * const set = new Set();
  2157. * util.types.isSetIterator(set.keys()); // Returns true
  2158. * util.types.isSetIterator(set.values()); // Returns true
  2159. * util.types.isSetIterator(set.entries()); // Returns true
  2160. * util.types.isSetIterator(set[Symbol.iterator]()); // Returns true
  2161. * ```
  2162. * @since v10.0.0
  2163. */
  2164. function isSetIterator(object: unknown): boolean;
  2165. /**
  2166. * Returns `true` if the value is a built-in [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instance.
  2167. * This does _not_ include [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) instances. Usually, it is
  2168. * desirable to test for both; See `util.types.isAnyArrayBuffer()` for that.
  2169. *
  2170. * ```js
  2171. * util.types.isSharedArrayBuffer(new ArrayBuffer()); // Returns false
  2172. * util.types.isSharedArrayBuffer(new SharedArrayBuffer()); // Returns true
  2173. * ```
  2174. * @since v10.0.0
  2175. */
  2176. function isSharedArrayBuffer(object: unknown): object is SharedArrayBuffer;
  2177. /**
  2178. * Returns `true` if the value is a string object, e.g. created
  2179. * by `new String()`.
  2180. *
  2181. * ```js
  2182. * util.types.isStringObject('foo'); // Returns false
  2183. * util.types.isStringObject(new String('foo')); // Returns true
  2184. * ```
  2185. * @since v10.0.0
  2186. */
  2187. function isStringObject(object: unknown): object is String;
  2188. /**
  2189. * Returns `true` if the value is a symbol object, created
  2190. * by calling `Object()` on a `Symbol` primitive.
  2191. *
  2192. * ```js
  2193. * const symbol = Symbol('foo');
  2194. * util.types.isSymbolObject(symbol); // Returns false
  2195. * util.types.isSymbolObject(Object(symbol)); // Returns true
  2196. * ```
  2197. * @since v10.0.0
  2198. */
  2199. function isSymbolObject(object: unknown): object is Symbol;
  2200. /**
  2201. * Returns `true` if the value is a built-in [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) instance.
  2202. *
  2203. * ```js
  2204. * util.types.isTypedArray(new ArrayBuffer()); // Returns false
  2205. * util.types.isTypedArray(new Uint8Array()); // Returns true
  2206. * util.types.isTypedArray(new Float64Array()); // Returns true
  2207. * ```
  2208. *
  2209. * See also [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
  2210. * @since v10.0.0
  2211. */
  2212. function isTypedArray(object: unknown): object is NodeJS.TypedArray;
  2213. /**
  2214. * Returns `true` if the value is a built-in [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) instance.
  2215. *
  2216. * ```js
  2217. * util.types.isUint8Array(new ArrayBuffer()); // Returns false
  2218. * util.types.isUint8Array(new Uint8Array()); // Returns true
  2219. * util.types.isUint8Array(new Float64Array()); // Returns false
  2220. * ```
  2221. * @since v10.0.0
  2222. */
  2223. function isUint8Array(object: unknown): object is Uint8Array;
  2224. /**
  2225. * Returns `true` if the value is a built-in [`Uint8ClampedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray) instance.
  2226. *
  2227. * ```js
  2228. * util.types.isUint8ClampedArray(new ArrayBuffer()); // Returns false
  2229. * util.types.isUint8ClampedArray(new Uint8ClampedArray()); // Returns true
  2230. * util.types.isUint8ClampedArray(new Float64Array()); // Returns false
  2231. * ```
  2232. * @since v10.0.0
  2233. */
  2234. function isUint8ClampedArray(object: unknown): object is Uint8ClampedArray;
  2235. /**
  2236. * Returns `true` if the value is a built-in [`Uint16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array) instance.
  2237. *
  2238. * ```js
  2239. * util.types.isUint16Array(new ArrayBuffer()); // Returns false
  2240. * util.types.isUint16Array(new Uint16Array()); // Returns true
  2241. * util.types.isUint16Array(new Float64Array()); // Returns false
  2242. * ```
  2243. * @since v10.0.0
  2244. */
  2245. function isUint16Array(object: unknown): object is Uint16Array;
  2246. /**
  2247. * Returns `true` if the value is a built-in [`Uint32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array) instance.
  2248. *
  2249. * ```js
  2250. * util.types.isUint32Array(new ArrayBuffer()); // Returns false
  2251. * util.types.isUint32Array(new Uint32Array()); // Returns true
  2252. * util.types.isUint32Array(new Float64Array()); // Returns false
  2253. * ```
  2254. * @since v10.0.0
  2255. */
  2256. function isUint32Array(object: unknown): object is Uint32Array;
  2257. /**
  2258. * Returns `true` if the value is a built-in [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) instance.
  2259. *
  2260. * ```js
  2261. * util.types.isWeakMap(new WeakMap()); // Returns true
  2262. * ```
  2263. * @since v10.0.0
  2264. */
  2265. function isWeakMap(object: unknown): object is WeakMap<object, unknown>;
  2266. /**
  2267. * Returns `true` if the value is a built-in [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) instance.
  2268. *
  2269. * ```js
  2270. * util.types.isWeakSet(new WeakSet()); // Returns true
  2271. * ```
  2272. * @since v10.0.0
  2273. */
  2274. function isWeakSet(object: unknown): object is WeakSet<object>;
  2275. /**
  2276. * Returns `true` if `value` is a `KeyObject`, `false` otherwise.
  2277. * @since v16.2.0
  2278. */
  2279. function isKeyObject(object: unknown): object is KeyObject;
  2280. /**
  2281. * Returns `true` if `value` is a `CryptoKey`, `false` otherwise.
  2282. * @since v16.2.0
  2283. */
  2284. function isCryptoKey(object: unknown): object is webcrypto.CryptoKey;
  2285. }
  2286. declare module "node:util" {
  2287. export * from "util";
  2288. }
  2289. declare module "node:util/types" {
  2290. export * from "util/types";
  2291. }