-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (34 loc) · 867 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
var es = require('event-stream'),
postcss = require('postcss');
module.exports = function (fn, options) {
var transformSelector;
if (!options) {
options = {};
}
transformSelector = postcss(function (css) {
css.eachRule(function (rule) {
if (!options.splitOnCommas) {
rule.selector = fn(rule.selector);
} else {
rule.selectors = rule.selectors.map(fn);
}
});
});
return es.map(function (file, callback) {
var through,
wait;
if (file.isStream()) {
through = es.through();
wait = es.wait(function (err, contents) {
through.write(transformSelector.process(contents).css);
through.end();
});
file.contents.pipe(wait);
file.contents = through;
} else if (file.isBuffer()) {
file.contents = new Buffer(transformSelector.process(file.contents).css);
}
callback(null, file);
});
};