UNPKG

@n3okill/utils

Version:
22 lines 827 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatMessage = formatMessage; const toString_1 = require("./toString"); /** * Replace items in string based on given object * Ex: formatMessage("Hello {World}!",{"World":"Joe"}) => Hello Joe! * @param str String to be replaced * @param params Object with items to replace * @returns String with items replaced */ function formatMessage(str, params) { let s = (0, toString_1.toString)(str); for (const key of Object.keys(params)) { // eslint-disable-next-line security/detect-non-literal-regexp const reg = new RegExp(`{${key}}`, "g"); // eslint-disable-next-line security/detect-object-injection s = s.replace(reg, params[key]); } return s; } //# sourceMappingURL=formatMessage.js.map