$ npm install shellsubstitute
Like shell substitution but for your JS.
var substitute = require('shellsubstitute');
substitute('Hi $USER', {USER: 'Josh'}) // Hi Josh
substitute('Hi ${USER}', {USER: 'Josh'}) // Hi Josh
// escape
substitute('Hi \\$USER', {USER: 'Josh'}) // Hi $USER
substitute('Hi \\${USER}', {USER: 'Josh'}) // Hi ${USER}
// escape escapes
substitute('Hi \\\\$USER', {USER: 'Josh'}) // Hi \$USER
substitute('Hi \\\\${USER}', {USER: 'Josh'}) // Hi \${USER}
Variables are $
followed by _
or numbers 0-9
or upper or lower-case characters a-z
.
Variables can be wrapped in braces {...}
. Useful to delimit the variable from following text.
© 2010 - cnpmjs.org x YWFE | Home | YWFE