This week in my spare time I implemented the Python3000 Advanced String Formatting described here.
It was more easy than I apprehended, less than 200 lines (without comments) and I managed to use a minimal amount of regular expressions so it's quite fast. Still, I did this as a hobby and it's the first release so don't expect it to be perfect, I don't recommend to use it in serious projects yet. That said, comments, feedback and patches are more than welcome.
You can submit bugs to the issues tracker on the project page, please specify the plugin (jquery-string) in labels.
The API documentation is here.
// all return "1bc"
$.format('{a}bc', {a:'1'}) // named arguments
$.format('{0}bc', [1]) // array arguments
$.format('{0}bc', 1) // normal arguments
$.format('{a:d}bc', {a:'a1'}) // return "1bc"
$.format('{a:d}bc', {a:1.5}) // return "1bc"
$.format('{a:.2f}bc', {a:'1'}) // returns 1.00bc
$.format('{a:08.2f}bc', {a:'1'}) // return 00001.00bc
$.extend(jQuery.strConversion,
{'U': function(input, arg){ return input.toUpperCase(); }
});
$.format('{0:U}bc', 'a') // return Abc
Does it work on Internet Explorer 4 on my cell phone?
I like it.
permalink DomesticMouse ~ May 17, 2008 at 8:39 p.m.