cjs-format

1.4.2 • Public • Published

String substitution according to the given format

build status npm version dependencies status devDependencies status Gitter RunKit

Simplified speed-oriented JavaScript equivalent of the C/PHP sprintf function.

Installation

npm install cjs-format

Usage

Add to the scope:

var format = require('cjs-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'));

Development mode

There is a global var DEVELOP which activates additional consistency checks and protection logic not available in release mode.

Contribution

If you have any problems or suggestions please open an issue according to the contribution rules.

License

cjs-format is released under the MIT License.

Package Sidebar

Install

npm i cjs-format

Weekly Downloads

16

Version

1.4.2

License

MIT

Unpacked Size

4.81 kB

Total Files

4

Last publish

Collaborators

  • cjssdk