UNPKG

@n3okill/utils

Version:
19 lines 699 B
import { toString } from "./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 */ export function formatMessage(str, params) { let s = 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