Skip to content
Browse files

add minified version

  • Loading branch information...
1 parent 2aee1a0 commit 4a0f6413bb2b183a6fc537adca17de08d483351c @samsonjs committed Mar 7, 2013
Showing with 18 additions and 1 deletion.
  1. +13 −0 Makefile
  2. +3 −0 format-min.js
  3. +2 −1 test_format.js
View
13 Makefile
@@ -0,0 +1,13 @@
+minify: real-minify test-minified
+
+real-minify: format.js
+ rm -f format-min.js
+ closure <format.js >|format-min.js
+
+test:
+ node test_format.js
+
+test-minified:
+ node test_format.js format-min.js
+
+.PHONY: test test-minified
View
3 format-min.js
@@ -0,0 +1,3 @@
+exports.printf=function(){console.log(exports.format.apply(this,arguments))};
+exports.format=function(d){for(var f=1,i=[].slice.call(arguments),e=0,j=d.length,a="",b,g=!1,h,c=function(){return i[f++]},k=function(){for(var a="";d[e].match(/\d/);)a+=d[e++];return a.length>0?parseInt(a):null};e<j;++e)if(b=d[e],g)switch(g=!1,h=k(),b){case "b":a+=parseInt(c(),10).toString(2);break;case "c":b=c();a+=typeof b==="string"||b instanceof String?b:String.fromCharCode(parseInt(b,10));break;case "d":a+=parseInt(c(),10);break;case "f":a+=parseFloat(c()).toFixed(h||6);break;case "o":a+="0"+
+parseInt(c(),10).toString(8);break;case "s":a+=c();break;case "x":a+="0x"+parseInt(c(),10).toString(16);break;case "X":a+="0x"+parseInt(c(),10).toString(16).toUpperCase();break;default:a+=b}else b==="%"?g=!0:a+=b;return a};exports.vsprintf=function(d,f){return exports.format.apply(this,[d].concat(f))};exports.sprintf=exports.format;
View
3 test_format.js
@@ -1,4 +1,5 @@
-var format = require('./lib')
+var filename = process.argv[2] || './format.js'
+ , format = require(filename)
, printf = format.printf
;

0 comments on commit 4a0f641

Please sign in to comment.
Something went wrong with that request. Please try again.