lazy-result.d.ts 4.5 KB

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