File tree 2 files changed +14
-3
lines changed
2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ function reduceCSSCalc(value, decimalPrecision) {
66
66
}
67
67
68
68
// Remove units in expression:
69
- var toEvaluate = expression . replace ( new RegExp ( unit , "g " ) , "" )
69
+ var toEvaluate = expression . replace ( new RegExp ( unit , "gi " ) , "" )
70
70
var result
71
71
72
72
try {
@@ -134,16 +134,18 @@ function reduceCSSCalc(value, decimalPrecision) {
134
134
135
135
function getUnitsInExpression ( expression ) {
136
136
var uniqueUnits = [ ]
137
- var unitRegEx = / [ \. 0 - 9 ] ( [ % a - z ] + ) / g
137
+ var uniqueLowerCaseUnits = [ ]
138
+ var unitRegEx = / [ \. 0 - 9 ] ( [ % a - z ] + ) / gi
138
139
var matches = unitRegEx . exec ( expression )
139
140
140
141
while ( matches ) {
141
142
if ( ! matches || ! matches [ 1 ] ) {
142
143
continue
143
144
}
144
145
145
- if ( uniqueUnits . indexOf ( matches [ 1 ] ) === - 1 ) {
146
+ if ( uniqueLowerCaseUnits . indexOf ( matches [ 1 ] . toLowerCase ( ) ) === - 1 ) {
146
147
uniqueUnits . push ( matches [ 1 ] )
148
+ uniqueLowerCaseUnits . push ( matches [ 1 ] . toLowerCase ( ) )
147
149
}
148
150
149
151
matches = unitRegEx . exec ( expression )
Original file line number Diff line number Diff line change @@ -104,3 +104,12 @@ test("ignore unrecognized values", function(t) {
104
104
105
105
t . end ( )
106
106
} )
107
+
108
+ test ( "non-lowercase units" , function ( t ) {
109
+ t . equal ( reduceCSSCalc ( "calc(1PX)" ) , "1PX" , "all uppercase" ) ;
110
+ t . equal ( reduceCSSCalc ( "calc(1Px)" ) , "1Px" , "first letter uppercase" ) ;
111
+ t . equal ( reduceCSSCalc ( "calc(50% - 42Px)" ) , "calc(50% - 42Px)" , "preserves percentage" ) ;
112
+ t . equal ( reduceCSSCalc ( "calc(1Px + 1pX)" ) , "2Px" , "combines same units mixed case" ) ;
113
+
114
+ t . end ( )
115
+ } )
You can’t perform that action at this time.
0 commit comments