This project is no longer being maintened by me. If you want to take ownership over it, just ping me.
Since I'm now using ES6 on my projects (thanks to Babel), I left
sprintf
-like approaches and fully embraced template strings. If you still want this,sprintf-js
seem to cover all your needs (I personally have never used it tho).
Simple string formatter based on the sprintf
implementation.
I've always been a huge fan of sprintf
since the old ActionScript days (I even wrote an AS3 implementation of it). I really like its simplicity. Even the native console
object has basic support for it.
I just wanted a way to mix console
's formatting support with named arguments.
Works well with AMD, Node.js and the browser.
$ npm install matt.js --save
$ bower install matt.js --save
var message = 'Hello %s! \
You\'re our visitor number %d! \
That means you just won %f pounds of Nutella!';
console.log(matt(message, 'John', 1000, 780.35));
// Hello John! You're our visitor number 1000! That means you just won 780.35 pounds of Nutella!
var message = 'Hello user! This is %(name)s %(surname)s. Check %(website)s for more info.',
data = {
name: 'John',
surname: 'Doe',
website: 'http://johndoe.com'
};
console.log(matt(message, data));
// "Hello user! This is John Doe. Check http://johndoe.com for more info."