index.d.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import type {Value} from 'vfile'
  2. import type {CompileResults} from './lib/index.js'
  3. export type {
  4. // `CompileResultMap` is typed and exposed below.
  5. CompileResults,
  6. Compiler,
  7. // `Data` is typed and exposed below.
  8. Parser,
  9. Pluggable,
  10. PluggableList,
  11. Plugin,
  12. PluginTuple,
  13. Preset,
  14. ProcessCallback,
  15. Processor,
  16. RunCallback,
  17. // `Settings` is typed and exposed below.
  18. TransformCallback,
  19. Transformer
  20. } from './lib/index.js'
  21. export {unified} from './lib/index.js'
  22. // See: <https://github.com/sindresorhus/type-fest/blob/main/source/empty-object.d.ts>
  23. declare const emptyObjectSymbol: unique symbol
  24. /**
  25. * Interface of known results from compilers.
  26. *
  27. * Normally, compilers result in text ({@link Value `Value`} of `vfile`).
  28. * When you compile to something else, such as a React node (as in,
  29. * `rehype-react`), you can augment this interface to include that type.
  30. *
  31. * ```ts
  32. * import type {ReactNode} from 'somewhere'
  33. *
  34. * declare module 'unified' {
  35. * interface CompileResultMap {
  36. * // Register a new result (value is used, key should match it).
  37. * ReactNode: ReactNode
  38. * }
  39. * }
  40. *
  41. * export {} // You may not need this, but it makes sure the file is a module.
  42. * ```
  43. *
  44. * Use {@link CompileResults `CompileResults`} to access the values.
  45. */
  46. export interface CompileResultMap {
  47. // Note: if `Value` from `VFile` is changed, this should too.
  48. Uint8Array: Uint8Array
  49. string: string
  50. }
  51. /**
  52. * Interface of known data that can be supported by all plugins.
  53. *
  54. * Typically, options can be given to a specific plugin, but sometimes it makes
  55. * sense to have information shared with several plugins.
  56. * For example, a list of HTML elements that are self-closing, which is needed
  57. * during all phases.
  58. *
  59. * To type this, do something like:
  60. *
  61. * ```ts
  62. * declare module 'unified' {
  63. * interface Data {
  64. * htmlVoidElements?: Array<string> | undefined
  65. * }
  66. * }
  67. *
  68. * export {} // You may not need this, but it makes sure the file is a module.
  69. * ```
  70. */
  71. export interface Data {
  72. settings?: Settings | undefined
  73. }
  74. /**
  75. * Interface of known extra options, that can be supported by parser and
  76. * compilers.
  77. *
  78. * This exists so that users can use packages such as `remark`, which configure
  79. * both parsers and compilers (in this case `remark-parse` and
  80. * `remark-stringify`), and still provide options for them.
  81. *
  82. * When you make parsers or compilers, that could be packaged up together,
  83. * you should support `this.data('settings')` as input and merge it with
  84. * explicitly passed `options`.
  85. * Then, to type it, using `remark-stringify` as an example, do something like:
  86. *
  87. * ```ts
  88. * declare module 'unified' {
  89. * interface Settings {
  90. * bullet: '*' | '+' | '-'
  91. * // …
  92. * }
  93. * }
  94. *
  95. * export {} // You may not need this, but it makes sure the file is a module.
  96. * ```
  97. */
  98. export interface Settings {
  99. [emptyObjectSymbol]?: never
  100. }