@sebgroup/frontend-tools
Version:
A set of frontend tools
24 lines (20 loc) • 980 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Inserts values in a string
* This is mostly used to insert values in a translation message
* @param {string} str The string that contains the variables
* @param {object} params The params to insert in the string message
* @param {string} symbol The symbol to look for to insert the params in the string message. Default is `@` symbol. You can also pass an array of an openning and closing like this `["{{", "}}"]`
* @returns The replaced string
*/
function stringInsert(str, params, symbol = "@") {
if (str && typeof str === "string") {
for (const key in params) {
str = str.replace(new RegExp(`${Array.isArray(symbol) ? symbol[0] || "@" : symbol}${key}${Array.isArray(symbol) ? symbol[1] || "@" : symbol}`, "g"), String(params[key]));
}
}
return str;
}
exports.stringInsert = stringInsert;
//# sourceMappingURL=stringInsert.js.map