Permalink
Browse files

Adding default version of CSS min

  • Loading branch information...
1 parent 74728e1 commit 8a79f833d49e85b3518fe725c5975bfed4e25a2c Johan BLEUZEN committed Sep 30, 2010
Showing with 35 additions and 0 deletions.
  1. +35 −0 cssmin.js
View
@@ -0,0 +1,35 @@
+/*
+ node-cssmin - a css minifier
+
+
+
+*/
+
+
+exports.cssmin = cssmin;
+
+function cssmin(input, linebreak) {
+
+ if(linebreak == null){
+ linebreak = 0;
+ }
+
+ // normalize whitespace
+ output = input.replace(/\s+/g, " ");
+
+ // Remove comments
+ output = output.replace(/\/\*(.*?)\*\//g, "");
+
+ // Remove extra whitespace
+ output = output.replace(/([!{}:;>+\(\[,])\s+/g, "$1");
+
+ if(linebreak == 1){
+ // Option for debug, that adds a linebreak after each rule
+ output = output.replace(/(})/g, "$1\n");
+ }
+
+ // Remove unnecessary 0px, 0em,... Turning them into 0;
+ output = output.replace(/([\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)/g, "$1$2");
+
+ return output;
+}

0 comments on commit 8a79f83

Please sign in to comment.