Skip to content

Commit 1ce8bd0

Browse files
dennisfrankMoOx
authored andcommitted
Fixed: zero values are not unitless anymore (#11)
Browsers do not calculate calc() with 0 unitless values http://jsbin.com/punivivipo/edit?html,css,output
1 parent 0add031 commit 1ce8bd0

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,8 @@ function reduceCSSCalc(value, decimalPrecision) {
8989
result = Math.round(result * decimalPrecision) / decimalPrecision
9090
}
9191

92-
// We don't need units for zero values...
93-
if (result !== 0) {
94-
result += unit
95-
}
92+
// Add unit
93+
result += unit
9694

9795
return result
9896
}

test/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ test("reduce complexe css calc()", function(t) {
5959
t.equal(reduceCSSCalc("calc((2 * 100) / 12)"), reduceCSSCalc("calc((100 / 12) * 2)"), "indentical, wrong rounded")
6060
t.equal(reduceCSSCalc("calc((2 * 100) / 12)", 3), "16.667", "indentical rounded with options")
6161
t.equal(reduceCSSCalc("calc((100 / 12) * 2)", 3), "16.667", "indentical rounded with options")
62+
t.equal(reduceCSSCalc("calc(50% - 50vw + (100vw - 100vw) / 2 + 1em)"), "calc(50% - 50vw + 0vw / 2 + 1em)", "keep units for zero values")
6263
t.end()
6364
})
6465

0 commit comments

Comments
 (0)