UNPKG

@e-group/utils

Version:

eGroup team utils that share across projects.

29 lines (24 loc) 592 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = replacer; /** * Convert double curly brackets with variables into text string. * For example, * Hello, {{personName}}. -> Hello, Jerry. */ 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; }