lazy-result.d.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import Result, { Message, ResultOptions } from './result.js'
  2. import { SourceMap } from './postcss.js'
  3. import Processor from './processor.js'
  4. import Warning from './warning.js'
  5. import Root from './root.js'
  6. declare namespace LazyResult {
  7. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  8. export { LazyResult_ as default }
  9. }
  10. /**
  11. * A Promise proxy for the result of PostCSS transformations.
  12. *
  13. * A `LazyResult` instance is returned by `Processor#process`.
  14. *
  15. * ```js
  16. * const lazy = postcss([autoprefixer]).process(css)
  17. * ```
  18. */
  19. declare class LazyResult_ implements PromiseLike<Result> {
  20. /**
  21. * Processes input CSS through synchronous and asynchronous plugins
  22. * and calls `onFulfilled` with a Result instance. If a plugin throws
  23. * an error, the `onRejected` callback will be executed.
  24. *
  25. * It implements standard Promise API.
  26. *
  27. * ```js
  28. * postcss([autoprefixer]).process(css, { from: cssPath }).then(result => {
  29. * console.log(result.css)
  30. * })
  31. * ```
  32. */
  33. then: Promise<Result>['then']
  34. /**
  35. * Processes input CSS through synchronous and asynchronous plugins
  36. * and calls onRejected for each error thrown in any plugin.
  37. *
  38. * It implements standard Promise API.
  39. *
  40. * ```js
  41. * postcss([autoprefixer]).process(css).then(result => {
  42. * console.log(result.css)
  43. * }).catch(error => {
  44. * console.error(error)
  45. * })
  46. * ```
  47. */
  48. catch: Promise<Result>['catch']
  49. /**
  50. * Processes input CSS through synchronous and asynchronous plugins
  51. * and calls onFinally on any error or when all plugins will finish work.
  52. *
  53. * It implements standard Promise API.
  54. *
  55. * ```js
  56. * postcss([autoprefixer]).process(css).finally(() => {
  57. * console.log('processing ended')
  58. * })
  59. * ```
  60. */
  61. finally: Promise<Result>['finally']
  62. /**
  63. * @param processor Processor used for this transformation.
  64. * @param css CSS to parse and transform.
  65. * @param opts Options from the `Processor#process` or `Root#toResult`.
  66. */
  67. constructor(processor: Processor, css: string, opts: ResultOptions)
  68. /**
  69. * Returns the default string description of an object.
  70. * Required to implement the Promise interface.
  71. */
  72. get [Symbol.toStringTag](): string
  73. /**
  74. * Returns a `Processor` instance, which will be used
  75. * for CSS transformations.
  76. */
  77. get processor(): Processor
  78. /**
  79. * Options from the `Processor#process` call.
  80. */
  81. get opts(): ResultOptions
  82. /**
  83. * Processes input CSS through synchronous plugins, converts `Root`
  84. * to a CSS string and returns `Result#css`.
  85. *
  86. * This property will only work with synchronous plugins.
  87. * If the processor contains any asynchronous plugins
  88. * it will throw an error.
  89. *
  90. * PostCSS runners should always use `LazyResult#then`.
  91. */
  92. get css(): string
  93. /**
  94. * An alias for the `css` property. Use it with syntaxes
  95. * that generate non-CSS output.
  96. *
  97. * This property will only work with synchronous plugins.
  98. * If the processor contains any asynchronous plugins
  99. * it will throw an error.
  100. *
  101. * PostCSS runners should always use `LazyResult#then`.
  102. */
  103. get content(): string
  104. /**
  105. * Processes input CSS through synchronous plugins
  106. * and returns `Result#map`.
  107. *
  108. * This property will only work with synchronous plugins.
  109. * If the processor contains any asynchronous plugins
  110. * it will throw an error.
  111. *
  112. * PostCSS runners should always use `LazyResult#then`.
  113. */
  114. get map(): SourceMap
  115. /**
  116. * Processes input CSS through synchronous plugins
  117. * and returns `Result#root`.
  118. *
  119. * This property will only work with synchronous plugins. If the processor
  120. * contains any asynchronous plugins it will throw an error.
  121. *
  122. * PostCSS runners should always use `LazyResult#then`.
  123. */
  124. get root(): Root
  125. /**
  126. * Processes input CSS through synchronous plugins
  127. * and returns `Result#messages`.
  128. *
  129. * This property will only work with synchronous plugins. If the processor
  130. * contains any asynchronous plugins it will throw an error.
  131. *
  132. * PostCSS runners should always use `LazyResult#then`.
  133. */
  134. get messages(): Message[]
  135. /**
  136. * Processes input CSS through synchronous plugins
  137. * and calls `Result#warnings`.
  138. *
  139. * @return Warnings from plugins.
  140. */
  141. warnings(): Warning[]
  142. /**
  143. * Alias for the `LazyResult#css` property.
  144. *
  145. * ```js
  146. * lazy + '' === lazy.css
  147. * ```
  148. *
  149. * @return Output CSS.
  150. */
  151. toString(): string
  152. /**
  153. * Run plugin in sync way and return `Result`.
  154. *
  155. * @return Result with output content.
  156. */
  157. sync(): Result
  158. /**
  159. * Run plugin in async way and return `Result`.
  160. *
  161. * @return Result with output content.
  162. */
  163. async(): Promise<Result>
  164. }
  165. declare class LazyResult extends LazyResult_ {}
  166. export = LazyResult