-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
41 lines (33 loc) · 1.08 KB
/
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
'use strict';
var isPresent = require('is-present');
var hasClassSelector = require('has-class-selector');
module.exports = function classPrefix(prefix, options) {
options = options || {};
var ignored = options.ignored;
return function prefixRules(styling) {
styling.rules.forEach(function(rule) {
if (rule.rules) {
return prefixRules(rule);
}
if (!rule.selectors) return rule;
rule.selectors = rule.selectors.map(function(selector) {
var shouldIgnore = false;
if (hasClassSelector(selector)) {
// Ensure that the selector doesn't match the ignored list
if (isPresent(ignored)) {
shouldIgnore = ignored.some(function(opt) {
if (typeof opt == 'string') {
return selector === opt;
} else if (opt instanceof RegExp) {
return opt.exec(selector);
}
});
}
return shouldIgnore ? selector : selector.split('.').join('.' + prefix);
} else {
return selector;
}
});
});
};
};