js-string-format
extend String class with python-esque format function
introduction
This is a small library that extends the String prototype to allow for python like format. It supports multiple ways for replacement which are described in the usage section
install
from git:
npm install "git+https://github.com/belbis/js-string-format"
node/iojs:
npm install js-string-format
browser:
usage
import (node):
;
use:
// numericalvar ret = 'The {0} {1} fox jumps over the {2} dog.' var ret = 'The {0} {1} fox jumps over the {2} dog.' var ret = 'The {0} {1} fox jumps over the {2} dog.' // objectvar ret = 'The quick brown {i} jumps over the lazy {j}'console // The quick brown fox jumps over the lazy dog.
tests
run javascript npm test
notes
this library does not sanitize the input other than simple type checking