* Adds a better algorithm for quotation marks' removal.
* Adds a better non-adjacent optimizer compatible with the upcoming new property optimizer.
* Adds minifying remote files directly from CLI.
+* Adds `--rounding-precision` to control rounding precision.
* Moves quotation matching into a `QuoteScanner` class.
* Fixed issue [#134](https://github.com/GoalSmashers/clean-css/issues/134) - merges properties into shorthand form.
* Fixed issue [#164](https://github.com/GoalSmashers/clean-css/issues/164) - removes default values if not needed.
--skip-rebase Disable URLs rebasing
--skip-advanced Disable advanced optimizations - selector & property merging,
reduction, etc.
+--rounding-precision [value] Rounding precision, defaults to 2
-c, --compatibility [ie7|ie8] Force compatibility mode
-d, --debug Shows debug information (minification time & compression efficiency)
```
.option('-s, --skip-import', 'Disable @import processing')
.option('--skip-rebase', 'Disable URLs rebasing')
.option('--skip-advanced', 'Disable advanced optimizations - selector & property merging, reduction, etc.')
+ .option('--rounding-precision [value]', 'Rounding precision, defaults to 2', parseInt)
.option('-c, --compatibility [ie7|ie8]', 'Force compatibility mode')
.option('-t, --timeout [seconds]', 'Per connection timeout when fetching remote @imports (defaults to 5 seconds)')
.option('-d, --debug', 'Shows debug information (minification time & compression efficiency)');
cleanOptions.noAdvanced = true;
if (commands.compatibility)
cleanOptions.compatibility = commands.compatibility;
+if (commands.roundingPrecision !== undefined)
+ cleanOptions.roundingPrecision = commands.roundingPrecision;
if (commands.debug)
cleanOptions.debug = true;
if (commands.timeout)
replace(/(\s|:|,)0+([1-9])/g, '$1$2');
// round pixels to 2nd decimal place
- replace(/\.(\d{3,})px/g, function(match, decimalPlaces) {
- return '.' + Math.round(parseFloat('.' + decimalPlaces) * 100) + 'px';
+ var precision = 'roundingPrecision' in options ? options.roundingPrecision : 2;
+ var decimalMultiplier = Math.pow(10, precision);
+ replace(new RegExp('\\.(\\d{' + (precision + 1) + ',})px', 'g'), function(match, decimalPlaces) {
+ return precision === 0 ?
+ 'px' :
+ '.' + Math.round(parseFloat('.' + decimalPlaces) * decimalMultiplier) / decimalMultiplier + 'px';
});
// .0 to 0
'should not transform source': function(error, stdout) {
assert.equal(stdout, readFile('./test/data/unsupported/selectors-ie8.css'));
}
- })
+ }),
+ 'rounding precision': {
+ defaults: pipedContext('div{width:0.10051px}', '', {
+ 'should keep 2 decimal places': function(error, stdout) {
+ assert.equal(stdout, 'div{width:.1px}');
+ }
+ }),
+ custom: pipedContext('div{width:0.00051px}', '--rounding-precision 4', {
+ 'should keep 4 decimal places': function(error, stdout) {
+ assert.equal(stdout, 'div{width:.0005px}');
+ }
+ }),
+ zero: pipedContext('div{width:1.5051px}', '--rounding-precision 0', {
+ 'should keep 0 decimal places': function(error, stdout) {
+ assert.equal(stdout, 'div{width:1px}');
+ }
+ })
+ }
});
'do not round percentages': 'div{left:20.505%}',
'do not round ems': 'div{font-size:1.505em}'
}),
+ 'floats custom rounding': cssContext({
+ 'rounds to 4 values': [
+ 'div{transform:translateY(-418.505123px)}',
+ 'div{transform:translateY(-418.5051px)}'
+ ]
+ }, { roundingPrecision: 4 }),
'colors': cssContext({
'shorten rgb to standard hexadecimal format': [
'a{ color:rgb(5, 10, 15) }',