Fixes #215 - adds removing leading zeros from numerical values.
authorGoalSmashers <jakub@goalsmashers.com>
Mon, 3 Feb 2014 04:37:36 +0000 (04:37 +0000)
committerGoalSmashers <jakub@goalsmashers.com>
Mon, 3 Feb 2014 04:37:36 +0000 (04:37 +0000)
E.g 040px can be safely turned into 40px.

History.md
lib/clean.js
test/unit-test.js

index daf1157..8138ce9 100644 (file)
@@ -13,6 +13,7 @@
 * Fixed issue [#186](https://github.com/GoalSmashers/clean-css/issues/186) - strip unit from 0rem.
 * Fixed issue [#207](https://github.com/GoalSmashers/clean-css/issues/207) - bug in parsing protocol `@import`s.
 * Fixed issue [#213](https://github.com/GoalSmashers/clean-css/issues/213) - faster rgb to hex transforms.
+* Fixed issue [#215](https://github.com/GoalSmashers/clean-css/issues/215) - leading zeros in numerical values.
 * Fixed issue [#217](https://github.com/GoalSmashers/clean-css/issues/217) - whitespace inside attribute selectors and urls.
 * Fixed issue [#218](https://github.com/GoalSmashers/clean-css/issues/218) - `@import` statements cleanup.
 * Fixed issue [#220](https://github.com/GoalSmashers/clean-css/issues/220) - selector between comments.
index 16ea17c..07fb88e 100644 (file)
@@ -267,6 +267,9 @@ var minify = function(data, callback) {
   replace(new RegExp('(\\s|:|,)0(?:' + units.join('|') + ')', 'g'), '$1' + '0');
   replace(new RegExp('rect\\(0(?:' + units.join('|') + ')', 'g'), 'rect(0');
 
+  // zero(s) + value to value
+  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';
index bf4c423..976435b 100644 (file)
@@ -511,6 +511,14 @@ vows.describe('clean-units').addBatch({
     'fractions': [
       'div{margin:.1em .1em .1em .1em}',
       'div{margin:.1em}'
+    ],
+    'preceeding value': [
+      'div{padding:010px 00015px}',
+      'div{padding:10px 15px}'
+    ],
+    'preceeding value with fraction zeros': [
+      'div{padding:010.0em .05rem}',
+      'div{padding:10em .05rem}'
     ]
   }),
   'floats': cssContext({