forked from GMchris/postcss-camelcaser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (29 loc) · 1.01 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
var postcss = require('postcss');
module.exports = postcss.plugin('camelcaser', function camelcaser(options) {
return function (css) {
options = options || {};
var forceCaseStyle = options.forceCaseStyle || 'lowerCamelCase';
css.walkRules(function (rule) {
var output = rule.selector.replace(/(-|_){1,}\w/g,
function (match) {
return match[match.length - 1].toUpperCase();
});
switch (forceCaseStyle) {
case 'off':
break;
case 'UpperCamelCase':
output = output.replace(/(\W)[a-z]/g, function (match) {
return match.toUpperCase();
});
break;
case 'lowerCamelCase':
default:
output = output.replace(/(\W)[A-Z]/g, function (match) {
return match.toLowerCase();
});
break;
}
rule.selector = output;
});
};
});