index.d.ts 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. import {CallableInstance} from './callable-instance.js'
  2. /**
  3. * @template {Node | undefined} [ParseTree=undefined]
  4. * Output of `parse` (optional).
  5. * @template {Node | undefined} [HeadTree=undefined]
  6. * Input for `run` (optional).
  7. * @template {Node | undefined} [TailTree=undefined]
  8. * Output for `run` (optional).
  9. * @template {Node | undefined} [CompileTree=undefined]
  10. * Input of `stringify` (optional).
  11. * @template {CompileResults | undefined} [CompileResult=undefined]
  12. * Output of `stringify` (optional).
  13. * @extends {CallableInstance<[], Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>>}
  14. */
  15. export class Processor<ParseTree extends import("unist").Node | undefined = undefined, HeadTree extends import("unist").Node | undefined = undefined, TailTree extends import("unist").Node | undefined = undefined, CompileTree extends import("unist").Node | undefined = undefined, CompileResult extends CompileResults | undefined = undefined> extends CallableInstance<[], Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>> {
  16. /**
  17. * Create a processor.
  18. */
  19. constructor();
  20. /**
  21. * Compiler to use (deprecated).
  22. *
  23. * @deprecated
  24. * Use `compiler` instead.
  25. * @type {(
  26. * Compiler<
  27. * CompileTree extends undefined ? Node : CompileTree,
  28. * CompileResult extends undefined ? CompileResults : CompileResult
  29. * > |
  30. * undefined
  31. * )}
  32. */
  33. Compiler: (Compiler<CompileTree extends undefined ? Node : CompileTree, CompileResult extends undefined ? CompileResults : CompileResult> | undefined);
  34. /**
  35. * Parser to use (deprecated).
  36. *
  37. * @deprecated
  38. * Use `parser` instead.
  39. * @type {(
  40. * Parser<ParseTree extends undefined ? Node : ParseTree> |
  41. * undefined
  42. * )}
  43. */
  44. Parser: (Parser<ParseTree extends undefined ? Node : ParseTree> | undefined);
  45. /**
  46. * Internal list of configured plugins.
  47. *
  48. * @deprecated
  49. * This is a private internal property and should not be used.
  50. * @type {Array<PluginTuple<Array<unknown>>>}
  51. */
  52. attachers: Array<[plugin: Plugin<unknown[], undefined, undefined>, ...parameters: unknown[]]>;
  53. /**
  54. * Compiler to use.
  55. *
  56. * @type {(
  57. * Compiler<
  58. * CompileTree extends undefined ? Node : CompileTree,
  59. * CompileResult extends undefined ? CompileResults : CompileResult
  60. * > |
  61. * undefined
  62. * )}
  63. */
  64. compiler: (Compiler<CompileTree extends undefined ? Node : CompileTree, CompileResult extends undefined ? CompileResults : CompileResult> | undefined);
  65. /**
  66. * Internal state to track where we are while freezing.
  67. *
  68. * @deprecated
  69. * This is a private internal property and should not be used.
  70. * @type {number}
  71. */
  72. freezeIndex: number;
  73. /**
  74. * Internal state to track whether we’re frozen.
  75. *
  76. * @deprecated
  77. * This is a private internal property and should not be used.
  78. * @type {boolean | undefined}
  79. */
  80. frozen: boolean | undefined;
  81. /**
  82. * Internal state.
  83. *
  84. * @deprecated
  85. * This is a private internal property and should not be used.
  86. * @type {Data}
  87. */
  88. namespace: Data;
  89. /**
  90. * Parser to use.
  91. *
  92. * @type {(
  93. * Parser<ParseTree extends undefined ? Node : ParseTree> |
  94. * undefined
  95. * )}
  96. */
  97. parser: (Parser<ParseTree extends undefined ? Node : ParseTree> | undefined);
  98. /**
  99. * Internal list of configured transformers.
  100. *
  101. * @deprecated
  102. * This is a private internal property and should not be used.
  103. * @type {Pipeline}
  104. */
  105. transformers: Pipeline;
  106. /**
  107. * Copy a processor.
  108. *
  109. * @deprecated
  110. * This is a private internal method and should not be used.
  111. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  112. * New *unfrozen* processor ({@link Processor `Processor`}) that is
  113. * configured to work the same as its ancestor.
  114. * When the descendant processor is configured in the future it does not
  115. * affect the ancestral processor.
  116. */
  117. copy(): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>;
  118. /**
  119. * Configure the processor with info available to all plugins.
  120. * Information is stored in an object.
  121. *
  122. * Typically, options can be given to a specific plugin, but sometimes it
  123. * makes sense to have information shared with several plugins.
  124. * For example, a list of HTML elements that are self-closing, which is
  125. * needed during all phases.
  126. *
  127. * > 👉 **Note**: setting information cannot occur on *frozen* processors.
  128. * > Call the processor first to create a new unfrozen processor.
  129. *
  130. * > 👉 **Note**: to register custom data in TypeScript, augment the
  131. * > {@link Data `Data`} interface.
  132. *
  133. * @example
  134. * This example show how to get and set info:
  135. *
  136. * ```js
  137. * import {unified} from 'unified'
  138. *
  139. * const processor = unified().data('alpha', 'bravo')
  140. *
  141. * processor.data('alpha') // => 'bravo'
  142. *
  143. * processor.data() // => {alpha: 'bravo'}
  144. *
  145. * processor.data({charlie: 'delta'})
  146. *
  147. * processor.data() // => {charlie: 'delta'}
  148. * ```
  149. *
  150. * @template {keyof Data} Key
  151. *
  152. * @overload
  153. * @returns {Data}
  154. *
  155. * @overload
  156. * @param {Data} dataset
  157. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  158. *
  159. * @overload
  160. * @param {Key} key
  161. * @returns {Data[Key]}
  162. *
  163. * @overload
  164. * @param {Key} key
  165. * @param {Data[Key]} value
  166. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  167. *
  168. * @param {Data | Key} [key]
  169. * Key to get or set, or entire dataset to set, or nothing to get the
  170. * entire dataset (optional).
  171. * @param {Data[Key]} [value]
  172. * Value to set (optional).
  173. * @returns {unknown}
  174. * The current processor when setting, the value at `key` when getting, or
  175. * the entire dataset when getting without key.
  176. */
  177. data<Key extends keyof import("unified").Data>(): Data;
  178. /**
  179. * Configure the processor with info available to all plugins.
  180. * Information is stored in an object.
  181. *
  182. * Typically, options can be given to a specific plugin, but sometimes it
  183. * makes sense to have information shared with several plugins.
  184. * For example, a list of HTML elements that are self-closing, which is
  185. * needed during all phases.
  186. *
  187. * > 👉 **Note**: setting information cannot occur on *frozen* processors.
  188. * > Call the processor first to create a new unfrozen processor.
  189. *
  190. * > 👉 **Note**: to register custom data in TypeScript, augment the
  191. * > {@link Data `Data`} interface.
  192. *
  193. * @example
  194. * This example show how to get and set info:
  195. *
  196. * ```js
  197. * import {unified} from 'unified'
  198. *
  199. * const processor = unified().data('alpha', 'bravo')
  200. *
  201. * processor.data('alpha') // => 'bravo'
  202. *
  203. * processor.data() // => {alpha: 'bravo'}
  204. *
  205. * processor.data({charlie: 'delta'})
  206. *
  207. * processor.data() // => {charlie: 'delta'}
  208. * ```
  209. *
  210. * @template {keyof Data} Key
  211. *
  212. * @overload
  213. * @returns {Data}
  214. *
  215. * @overload
  216. * @param {Data} dataset
  217. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  218. *
  219. * @overload
  220. * @param {Key} key
  221. * @returns {Data[Key]}
  222. *
  223. * @overload
  224. * @param {Key} key
  225. * @param {Data[Key]} value
  226. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  227. *
  228. * @param {Data | Key} [key]
  229. * Key to get or set, or entire dataset to set, or nothing to get the
  230. * entire dataset (optional).
  231. * @param {Data[Key]} [value]
  232. * Value to set (optional).
  233. * @returns {unknown}
  234. * The current processor when setting, the value at `key` when getting, or
  235. * the entire dataset when getting without key.
  236. */
  237. data<Key extends keyof import("unified").Data>(dataset: Data): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>;
  238. /**
  239. * Configure the processor with info available to all plugins.
  240. * Information is stored in an object.
  241. *
  242. * Typically, options can be given to a specific plugin, but sometimes it
  243. * makes sense to have information shared with several plugins.
  244. * For example, a list of HTML elements that are self-closing, which is
  245. * needed during all phases.
  246. *
  247. * > 👉 **Note**: setting information cannot occur on *frozen* processors.
  248. * > Call the processor first to create a new unfrozen processor.
  249. *
  250. * > 👉 **Note**: to register custom data in TypeScript, augment the
  251. * > {@link Data `Data`} interface.
  252. *
  253. * @example
  254. * This example show how to get and set info:
  255. *
  256. * ```js
  257. * import {unified} from 'unified'
  258. *
  259. * const processor = unified().data('alpha', 'bravo')
  260. *
  261. * processor.data('alpha') // => 'bravo'
  262. *
  263. * processor.data() // => {alpha: 'bravo'}
  264. *
  265. * processor.data({charlie: 'delta'})
  266. *
  267. * processor.data() // => {charlie: 'delta'}
  268. * ```
  269. *
  270. * @template {keyof Data} Key
  271. *
  272. * @overload
  273. * @returns {Data}
  274. *
  275. * @overload
  276. * @param {Data} dataset
  277. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  278. *
  279. * @overload
  280. * @param {Key} key
  281. * @returns {Data[Key]}
  282. *
  283. * @overload
  284. * @param {Key} key
  285. * @param {Data[Key]} value
  286. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  287. *
  288. * @param {Data | Key} [key]
  289. * Key to get or set, or entire dataset to set, or nothing to get the
  290. * entire dataset (optional).
  291. * @param {Data[Key]} [value]
  292. * Value to set (optional).
  293. * @returns {unknown}
  294. * The current processor when setting, the value at `key` when getting, or
  295. * the entire dataset when getting without key.
  296. */
  297. data<Key extends keyof import("unified").Data>(key: Key): import("unified").Data[Key];
  298. /**
  299. * Configure the processor with info available to all plugins.
  300. * Information is stored in an object.
  301. *
  302. * Typically, options can be given to a specific plugin, but sometimes it
  303. * makes sense to have information shared with several plugins.
  304. * For example, a list of HTML elements that are self-closing, which is
  305. * needed during all phases.
  306. *
  307. * > 👉 **Note**: setting information cannot occur on *frozen* processors.
  308. * > Call the processor first to create a new unfrozen processor.
  309. *
  310. * > 👉 **Note**: to register custom data in TypeScript, augment the
  311. * > {@link Data `Data`} interface.
  312. *
  313. * @example
  314. * This example show how to get and set info:
  315. *
  316. * ```js
  317. * import {unified} from 'unified'
  318. *
  319. * const processor = unified().data('alpha', 'bravo')
  320. *
  321. * processor.data('alpha') // => 'bravo'
  322. *
  323. * processor.data() // => {alpha: 'bravo'}
  324. *
  325. * processor.data({charlie: 'delta'})
  326. *
  327. * processor.data() // => {charlie: 'delta'}
  328. * ```
  329. *
  330. * @template {keyof Data} Key
  331. *
  332. * @overload
  333. * @returns {Data}
  334. *
  335. * @overload
  336. * @param {Data} dataset
  337. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  338. *
  339. * @overload
  340. * @param {Key} key
  341. * @returns {Data[Key]}
  342. *
  343. * @overload
  344. * @param {Key} key
  345. * @param {Data[Key]} value
  346. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  347. *
  348. * @param {Data | Key} [key]
  349. * Key to get or set, or entire dataset to set, or nothing to get the
  350. * entire dataset (optional).
  351. * @param {Data[Key]} [value]
  352. * Value to set (optional).
  353. * @returns {unknown}
  354. * The current processor when setting, the value at `key` when getting, or
  355. * the entire dataset when getting without key.
  356. */
  357. data<Key extends keyof import("unified").Data>(key: Key, value: import("unified").Data[Key]): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>;
  358. /**
  359. * Freeze a processor.
  360. *
  361. * Frozen processors are meant to be extended and not to be configured
  362. * directly.
  363. *
  364. * When a processor is frozen it cannot be unfrozen.
  365. * New processors working the same way can be created by calling the
  366. * processor.
  367. *
  368. * It’s possible to freeze processors explicitly by calling `.freeze()`.
  369. * Processors freeze automatically when `.parse()`, `.run()`, `.runSync()`,
  370. * `.stringify()`, `.process()`, or `.processSync()` are called.
  371. *
  372. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  373. * The current processor.
  374. */
  375. freeze(): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>;
  376. /**
  377. * Parse text to a syntax tree.
  378. *
  379. * > 👉 **Note**: `parse` freezes the processor if not already *frozen*.
  380. *
  381. * > 👉 **Note**: `parse` performs the parse phase, not the run phase or other
  382. * > phases.
  383. *
  384. * @param {Compatible | undefined} [file]
  385. * file to parse (optional); typically `string` or `VFile`; any value
  386. * accepted as `x` in `new VFile(x)`.
  387. * @returns {ParseTree extends undefined ? Node : ParseTree}
  388. * Syntax tree representing `file`.
  389. */
  390. parse(file?: Compatible | undefined): ParseTree extends undefined ? Node : ParseTree;
  391. /**
  392. * Process the given file as configured on the processor.
  393. *
  394. * > 👉 **Note**: `process` freezes the processor if not already *frozen*.
  395. *
  396. * > 👉 **Note**: `process` performs the parse, run, and stringify phases.
  397. *
  398. * @overload
  399. * @param {Compatible | undefined} file
  400. * @param {ProcessCallback<VFileWithOutput<CompileResult>>} done
  401. * @returns {undefined}
  402. *
  403. * @overload
  404. * @param {Compatible | undefined} [file]
  405. * @returns {Promise<VFileWithOutput<CompileResult>>}
  406. *
  407. * @param {Compatible | undefined} [file]
  408. * File (optional); typically `string` or `VFile`]; any value accepted as
  409. * `x` in `new VFile(x)`.
  410. * @param {ProcessCallback<VFileWithOutput<CompileResult>> | undefined} [done]
  411. * Callback (optional).
  412. * @returns {Promise<VFile> | undefined}
  413. * Nothing if `done` is given.
  414. * Otherwise a promise, rejected with a fatal error or resolved with the
  415. * processed file.
  416. *
  417. * The parsed, transformed, and compiled value is available at
  418. * `file.value` (see note).
  419. *
  420. * > 👉 **Note**: unified typically compiles by serializing: most
  421. * > compilers return `string` (or `Uint8Array`).
  422. * > Some compilers, such as the one configured with
  423. * > [`rehype-react`][rehype-react], return other values (in this case, a
  424. * > React tree).
  425. * > If you’re using a compiler that doesn’t serialize, expect different
  426. * > result values.
  427. * >
  428. * > To register custom results in TypeScript, add them to
  429. * > {@link CompileResultMap `CompileResultMap`}.
  430. *
  431. * [rehype-react]: https://github.com/rehypejs/rehype-react
  432. */
  433. process(file: Compatible | undefined, done: ProcessCallback<VFileWithOutput<CompileResult>>): undefined;
  434. /**
  435. * Process the given file as configured on the processor.
  436. *
  437. * > 👉 **Note**: `process` freezes the processor if not already *frozen*.
  438. *
  439. * > 👉 **Note**: `process` performs the parse, run, and stringify phases.
  440. *
  441. * @overload
  442. * @param {Compatible | undefined} file
  443. * @param {ProcessCallback<VFileWithOutput<CompileResult>>} done
  444. * @returns {undefined}
  445. *
  446. * @overload
  447. * @param {Compatible | undefined} [file]
  448. * @returns {Promise<VFileWithOutput<CompileResult>>}
  449. *
  450. * @param {Compatible | undefined} [file]
  451. * File (optional); typically `string` or `VFile`]; any value accepted as
  452. * `x` in `new VFile(x)`.
  453. * @param {ProcessCallback<VFileWithOutput<CompileResult>> | undefined} [done]
  454. * Callback (optional).
  455. * @returns {Promise<VFile> | undefined}
  456. * Nothing if `done` is given.
  457. * Otherwise a promise, rejected with a fatal error or resolved with the
  458. * processed file.
  459. *
  460. * The parsed, transformed, and compiled value is available at
  461. * `file.value` (see note).
  462. *
  463. * > 👉 **Note**: unified typically compiles by serializing: most
  464. * > compilers return `string` (or `Uint8Array`).
  465. * > Some compilers, such as the one configured with
  466. * > [`rehype-react`][rehype-react], return other values (in this case, a
  467. * > React tree).
  468. * > If you’re using a compiler that doesn’t serialize, expect different
  469. * > result values.
  470. * >
  471. * > To register custom results in TypeScript, add them to
  472. * > {@link CompileResultMap `CompileResultMap`}.
  473. *
  474. * [rehype-react]: https://github.com/rehypejs/rehype-react
  475. */
  476. process(file?: Compatible | undefined): Promise<VFileWithOutput<CompileResult>>;
  477. /**
  478. * Process the given file as configured on the processor.
  479. *
  480. * An error is thrown if asynchronous transforms are configured.
  481. *
  482. * > 👉 **Note**: `processSync` freezes the processor if not already *frozen*.
  483. *
  484. * > 👉 **Note**: `processSync` performs the parse, run, and stringify phases.
  485. *
  486. * @param {Compatible | undefined} [file]
  487. * File (optional); typically `string` or `VFile`; any value accepted as
  488. * `x` in `new VFile(x)`.
  489. * @returns {VFileWithOutput<CompileResult>}
  490. * The processed file.
  491. *
  492. * The parsed, transformed, and compiled value is available at
  493. * `file.value` (see note).
  494. *
  495. * > 👉 **Note**: unified typically compiles by serializing: most
  496. * > compilers return `string` (or `Uint8Array`).
  497. * > Some compilers, such as the one configured with
  498. * > [`rehype-react`][rehype-react], return other values (in this case, a
  499. * > React tree).
  500. * > If you’re using a compiler that doesn’t serialize, expect different
  501. * > result values.
  502. * >
  503. * > To register custom results in TypeScript, add them to
  504. * > {@link CompileResultMap `CompileResultMap`}.
  505. *
  506. * [rehype-react]: https://github.com/rehypejs/rehype-react
  507. */
  508. processSync(file?: Compatible | undefined): VFileWithOutput<CompileResult>;
  509. /**
  510. * Run *transformers* on a syntax tree.
  511. *
  512. * > 👉 **Note**: `run` freezes the processor if not already *frozen*.
  513. *
  514. * > 👉 **Note**: `run` performs the run phase, not other phases.
  515. *
  516. * @overload
  517. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  518. * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
  519. * @returns {undefined}
  520. *
  521. * @overload
  522. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  523. * @param {Compatible | undefined} file
  524. * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
  525. * @returns {undefined}
  526. *
  527. * @overload
  528. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  529. * @param {Compatible | undefined} [file]
  530. * @returns {Promise<TailTree extends undefined ? Node : TailTree>}
  531. *
  532. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  533. * Tree to transform and inspect.
  534. * @param {(
  535. * RunCallback<TailTree extends undefined ? Node : TailTree> |
  536. * Compatible
  537. * )} [file]
  538. * File associated with `node` (optional); any value accepted as `x` in
  539. * `new VFile(x)`.
  540. * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} [done]
  541. * Callback (optional).
  542. * @returns {Promise<TailTree extends undefined ? Node : TailTree> | undefined}
  543. * Nothing if `done` is given.
  544. * Otherwise, a promise rejected with a fatal error or resolved with the
  545. * transformed tree.
  546. */
  547. run(tree: HeadTree extends undefined ? Node : HeadTree, done: RunCallback<TailTree extends undefined ? Node : TailTree>): undefined;
  548. /**
  549. * Run *transformers* on a syntax tree.
  550. *
  551. * > 👉 **Note**: `run` freezes the processor if not already *frozen*.
  552. *
  553. * > 👉 **Note**: `run` performs the run phase, not other phases.
  554. *
  555. * @overload
  556. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  557. * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
  558. * @returns {undefined}
  559. *
  560. * @overload
  561. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  562. * @param {Compatible | undefined} file
  563. * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
  564. * @returns {undefined}
  565. *
  566. * @overload
  567. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  568. * @param {Compatible | undefined} [file]
  569. * @returns {Promise<TailTree extends undefined ? Node : TailTree>}
  570. *
  571. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  572. * Tree to transform and inspect.
  573. * @param {(
  574. * RunCallback<TailTree extends undefined ? Node : TailTree> |
  575. * Compatible
  576. * )} [file]
  577. * File associated with `node` (optional); any value accepted as `x` in
  578. * `new VFile(x)`.
  579. * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} [done]
  580. * Callback (optional).
  581. * @returns {Promise<TailTree extends undefined ? Node : TailTree> | undefined}
  582. * Nothing if `done` is given.
  583. * Otherwise, a promise rejected with a fatal error or resolved with the
  584. * transformed tree.
  585. */
  586. run(tree: HeadTree extends undefined ? Node : HeadTree, file: Compatible | undefined, done: RunCallback<TailTree extends undefined ? Node : TailTree>): undefined;
  587. /**
  588. * Run *transformers* on a syntax tree.
  589. *
  590. * > 👉 **Note**: `run` freezes the processor if not already *frozen*.
  591. *
  592. * > 👉 **Note**: `run` performs the run phase, not other phases.
  593. *
  594. * @overload
  595. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  596. * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
  597. * @returns {undefined}
  598. *
  599. * @overload
  600. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  601. * @param {Compatible | undefined} file
  602. * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
  603. * @returns {undefined}
  604. *
  605. * @overload
  606. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  607. * @param {Compatible | undefined} [file]
  608. * @returns {Promise<TailTree extends undefined ? Node : TailTree>}
  609. *
  610. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  611. * Tree to transform and inspect.
  612. * @param {(
  613. * RunCallback<TailTree extends undefined ? Node : TailTree> |
  614. * Compatible
  615. * )} [file]
  616. * File associated with `node` (optional); any value accepted as `x` in
  617. * `new VFile(x)`.
  618. * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} [done]
  619. * Callback (optional).
  620. * @returns {Promise<TailTree extends undefined ? Node : TailTree> | undefined}
  621. * Nothing if `done` is given.
  622. * Otherwise, a promise rejected with a fatal error or resolved with the
  623. * transformed tree.
  624. */
  625. run(tree: HeadTree extends undefined ? Node : HeadTree, file?: Compatible | undefined): Promise<TailTree extends undefined ? Node : TailTree>;
  626. /**
  627. * Run *transformers* on a syntax tree.
  628. *
  629. * An error is thrown if asynchronous transforms are configured.
  630. *
  631. * > 👉 **Note**: `runSync` freezes the processor if not already *frozen*.
  632. *
  633. * > 👉 **Note**: `runSync` performs the run phase, not other phases.
  634. *
  635. * @param {HeadTree extends undefined ? Node : HeadTree} tree
  636. * Tree to transform and inspect.
  637. * @param {Compatible | undefined} [file]
  638. * File associated with `node` (optional); any value accepted as `x` in
  639. * `new VFile(x)`.
  640. * @returns {TailTree extends undefined ? Node : TailTree}
  641. * Transformed tree.
  642. */
  643. runSync(tree: HeadTree extends undefined ? Node : HeadTree, file?: Compatible | undefined): TailTree extends undefined ? Node : TailTree;
  644. /**
  645. * Compile a syntax tree.
  646. *
  647. * > 👉 **Note**: `stringify` freezes the processor if not already *frozen*.
  648. *
  649. * > 👉 **Note**: `stringify` performs the stringify phase, not the run phase
  650. * > or other phases.
  651. *
  652. * @param {CompileTree extends undefined ? Node : CompileTree} tree
  653. * Tree to compile.
  654. * @param {Compatible | undefined} [file]
  655. * File associated with `node` (optional); any value accepted as `x` in
  656. * `new VFile(x)`.
  657. * @returns {CompileResult extends undefined ? Value : CompileResult}
  658. * Textual representation of the tree (see note).
  659. *
  660. * > 👉 **Note**: unified typically compiles by serializing: most compilers
  661. * > return `string` (or `Uint8Array`).
  662. * > Some compilers, such as the one configured with
  663. * > [`rehype-react`][rehype-react], return other values (in this case, a
  664. * > React tree).
  665. * > If you’re using a compiler that doesn’t serialize, expect different
  666. * > result values.
  667. * >
  668. * > To register custom results in TypeScript, add them to
  669. * > {@link CompileResultMap `CompileResultMap`}.
  670. *
  671. * [rehype-react]: https://github.com/rehypejs/rehype-react
  672. */
  673. stringify(tree: CompileTree extends undefined ? Node : CompileTree, file?: Compatible | undefined): CompileResult extends undefined ? Value : CompileResult;
  674. /**
  675. * Configure the processor to use a plugin, a list of usable values, or a
  676. * preset.
  677. *
  678. * If the processor is already using a plugin, the previous plugin
  679. * configuration is changed based on the options that are passed in.
  680. * In other words, the plugin is not added a second time.
  681. *
  682. * > 👉 **Note**: `use` cannot be called on *frozen* processors.
  683. * > Call the processor first to create a new unfrozen processor.
  684. *
  685. * @example
  686. * There are many ways to pass plugins to `.use()`.
  687. * This example gives an overview:
  688. *
  689. * ```js
  690. * import {unified} from 'unified'
  691. *
  692. * unified()
  693. * // Plugin with options:
  694. * .use(pluginA, {x: true, y: true})
  695. * // Passing the same plugin again merges configuration (to `{x: true, y: false, z: true}`):
  696. * .use(pluginA, {y: false, z: true})
  697. * // Plugins:
  698. * .use([pluginB, pluginC])
  699. * // Two plugins, the second with options:
  700. * .use([pluginD, [pluginE, {}]])
  701. * // Preset with plugins and settings:
  702. * .use({plugins: [pluginF, [pluginG, {}]], settings: {position: false}})
  703. * // Settings only:
  704. * .use({settings: {position: false}})
  705. * ```
  706. *
  707. * @template {Array<unknown>} [Parameters=[]]
  708. * @template {Node | string | undefined} [Input=undefined]
  709. * @template [Output=Input]
  710. *
  711. * @overload
  712. * @param {Preset | null | undefined} [preset]
  713. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  714. *
  715. * @overload
  716. * @param {PluggableList} list
  717. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  718. *
  719. * @overload
  720. * @param {Plugin<Parameters, Input, Output>} plugin
  721. * @param {...(Parameters | [boolean])} parameters
  722. * @returns {UsePlugin<ParseTree, HeadTree, TailTree, CompileTree, CompileResult, Input, Output>}
  723. *
  724. * @param {PluggableList | Plugin | Preset | null | undefined} value
  725. * Usable value.
  726. * @param {...unknown} parameters
  727. * Parameters, when a plugin is given as a usable value.
  728. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  729. * Current processor.
  730. */
  731. use<Parameters_2 extends unknown[] = [], Input extends string | import("unist").Node | undefined = undefined, Output = Input>(preset?: Preset | null | undefined): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>;
  732. /**
  733. * Configure the processor to use a plugin, a list of usable values, or a
  734. * preset.
  735. *
  736. * If the processor is already using a plugin, the previous plugin
  737. * configuration is changed based on the options that are passed in.
  738. * In other words, the plugin is not added a second time.
  739. *
  740. * > 👉 **Note**: `use` cannot be called on *frozen* processors.
  741. * > Call the processor first to create a new unfrozen processor.
  742. *
  743. * @example
  744. * There are many ways to pass plugins to `.use()`.
  745. * This example gives an overview:
  746. *
  747. * ```js
  748. * import {unified} from 'unified'
  749. *
  750. * unified()
  751. * // Plugin with options:
  752. * .use(pluginA, {x: true, y: true})
  753. * // Passing the same plugin again merges configuration (to `{x: true, y: false, z: true}`):
  754. * .use(pluginA, {y: false, z: true})
  755. * // Plugins:
  756. * .use([pluginB, pluginC])
  757. * // Two plugins, the second with options:
  758. * .use([pluginD, [pluginE, {}]])
  759. * // Preset with plugins and settings:
  760. * .use({plugins: [pluginF, [pluginG, {}]], settings: {position: false}})
  761. * // Settings only:
  762. * .use({settings: {position: false}})
  763. * ```
  764. *
  765. * @template {Array<unknown>} [Parameters=[]]
  766. * @template {Node | string | undefined} [Input=undefined]
  767. * @template [Output=Input]
  768. *
  769. * @overload
  770. * @param {Preset | null | undefined} [preset]
  771. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  772. *
  773. * @overload
  774. * @param {PluggableList} list
  775. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  776. *
  777. * @overload
  778. * @param {Plugin<Parameters, Input, Output>} plugin
  779. * @param {...(Parameters | [boolean])} parameters
  780. * @returns {UsePlugin<ParseTree, HeadTree, TailTree, CompileTree, CompileResult, Input, Output>}
  781. *
  782. * @param {PluggableList | Plugin | Preset | null | undefined} value
  783. * Usable value.
  784. * @param {...unknown} parameters
  785. * Parameters, when a plugin is given as a usable value.
  786. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  787. * Current processor.
  788. */
  789. use<Parameters_2 extends unknown[] = [], Input extends string | import("unist").Node | undefined = undefined, Output = Input>(list: PluggableList): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>;
  790. /**
  791. * Configure the processor to use a plugin, a list of usable values, or a
  792. * preset.
  793. *
  794. * If the processor is already using a plugin, the previous plugin
  795. * configuration is changed based on the options that are passed in.
  796. * In other words, the plugin is not added a second time.
  797. *
  798. * > 👉 **Note**: `use` cannot be called on *frozen* processors.
  799. * > Call the processor first to create a new unfrozen processor.
  800. *
  801. * @example
  802. * There are many ways to pass plugins to `.use()`.
  803. * This example gives an overview:
  804. *
  805. * ```js
  806. * import {unified} from 'unified'
  807. *
  808. * unified()
  809. * // Plugin with options:
  810. * .use(pluginA, {x: true, y: true})
  811. * // Passing the same plugin again merges configuration (to `{x: true, y: false, z: true}`):
  812. * .use(pluginA, {y: false, z: true})
  813. * // Plugins:
  814. * .use([pluginB, pluginC])
  815. * // Two plugins, the second with options:
  816. * .use([pluginD, [pluginE, {}]])
  817. * // Preset with plugins and settings:
  818. * .use({plugins: [pluginF, [pluginG, {}]], settings: {position: false}})
  819. * // Settings only:
  820. * .use({settings: {position: false}})
  821. * ```
  822. *
  823. * @template {Array<unknown>} [Parameters=[]]
  824. * @template {Node | string | undefined} [Input=undefined]
  825. * @template [Output=Input]
  826. *
  827. * @overload
  828. * @param {Preset | null | undefined} [preset]
  829. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  830. *
  831. * @overload
  832. * @param {PluggableList} list
  833. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  834. *
  835. * @overload
  836. * @param {Plugin<Parameters, Input, Output>} plugin
  837. * @param {...(Parameters | [boolean])} parameters
  838. * @returns {UsePlugin<ParseTree, HeadTree, TailTree, CompileTree, CompileResult, Input, Output>}
  839. *
  840. * @param {PluggableList | Plugin | Preset | null | undefined} value
  841. * Usable value.
  842. * @param {...unknown} parameters
  843. * Parameters, when a plugin is given as a usable value.
  844. * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
  845. * Current processor.
  846. */
  847. use<Parameters_2 extends unknown[] = [], Input extends string | import("unist").Node | undefined = undefined, Output = Input>(plugin: Plugin<Parameters_2, Input, Output>, ...parameters: Parameters_2 | [boolean]): UsePlugin<ParseTree, HeadTree, TailTree, CompileTree, CompileResult, Input, Output>;
  848. }
  849. /**
  850. * Create a new processor.
  851. *
  852. * @example
  853. * This example shows how a new processor can be created (from `remark`) and linked
  854. * to **stdin**(4) and **stdout**(4).
  855. *
  856. * ```js
  857. * import process from 'node:process'
  858. * import concatStream from 'concat-stream'
  859. * import {remark} from 'remark'
  860. *
  861. * process.stdin.pipe(
  862. * concatStream(function (buf) {
  863. * process.stdout.write(String(remark().processSync(buf)))
  864. * })
  865. * )
  866. * ```
  867. *
  868. * @returns
  869. * New *unfrozen* processor (`processor`).
  870. *
  871. * This processor is configured to work the same as its ancestor.
  872. * When the descendant processor is configured in the future it does not
  873. * affect the ancestral processor.
  874. */
  875. export const unified: Processor<undefined, undefined, undefined, undefined, undefined>;
  876. export type Pipeline = import('trough').Pipeline;
  877. export type Node = import('unist').Node;
  878. export type Compatible = import('vfile').Compatible;
  879. export type Value = import('vfile').Value;
  880. export type CompileResultMap = import('../index.js').CompileResultMap;
  881. export type Data = import('../index.js').Data;
  882. export type Settings = import('../index.js').Settings;
  883. /**
  884. * Acceptable results from compilers.
  885. *
  886. * To register custom results, add them to
  887. * {@link CompileResultMap `CompileResultMap`}.
  888. */
  889. export type CompileResults = CompileResultMap[keyof CompileResultMap];
  890. /**
  891. * A **compiler** handles the compiling of a syntax tree to something else
  892. * (in most cases, text) (TypeScript type).
  893. *
  894. * It is used in the stringify phase and called with a {@link Node `Node`}
  895. * and {@link VFile `VFile`} representation of the document to compile.
  896. * It should return the textual representation of the given tree (typically
  897. * `string`).
  898. *
  899. * > 👉 **Note**: unified typically compiles by serializing: most compilers
  900. * > return `string` (or `Uint8Array`).
  901. * > Some compilers, such as the one configured with
  902. * > [`rehype-react`][rehype-react], return other values (in this case, a
  903. * > React tree).
  904. * > If you’re using a compiler that doesn’t serialize, expect different
  905. * > result values.
  906. * >
  907. * > To register custom results in TypeScript, add them to
  908. * > {@link CompileResultMap `CompileResultMap`}.
  909. *
  910. * [rehype-react]: https://github.com/rehypejs/rehype-react
  911. */
  912. export type Compiler<Tree extends import("unist").Node = import("unist").Node, Result extends CompileResults = CompileResults> = (tree: Tree, file: VFile) => Result;
  913. /**
  914. * A **parser** handles the parsing of text to a syntax tree.
  915. *
  916. * It is used in the parse phase and is called with a `string` and
  917. * {@link VFile `VFile`} of the document to parse.
  918. * It must return the syntax tree representation of the given file
  919. * ({@link Node `Node`}).
  920. */
  921. export type Parser<Tree extends import("unist").Node = import("unist").Node> = (document: string, file: VFile) => Tree;
  922. /**
  923. * Union of the different ways to add plugins and settings.
  924. */
  925. export type Pluggable = (Plugin<Array<any>, any, any> | PluginTuple<Array<any>, any, any> | Preset);
  926. /**
  927. * List of plugins and presets.
  928. */
  929. export type PluggableList = Array<Pluggable>;
  930. /**
  931. * Single plugin.
  932. *
  933. * Plugins configure the processors they are applied on in the following
  934. * ways:
  935. *
  936. * * they change the processor, such as the parser, the compiler, or by
  937. * configuring data
  938. * * they specify how to handle trees and files
  939. *
  940. * In practice, they are functions that can receive options and configure the
  941. * processor (`this`).
  942. *
  943. * > 👉 **Note**: plugins are called when the processor is *frozen*, not when
  944. * > they are applied.
  945. */
  946. export type Plugin<PluginParameters extends unknown[] = [], Input extends string | import("unist").Node | undefined = import("unist").Node, Output = Input> = (this: Processor, ...parameters: PluginParameters) => Input extends string ? Output extends Node | undefined ? undefined | void : never : Output extends CompileResults ? Input extends Node | undefined ? undefined | void : never : Transformer<Input extends Node ? Input : Node, Output extends Node ? Output : Node> | undefined | void;
  947. /**
  948. * Tuple of a plugin and its configuration.
  949. *
  950. * The first item is a plugin, the rest are its parameters.
  951. */
  952. export type PluginTuple<TupleParameters extends unknown[] = [], Input extends string | import("unist").Node | undefined = undefined, Output = undefined> = ([
  953. plugin: Plugin<TupleParameters, Input, Output>,
  954. ...parameters: TupleParameters
  955. ]);
  956. /**
  957. * Sharable configuration.
  958. *
  959. * They can contain plugins and settings.
  960. */
  961. export type Preset = {
  962. /**
  963. * List of plugins and presets (optional).
  964. */
  965. plugins?: PluggableList | undefined;
  966. /**
  967. * Shared settings for parsers and compilers (optional).
  968. */
  969. settings?: Settings | undefined;
  970. };
  971. /**
  972. * Callback called when the process is done.
  973. *
  974. * Called with either an error or a result.
  975. */
  976. export type ProcessCallback<File extends VFile = VFile> = (error?: Error | undefined, file?: File | undefined) => undefined;
  977. /**
  978. * Callback called when transformers are done.
  979. *
  980. * Called with either an error or results.
  981. */
  982. export type RunCallback<Tree extends import("unist").Node = import("unist").Node> = (error?: Error | undefined, tree?: Tree | undefined, file?: VFile | undefined) => undefined;
  983. /**
  984. * Callback passed to transforms.
  985. *
  986. * If the signature of a `transformer` accepts a third argument, the
  987. * transformer may perform asynchronous operations, and must call it.
  988. */
  989. export type TransformCallback<Output extends import("unist").Node = import("unist").Node> = (error?: Error | undefined, tree?: Output | undefined, file?: VFile | undefined) => undefined;
  990. /**
  991. * Transformers handle syntax trees and files.
  992. *
  993. * They are functions that are called each time a syntax tree and file are
  994. * passed through the run phase.
  995. * When an error occurs in them (either because it’s thrown, returned,
  996. * rejected, or passed to `next`), the process stops.
  997. *
  998. * The run phase is handled by [`trough`][trough], see its documentation for
  999. * the exact semantics of these functions.
  1000. *
  1001. * > 👉 **Note**: you should likely ignore `next`: don’t accept it.
  1002. * > it supports callback-style async work.
  1003. * > But promises are likely easier to reason about.
  1004. *
  1005. * [trough]: https://github.com/wooorm/trough#function-fninput-next
  1006. */
  1007. export type Transformer<Input extends import("unist").Node = import("unist").Node, Output extends import("unist").Node = Input> = (tree: Input, file: VFile, next: TransformCallback<Output>) => (Promise<Output | undefined | void> | Promise<never> | // For some reason this is needed separately.
  1008. Output | Error | undefined | void);
  1009. /**
  1010. * Create a processor based on the input/output of a {@link Plugin plugin}.
  1011. */
  1012. export type UsePlugin<ParseTree extends import("unist").Node | undefined, HeadTree extends import("unist").Node | undefined, TailTree extends import("unist").Node | undefined, CompileTree extends import("unist").Node | undefined, CompileResult extends CompileResults | undefined, Input extends string | import("unist").Node | undefined, Output> = (Input extends string ? Output extends Node | undefined ? Processor<Output extends undefined ? ParseTree : Output, HeadTree, TailTree, CompileTree, CompileResult> : Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult> : Output extends CompileResults ? Input extends Node | undefined ? Processor<ParseTree, HeadTree, TailTree, Input extends undefined ? CompileTree : Input, Output extends undefined ? CompileResult : Output> : Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult> : Input extends Node | undefined ? Output extends Node | undefined ? Processor<ParseTree, HeadTree extends undefined ? Input : HeadTree, Output extends undefined ? TailTree : Output, CompileTree, CompileResult> : Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult> : Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>);
  1013. /**
  1014. * Type to generate a {@link VFile `VFile`} corresponding to a compiler result.
  1015. *
  1016. * If a result that is not acceptable on a `VFile` is used, that will
  1017. * be stored on the `result` field of {@link VFile `VFile`}.
  1018. */
  1019. export type VFileWithOutput<Result extends CompileResults | undefined> = (Result extends Value | undefined ? VFile : VFile & {
  1020. result: Result;
  1021. });
  1022. import { VFile } from 'vfile';
  1023. export {};
  1024. //# sourceMappingURL=index.d.ts.map