source: frontend/node_modules/postcss/lib/result.d.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 4.2 KB
Line 
1import {
2 Document,
3 Node,
4 Plugin,
5 ProcessOptions,
6 Root,
7 SourceMap,
8 TransformCallback,
9 Warning,
10 WarningOptions
11} from './postcss.js'
12import Processor from './processor.js'
13
14declare namespace Result {
15 export interface Message {
16 [others: string]: any
17
18 /**
19 * Source PostCSS plugin name.
20 */
21 plugin?: string
22
23 /**
24 * Message type.
25 */
26 type: string
27 }
28
29 export interface ResultOptions extends ProcessOptions {
30 /**
31 * The CSS node that was the source of the warning.
32 */
33 node?: Node
34
35 /**
36 * Name of plugin that created this warning. `Result#warn` will fill it
37 * automatically with `Plugin#postcssPlugin` value.
38 */
39 plugin?: string
40 }
41
42 export { Result_ as default }
43}
44
45/**
46 * Provides the result of the PostCSS transformations.
47 *
48 * A Result instance is returned by `LazyResult#then`
49 * or `Root#toResult` methods.
50 *
51 * ```js
52 * postcss([autoprefixer]).process(css).then(result => {
53 * console.log(result.css)
54 * })
55 * ```
56 *
57 * ```js
58 * const result2 = postcss.parse(css).toResult()
59 * ```
60 */
61declare class Result_<RootNode = Document | Root> {
62 /**
63 * A CSS string representing of `Result#root`.
64 *
65 * ```js
66 * postcss.parse('a{}').toResult().css //=> "a{}"
67 * ```
68 */
69 css: string
70
71 /**
72 * Last runned PostCSS plugin.
73 */
74 lastPlugin: Plugin | TransformCallback
75
76 /**
77 * An instance of `SourceMapGenerator` class from the `source-map` library,
78 * representing changes to the `Result#root` instance.
79 *
80 * ```js
81 * result.map.toJSON() //=> { version: 3, file: 'a.css', … }
82 * ```
83 *
84 * ```js
85 * if (result.map) {
86 * fs.writeFileSync(result.opts.to + '.map', result.map.toString())
87 * }
88 * ```
89 */
90 map: SourceMap
91
92 /**
93 * Contains messages from plugins (e.g., warnings or custom messages).
94 * Each message should have type and plugin properties.
95 *
96 * ```js
97 * AtRule: {
98 * import: (atRule, { result }) {
99 * const importedFile = parseImport(atRule)
100 * result.messages.push({
101 * type: 'dependency',
102 * plugin: 'postcss-import',
103 * file: importedFile,
104 * parent: result.opts.from
105 * })
106 * }
107 * }
108 * ```
109 */
110 messages: Result.Message[]
111
112 /**
113 * Options from the `Processor#process` or `Root#toResult` call
114 * that produced this Result instance.]
115 *
116 * ```js
117 * root.toResult(opts).opts === opts
118 * ```
119 */
120 opts: Result.ResultOptions
121
122 /**
123 * The Processor instance used for this transformation.
124 *
125 * ```js
126 * for (const plugin of result.processor.plugins) {
127 * if (plugin.postcssPlugin === 'postcss-bad') {
128 * throw 'postcss-good is incompatible with postcss-bad'
129 * }
130 * })
131 * ```
132 */
133 processor: Processor
134
135 /**
136 * Root node after all transformations.
137 *
138 * ```js
139 * root.toResult().root === root
140 * ```
141 */
142 root: RootNode
143
144 /**
145 * An alias for the `Result#css` property.
146 * Use it with syntaxes that generate non-CSS output.
147 *
148 * ```js
149 * result.css === result.content
150 * ```
151 */
152 get content(): string
153
154 /**
155 * @param processor Processor used for this transformation.
156 * @param root Root node after all transformations.
157 * @param opts Options from the `Processor#process` or `Root#toResult`.
158 */
159 constructor(processor: Processor, root: RootNode, opts: Result.ResultOptions)
160
161 /**
162 * Returns for `Result#css` content.
163 *
164 * ```js
165 * result + '' === result.css
166 * ```
167 *
168 * @return String representing of `Result#root`.
169 */
170 toString(): string
171
172 /**
173 * Creates an instance of `Warning` and adds it to `Result#messages`.
174 *
175 * ```js
176 * if (decl.important) {
177 * result.warn('Avoid !important', { node: decl, word: '!important' })
178 * }
179 * ```
180 *
181 * @param text Warning message.
182 * @param opts Warning options.
183 * @return Created warning.
184 */
185 warn(message: string, options?: WarningOptions): Warning
186
187 /**
188 * Returns warnings from plugins. Filters `Warning` instances
189 * from `Result#messages`.
190 *
191 * ```js
192 * result.warnings().forEach(warn => {
193 * console.warn(warn.toString())
194 * })
195 * ```
196 *
197 * @return Warnings from plugins.
198 */
199 warnings(): Warning[]
200}
201
202declare class Result<RootNode = Document | Root> extends Result_<RootNode> {}
203
204export = Result
Note: See TracBrowser for help on using the repository browser.