New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

es6ish-string-format

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6ish-string-format

An ES5 JavaScript string formatter compatible with ES6-style template strings

1.0.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 04 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts