string-substitute.js
v0.0.2
Published
Substitute keys in a string to values of json.
Downloads
4
Maintainers
Readme
Substitute
Substitute keys in a string to values of json.
Install
npm i --save substitude
Include
import Substitute from 'substitude'
Initialize
new Substitute();
or
new Substitute(/{([^{]+)}/g, false, true, true);
#params#
regex: regex for replacing, default - /\$([^$ ]+)( |$)/g
inspectObject: flag for parse object, default - true
outUndefined: flag for out undefined, default - false
outNull: flag for out null, default - false
Usages
console.log("My long {first} {second} long {third}".substitute({
first: {value: 'text'},
third: null
}, /{([^{]+)}/g));
|
or with custom regex
|
console.log("My long $first $second long $third".substitute({
first: {a: 'asgsag'},
third: null
}));``