ES6-ish String formatter
An JavaScript string formatter that is mostly compatible with ES6 template strings.
Installation
In a browser:
<script src="format.js"></script>
Via bower:
bower install es6ish-string-format
Notes
This method will attach itself to the String prototype. That means that once you include it, you can use it like this:
var test = 'test';
console.log('this is a ${test}'.format({ test: test }));
It can also access object attributes, like so:
var user = { username: 'cdmckay' };
console.log('hello, ${user.username}'.format({ user: user }));
This format method was designed to have a migration path to ES6 template strings. So, if you wanted to convert
the above example to an ES6 template string, simple replace the quotes with backticks and delete the .format(...)
part:
var user = { username: 'cdmckay' };
console.log(`hello, ${user.username}`);
Author
License
This library is available under the MIT license.