stb-util-format
v1.3.0
Published
String substitution according to the given format.
Downloads
3
Maintainers
Readme
String substitution according to the given format
util-format
is simplified speed-oriented JavaScript equivalent of the C/PHP sprintf
function.
Installation
npm install stb-util-format
Usage
Add to the scope:
var format = require('stb-util-format');
Simple replacement:
// This is a cat
console.log(format('This is a {0}', 'cat'));
Multiple replacement:
// This is a cat and a dog
console.log(format('This is a {0} and a {1}', 'cat', 'dog'));
Replacement with changed order:
// This is a cat and a dog and another cat
console.log(format('This is a {0} and a {1} and another {0}', 'cat', 'dog'));
Debug mode
There is a global var
DEBUG
which activates additional consistency checks and protection logic not available in release mode.
In debug mode the util method is exposed to the global namespace as window.utilFormat
.
Contribution
If you have any problem or suggestion please open an issue here. Pull requests are welcomed with respect to the JavaScript Code Style.
License
stb-util-format
is released under the GPL-3.0 License.