index.d.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import type {VFile} from './lib/index.js'
  2. // See: <https://github.com/sindresorhus/type-fest/blob/main/source/empty-object.d.ts>
  3. declare const emptyObjectSymbol: unique symbol
  4. // To do: next major: remove.
  5. export type {Options as MessageOptions} from 'vfile-message'
  6. export {VFile} from './lib/index.js'
  7. // To do: next major: remove.
  8. // Deprecated names (w/ prefix):
  9. export type {
  10. Compatible as VFileCompatible,
  11. DataMap as VFileDataMap,
  12. Data as VFileData,
  13. Options as VFileOptions,
  14. ReporterSettings as VFileReporterSettings,
  15. Reporter as VFileReporter,
  16. Value as VFileValue
  17. }
  18. /**
  19. * Things that can be passed to the constructor.
  20. */
  21. export type Compatible = Options | URL | VFile | Value
  22. /**
  23. * Raw source map.
  24. *
  25. * See:
  26. * <https://github.com/mozilla/source-map/blob/60adcb0/source-map.d.ts#L15-L23>.
  27. */
  28. export interface Map {
  29. /**
  30. * The generated file this source map is associated with.
  31. */
  32. file: string
  33. /**
  34. * A string of base64 VLQs which contain the actual mappings.
  35. */
  36. mappings: string
  37. /**
  38. * An array of identifiers which can be referenced by individual mappings.
  39. */
  40. names: Array<string>
  41. /**
  42. * An array of contents of the original source files.
  43. */
  44. sourcesContent?: Array<string> | undefined
  45. /**
  46. * The URL root from which all sources are relative.
  47. */
  48. sourceRoot?: string | undefined
  49. /**
  50. * An array of URLs to the original source files.
  51. */
  52. sources: Array<string>
  53. /**
  54. * Which version of the source map spec this map is following.
  55. */
  56. version: number
  57. }
  58. /**
  59. * This map registers the type of the `data` key of a `VFile`.
  60. *
  61. * This type can be augmented to register custom `data` types.
  62. *
  63. * @example
  64. * declare module 'vfile' {
  65. * interface DataMap {
  66. * // `file.data.name` is typed as `string`
  67. * name: string
  68. * }
  69. * }
  70. */
  71. export interface DataMap {
  72. [emptyObjectSymbol]?: never
  73. }
  74. /**
  75. * Custom info.
  76. *
  77. * Known attributes can be added to {@linkcode DataMap}
  78. */
  79. export type Data = Record<string, unknown> & Partial<DataMap>
  80. /**
  81. * Configuration.
  82. */
  83. export interface Options {
  84. /**
  85. * Arbitrary fields that will be shallow copied over to the new file.
  86. */
  87. [key: string]: unknown
  88. /**
  89. * Set `basename` (name).
  90. */
  91. basename?: string | null | undefined
  92. /**
  93. * Set `cwd` (working directory).
  94. */
  95. cwd?: string | null | undefined
  96. /**
  97. * Set `data` (associated info).
  98. */
  99. data?: Data | null | undefined
  100. /**
  101. * Set `dirname` (path w/o basename).
  102. */
  103. dirname?: string | null | undefined
  104. /**
  105. * Set `extname` (extension with dot).
  106. */
  107. extname?: string | null | undefined
  108. /**
  109. * Set `history` (paths the file moved between).
  110. */
  111. history?: Array<string> | null | undefined
  112. /**
  113. * Set `path` (current path).
  114. */
  115. path?: URL | string | null | undefined
  116. /**
  117. * Set `stem` (name without extension).
  118. */
  119. stem?: string | null | undefined
  120. /**
  121. * Set `value` (the contents of the file).
  122. */
  123. value?: Value | null | undefined
  124. }
  125. /**
  126. * Configuration for reporters.
  127. */
  128. export type ReporterSettings = Record<string, unknown>
  129. /**
  130. * Type for a reporter.
  131. */
  132. export type Reporter<Settings = ReporterSettings> = (
  133. files: Array<VFile>,
  134. options: Settings
  135. ) => string
  136. /**
  137. * Contents of the file.
  138. *
  139. * Can either be text or a `Uint8Array` structure.
  140. */
  141. export type Value = Uint8Array | string