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(function (result) {
   console.log(result.css);
});
var 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) => {
    var browsers = detectMinBrowsersByCanIUse(root);
    result.messages.push({
      type:    'min-browser',
      plugin:  'postcss-min-browser',
      browsers: 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 ( let 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>