timepiece/node_modules/clean-css/lib/optimizer/level-1/value-optimizers/precision.js

23 lines
748 B
JavaScript
Raw Normal View History

2024-05-14 14:54:12 +00:00
var plugin = {
level1: {
value: function precision(_name, value, options) {
if (!options.precision.enabled || value.indexOf('.') === -1) {
return value;
}
return value
.replace(options.precision.decimalPointMatcher, '$1$2$3')
.replace(options.precision.zeroMatcher, function(match, integerPart, fractionPart, unit) {
var multiplier = options.precision.units[unit].multiplier;
var parsedInteger = parseInt(integerPart);
var integer = Number.isNaN(parsedInteger) ? 0 : parsedInteger;
var fraction = parseFloat(fractionPart);
return Math.round((integer + fraction) * multiplier) / multiplier + unit;
});
}
}
};
module.exports = plugin;