UNPKG

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