Skip to content

Commit

Permalink
fix trailing zero with non-zero value
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound authored and ben-eb committed Feb 26, 2017
1 parent d3ac55d commit 8717071
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/postcss-convert-values/index.js
Expand Up @@ -20,14 +20,19 @@ function durationOptimiser (value) {

function lengthOptimiser (value, prop) {
if (length.test(value)) {
var isZero = false;
value = value.replace(length, function (_, num, unit) {
isZero = parseFloat(num) === 0;
return converter(num, unit);
});
if (!~prop.indexOf('flex') && isZero) {
return '0';
var match = value.match(length),
num = match[1],
integer = parseInt(num),
unit = match[2];
if (parseFloat(num) === integer) {
num = integer;
}
if (num !== 0) {
num = converter(num, unit);
} else if (~prop.indexOf('flex')) {
return value;
}
return num;
}
return value;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/postcss-convert-values/test.js
Expand Up @@ -43,6 +43,10 @@ var tests = [{
message: 'should trim trailing zeros + unit',
fixture: 'h1{width:0.00px}',
expected: 'h1{width:0}'
}, {
message: 'should trim trailing zeros without unit',
fixture: 'h1{width:100.00%}',
expected: 'h1{width:100%}'
}, {
message: 'should not mangle flex basis',
fixture: 'h1{flex-basis:0%}',
Expand Down

0 comments on commit 8717071

Please sign in to comment.