if (['ie7', 'ie8'].indexOf(options.compatibility) == -1)
units.push('rem');
options.unitsRegexp = new RegExp('(^|\\s|\\(|,)0(?:' + units.join('|') + ')', 'g');
+
+ options.precision = {};
+ options.precision.value = options.roundingPrecision === undefined ?
+ DEFAULT_ROUNDING_PRECISION :
+ options.roundingPrecision;
+ options.precision.multiplier = Math.pow(10, options.precision.value);
+ options.precision.regexp = new RegExp('\\.(\\d{' + (options.precision.value + 1) + ',})px', 'g');
}
function removeUnsupported(token, compatibility) {
.replace(/(^|\D)0\.(\d)/g, '$1.$2');
}
-function precisionMinifier(_, value, precision) {
- if (precision === undefined)
- precision = DEFAULT_ROUNDING_PRECISION;
- var decimalMultiplier = Math.pow(10, precision);
+function precisionMinifier(_, value, precisionOptions) {
+ if (value.indexOf('.') === -1)
+ return value;
return value
- .replace(new RegExp('\\.(\\d{' + (precision + 1) + ',})px', 'g'), function(match, decimalPlaces) {
- var newFraction = Math.round(parseFloat('.' + decimalPlaces) * decimalMultiplier) / decimalMultiplier;
- return precision === 0 || newFraction === 0 ?
+ .replace(precisionOptions.regexp, function(match, decimalPlaces) {
+ var newFraction = Math.round(parseFloat('.' + decimalPlaces) * precisionOptions.multiplier) / precisionOptions.multiplier;
+ return precisionOptions.value === 0 || newFraction === 0 ?
'px' :
'.' + ('' + newFraction).substring('0.'.length) + 'px';
})
value = valueMinifiers[property](value);
value = zeroMinifier(property, value);
- value = precisionMinifier(property, value, options.roundingPrecision);
+ value = precisionMinifier(property, value, options.precision);
value = unitMinifier(property, value, options.unitsRegexp);
value = multipleZerosMinifier(property, value);
value = colorMininifier(property, value, options.compatibility);