poe-i18n
Version:
i18n utility for Path of Exile
18 lines (17 loc) • 617 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
*
* @param message - conforming to ICU message syntax
* @param args - if the message requires arguments pass them in this object or an error is thrown
*/
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]);
});
}
exports.default = formatMessage;