From 69e2e33e763d4fadecbff6a3a4fd20b6350c006f Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Mon, 3 Feb 2014 04:37:36 +0000 Subject: [PATCH] Fixes #215 - adds removing leading zeros from numerical values. E.g 040px can be safely turned into 40px. --- History.md | 1 + lib/clean.js | 3 +++ test/unit-test.js | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/History.md b/History.md index daf11571..8138ce9a 100644 --- a/History.md +++ b/History.md @@ -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. diff --git a/lib/clean.js b/lib/clean.js index 16ea17c4..07fb88e4 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -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'; diff --git a/test/unit-test.js b/test/unit-test.js index bf4c4237..976435ba 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -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({ -- 2.34.1