poe-i18n
Version:
i18n utility for Path of Exile
15 lines (14 loc) • 522 B
JavaScript
/**
*
* @param message - conforming to ICU message syntax
* @param args - if the message requires arguments pass them in this object or an error is thrown
*/
export default function formatMessage(message, args) {
if (args === void 0) { args = {}; }
return message.replace(/\{([^}]+)\}/g, function (_, arg_name) {
if (args.hasOwnProperty(arg_name) === false) {
throw new Error("Message required '" + arg_name + "' to be present.");
}
return String(args[arg_name]);
});
}