Substitute keys in a string to values of json.
npm i --save substitude
import Substitute from 'substitude'
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
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
}));``