@e-group/utils
Version:
eGroup team utils that share across projects.
22 lines (19 loc) • 498 B
JavaScript
/**
* Convert double curly brackets with variables into text string.
* For example,
* Hello, {{personName}}. -> Hello, Jerry.
*/
export default function replacer(text, variables) {
let result = text;
if (variables) {
Object.keys(variables).forEach(key => {
const replace = "{{".concat(key, "}}");
const re = new RegExp(replace, 'g');
const value = variables[key];
if (value) {
result = result.replace(re, value);
}
});
}
return result;
}