Trim whitespace
authorvvo <v@fasterize.com>
Wed, 23 May 2012 12:54:25 +0000 (14:54 +0200)
committervvo <v@fasterize.com>
Wed, 23 May 2012 12:54:25 +0000 (14:54 +0200)
lib/clean.js

index ce7f637..ca540d5 100644 (file)
@@ -7,7 +7,7 @@ var CleanCSS = {
     fuchsia: '#f0f',
     yellow: '#ff0'
   },
-  
+
   process: function(data) {
     var specialComments = [],
       contentBlocks = [];
@@ -20,18 +20,18 @@ var CleanCSS = {
         var start = new Date().getTime();
         data = data.replace(pattern, replacement);
         var end = new Date().getTime();
-      
+
         if (end > start)
           util.print(pattern + ' -> ' + (end - start) + ' milliseconds\n');
       }
     };
-    
+
     // strip comments one by one
     for (var end = 0; end < data.length; ) {
       var start = data.indexOf('/*', end);
       end = data.indexOf('*/', start);
       if (start == -1 || end == -1) break;
-      
+
       if (data[start + 2] == '!') {
         // in case of special comments, replace them with a placeholder
         specialComments.push(data.substring(start, end + 2));
@@ -41,12 +41,12 @@ var CleanCSS = {
       }
       end = start;
     }
-    
+
     // replace content: with a placeholder
     for (var end = 0; end < data.length; ) {
       var start = data.indexOf('content', end);
       if (start == -1) break;
-      
+
       var wrapper = /[^ :]/.exec(data.substring(start + 7))[0];
       if (/['"]/.test(wrapper) == false) {
         end = start + 7;
@@ -55,12 +55,12 @@ var CleanCSS = {
 
       var firstIndex = data.indexOf(wrapper, start);
       var lastIndex = data.indexOf(wrapper, firstIndex + 1);
-      
+
       contentBlocks.push(data.substring(firstIndex, lastIndex + 1));
       data = data.substring(0, firstIndex) + '__CSSCONTENT__' + data.substring(lastIndex + 1);
       end = lastIndex + 1;
     }
-    
+
     replace(/;\s*;+/g, ';') // whitespace between semicolons & multiple semicolons
     replace(/\n/g, '') // line breaks
     replace(/\s+/g, ' ') // multiple whitespace
@@ -113,14 +113,14 @@ var CleanCSS = {
     replace(/\*([\.#:\[])/g, '$1') // remove universal selector when not needed (*#id, *.class etc)
     replace(/ {/g, '{') // whitespace before definition
     replace(/\} /g, '}') // whitespace after definition
-    
+
     // Get the special comments, content content, and spaces inside calc back
     replace(/calc\([^\}]+\}/g, function(match) {
       return match.replace(/\+/g, ' + ');
     });
     replace(/__CSSCOMMENT__/g, function() { return specialComments.shift(); });
     replace(/__CSSCONTENT__/g, function() { return contentBlocks.shift(); });
-    
+
     return data.trim() // trim spaces at beginning and end
   }
 };