1.0.0 • Published 9 years ago

es6ish-string-format v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

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 }));
// = 'this is a test'

It can also access object attributes, like so:

var user = { username: 'cdmckay' };
console.log('hello, ${user.username}'.format({ user: user }));
// = 'hello, cdmckay'

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}`);
// = 'hello, cdmckay'

Author

twitter/cdmckay
Cameron McKay

License

This library is available under the MIT license.