forked from csscomb/csscomb.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leading-zero.js
46 lines (38 loc) · 937 Bytes
/
leading-zero.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
46
'use strict';
module.exports = {
name: 'leading-zero',
syntax: ['css', 'less', 'sass', 'scss'],
accepts: {
boolean: [true, false]
},
/**
* Processes tree node.
* @param {node} ast
*/
process: function process(ast) {
var value = this.value;
ast.traverseByType('number', function (number) {
if (!value) {
number.content = number.content.replace(/^0+(?=\.)/, '');
} else if (number.content[0] === '.') {
number.content = '0' + number.content;
}
});
},
/**
* Detects the value of an option at the tree node.
*
* @param {node} ast
*/
detect: function detect(ast) {
var detected = [];
ast.traverseByType('number', function (number) {
if (number.content.match(/^\.[0-9]+/)) {
detected.push(false);
} else if (number.content.match(/^0\.[0-9]+/)) {
detected.push(true);
}
});
return detected;
}
};