bug4.js
859 Bytes
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
var postcss = require('postcss');
function shouldSetZeroBasis(basisValue) {
if (!basisValue) {
return false;
}
return basisValue === '0' || basisValue.replace(/\s/g, '') === '0px';
}
function properBasis(basis) {
if (shouldSetZeroBasis(basis)) {
return '0%';
}
return basis;
}
module.exports = function(decl) {
if (decl.prop === 'flex') {
var values = postcss.list.space(decl.value);
// set default values
var flexGrow = '0';
var flexShrink = '1';
var flexBasis = '0%';
if (values[0]) {
flexGrow = values[0];
}
if (values[1]) {
if (!isNaN(values[1])) {
flexShrink = values[1];
} else {
flexBasis = values[1];
}
}
if (values[2]) {
flexBasis = values[2];
}
decl.value = flexGrow + ' ' + flexShrink + ' ' + properBasis(flexBasis);
}
};