mirror of
https://github.com/hanzoai/postcss.git
synced 2026-09-24 17:01:56 +00:00
38 lines
918 B
JavaScript
38 lines
918 B
JavaScript
import LazyResult from './lazy-result';
|
|
|
|
export default class Processor {
|
|
|
|
constructor(plugins = []) {
|
|
this.plugins = this.normalize(plugins);
|
|
}
|
|
|
|
use(plugin) {
|
|
this.plugins = this.plugins.concat(this.normalize([plugin]));
|
|
return this;
|
|
}
|
|
|
|
process(css, opts = { }) {
|
|
return new LazyResult(this, css, opts);
|
|
}
|
|
|
|
normalize(plugins) {
|
|
let normalized = [];
|
|
for ( let i of plugins ) {
|
|
let type = typeof i;
|
|
if ( (type === 'object' || type === 'function') && i.postcss ) {
|
|
i = i.postcss;
|
|
}
|
|
|
|
if ( typeof i === 'object' && Array.isArray(i.plugins) ) {
|
|
normalized = normalized.concat(i.plugins);
|
|
} else {
|
|
normalized.push(i);
|
|
}
|
|
}
|
|
return normalized;
|
|
}
|
|
|
|
}
|
|
|
|
Processor.prototype.version = require('../package').version;
|