string-sub
v0.0.1
Published
Super lightweight string substitution module.
Downloads
1,151
Readme
string-sub
Super lightweight string substitution module.
This module is a very simple string substitution module that allows for either key names, or index positions as the placeholder.
Install
$ npm install --save string-sub
Usage
Basic usage
var sub = require('string-sub');
sub('Hello {0}!', 'world');
// => Hello world!
Using variable arguments
sub('Hello {0}, {1}!', 'world', 'nice to meet you');
// => Hello world, nice to meet you!
Using objects
sub('Hello {subject}, {greeting}!', {greeting: 'nice to meet you', subject: 'world'});
// => Hello world, nice to meet you!
Using arrays
sub('Hello {0}, {1}!', ['world', 'nice to meet you']);
// => Hello world, nice to meet you!
License
MIT © Nate Cavanaugh