0.0.2 • Published 6 years ago

string-substitute.js v0.0.2

Weekly downloads
5
License
ISC
Repository
github
Last release
6 years ago

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
}));``