stb-util-format

1.3.0 • Public • Published

String substitution according to the given format

NPM version Dependencies Status Gitter

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.

Package Sidebar

Install

npm i stb-util-format

Weekly Downloads

0

Version

1.3.0

License

GPL-3.0

Last publish

Collaborators

  • mullock