Result

Result

Provides the result of the PostCSS transformations.

A Result instance is returned by LazyResult#then or Root#toResult methods.

Constructor

new Result(processor, root, opts)

Source:
Examples
postcss([cssnext]).process(css).then(result => {
 console.log(result.css)
})
const result2 = postcss.parse(css).toResult()
Parameters:
Name Type Description
processor Processor

Processor used for this transformation.

root Root

Root node after all transformations.

opts processOptions

Options from the Processor#process or Root#toResult.

Members

content :string

Source:

An alias for the Result#css property. Use it with syntaxes that generate non-CSS output.

Type:
  • string
Example
result.css === result.content

css :string

Source:

A CSS string representing of Result#root.

Type:
  • string
Example
postcss.parse('a{}').toResult().css //=> "a{}"

map :SourceMapGenerator

Source:

An instance of SourceMapGenerator class from the source-map library, representing changes to the Result#root instance.

Type:
  • SourceMapGenerator
Examples
result.map.toJSON() //=> { version: 3, file: 'a.css', … }
if (result.map) {
  fs.writeFileSync(result.opts.to + '.map', result.map.toString())
}

messages :Array.<Message>

Source:

Contains messages from plugins (e.g., warnings or custom messages). Each message should have type and plugin properties.

Type:
Example
postcss.plugin('postcss-min-browser', () => {
  return (root, result) => {
    const browsers = detectMinBrowsersByCanIUse(root)
    result.messages.push({
      type: 'min-browser',
      plugin: 'postcss-min-browser',
      browsers
    })
  }
})

opts :processOptions

Source:

Options from the Processor#process or Root#toResult call that produced this Result instance.

Type:
Example
root.toResult(opts).opts === opts

processor :Processor

Source:

The Processor instance used for this transformation.

Type:
Example
for (const plugin of result.processor.plugins) {
  if (plugin.postcssPlugin === 'postcss-bad') {
    throw 'postcss-good is incompatible with postcss-bad'
  }
})

root :Root

Source:

Root node after all transformations.

Type:
Example
root.toResult().root === root

Methods

toString() → {string}

Source:

Returns for @{link Result#css} content.

Example
result + '' === result.css
Returns:

String representing of Result#root.

Type
string

warn(text, optsopt) → {Warning}

Source:

Creates an instance of Warning and adds it to Result#messages.

Parameters:
Name Type Attributes Description
text string

Warning message.

opts Object <optional>

Warning options.

Properties
Name Type Description
node Node

CSS node that caused the warning.

word string

Word in CSS source that caused the warning.

index number

Index in CSS node string that caused the warning.

plugin string

Name of the plugin that created this warning. Result#warn fills this property automatically.

Returns:

Created warning.

Type
Warning

warnings() → {Array.<Warning>}

Source:

Returns warnings from plugins. Filters Warning instances from Result#messages.

Example
result.warnings().forEach(warn => {
  console.warn(warn.toString())
})
Returns:

Warnings from plugins.

Type
Array.<Warning>