(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.IntlMessageFormat = {}));
}(this, function (exports) { 'use strict';
var TYPE;
(function (TYPE) {
/**
* Raw text
*/
TYPE[TYPE["literal"] = 0] = "literal";
/**
* Variable w/o any format, e.g `var` in `this is a {var}`
*/
TYPE[TYPE["argument"] = 1] = "argument";
/**
* Variable w/ number format
*/
TYPE[TYPE["number"] = 2] = "number";
/**
* Variable w/ date format
*/
TYPE[TYPE["date"] = 3] = "date";
/**
* Variable w/ time format
*/
TYPE[TYPE["time"] = 4] = "time";
/**
* Variable w/ select format
*/
TYPE[TYPE["select"] = 5] = "select";
/**
* Variable w/ plural format
*/
TYPE[TYPE["plural"] = 6] = "plural";
})(TYPE || (TYPE = {}));
/**
* Type Guards
*/
function isLiteralElement(el) {
return el.type === TYPE.literal;
}
function isArgumentElement(el) {
return el.type === TYPE.argument;
}
function isNumberElement(el) {
return el.type === TYPE.number;
}
function isDateElement(el) {
return el.type === TYPE.date;
}
function isTimeElement(el) {
return el.type === TYPE.time;
}
function isSelectElement(el) {
return el.type === TYPE.select;
}
function isPluralElement(el) {
return el.type === TYPE.plural;
}
// tslint:disable:only-arrow-functions
// tslint:disable:object-literal-shorthand
// tslint:disable:trailing-comma
// tslint:disable:object-literal-sort-keys
// tslint:disable:one-variable-per-declaration
// tslint:disable:max-line-length
// tslint:disable:no-consecutive-blank-lines
// tslint:disable:align
var __extends = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (undefined && undefined.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var SyntaxError = /** @class */ (function (_super) {
__extends(SyntaxError, _super);
function SyntaxError(message, expected, found, location) {
var _this = _super.call(this) || this;
_this.message = message;
_this.expected = expected;
_this.found = found;
_this.location = location;
_this.name = "SyntaxError";
if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(_this, SyntaxError);
}
return _this;
}
SyntaxError.buildMessage = function (expected, found) {
function hex(ch) {
return ch.charCodeAt(0).toString(16).toUpperCase();
}
function literalEscape(s) {
return s
.replace(/\\/g, "\\\\")
.replace(/"/g, "\\\"")
.replace(/\0/g, "\\0")
.replace(/\t/g, "\\t")
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/[\x00-\x0F]/g, function (ch) { return "\\x0" + hex(ch); })
.replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { return "\\x" + hex(ch); });
}
function classEscape(s) {
return s
.replace(/\\/g, "\\\\")
.replace(/\]/g, "\\]")
.replace(/\^/g, "\\^")
.replace(/-/g, "\\-")
.replace(/\0/g, "\\0")
.replace(/\t/g, "\\t")
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/[\x00-\x0F]/g, function (ch) { return "\\x0" + hex(ch); })
.replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { return "\\x" + hex(ch); });
}
function describeExpectation(expectation) {
switch (expectation.type) {
case "literal":
return "\"" + literalEscape(expectation.text) + "\"";
case "class":
var escapedParts = expectation.parts.map(function (part) {
return Array.isArray(part)
? classEscape(part[0]) + "-" + classEscape(part[1])
: classEscape(part);
});
return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
case "any":
return "any character";
case "end":
return "end of input";
case "other":
return expectation.description;
}
}
function describeExpected(expected1) {
var descriptions = expected1.map(describeExpectation);
var i;
var j;
descriptions.sort();
if (descriptions.length > 0) {
for (i = 1, j = 1; i < descriptions.length; i++) {
if (descriptions[i - 1] !== descriptions[i]) {
descriptions[j] = descriptions[i];
j++;
}
}
descriptions.length = j;
}
switch (descriptions.length) {
case 1:
return descriptions[0];
case 2:
return descriptions[0] + " or " + descriptions[1];
default:
return descriptions.slice(0, -1).join(", ")
+ ", or "
+ descriptions[descriptions.length - 1];
}
}
function describeFound(found1) {
return found1 ? "\"" + literalEscape(found1) + "\"" : "end of input";
}
return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
};
return SyntaxError;
}(Error));
function peg$parse(input, options) {
options = options !== undefined ? options : {};
var peg$FAILED = {};
var peg$startRuleFunctions = { start: peg$parsestart };
var peg$startRuleFunction = peg$parsestart;
var peg$c0 = function (parts) {
return parts.join('');
};
var peg$c1 = function (messageText) {
return __assign({ type: TYPE.literal, value: messageText }, insertLocation());
};
var peg$c2 = peg$otherExpectation("argumentElement");
var peg$c3 = "{";
var peg$c4 = peg$literalExpectation("{", false);
var peg$c5 = "}";
var peg$c6 = peg$literalExpectation("}", false);
var peg$c7 = function (value) {
return __assign({ type: TYPE.argument, value: value }, insertLocation());
};
var peg$c8 = peg$otherExpectation("numberSkeletonId");
var peg$c9 = /^['\/{}]/;
var peg$c10 = peg$classExpectation(["'", "/", "{", "}"], false, false);
var peg$c11 = peg$anyExpectation();
var peg$c12 = peg$otherExpectation("numberSkeletonTokenOption");
var peg$c13 = "/";
var peg$c14 = peg$literalExpectation("/", false);
var peg$c15 = function (option) { return option; };
var peg$c16 = peg$otherExpectation("numberSkeletonToken");
var peg$c17 = function (stem, options) {
return { stem: stem, options: options };
};
var peg$c18 = function (tokens) {
return __assign({ type: 0 /* number */, tokens: tokens }, insertLocation());
};
var peg$c19 = "::";
var peg$c20 = peg$literalExpectation("::", false);
var peg$c21 = function (skeleton) { return skeleton; };
var peg$c22 = function (style) { return style.replace(/\s*$/, ''); };
var peg$c23 = ",";
var peg$c24 = peg$literalExpectation(",", false);
var peg$c25 = "number";
var peg$c26 = peg$literalExpectation("number", false);
var peg$c27 = function (value, type, style) {
return __assign({ type: type === 'number' ? TYPE.number : type === 'date' ? TYPE.date : TYPE.time, style: style && style[2], value: value }, insertLocation());
};
var peg$c28 = "'";
var peg$c29 = peg$literalExpectation("'", false);
var peg$c30 = /^[^']/;
var peg$c31 = peg$classExpectation(["'"], true, false);
var peg$c32 = /^[^a-zA-Z'{}]/;
var peg$c33 = peg$classExpectation([["a", "z"], ["A", "Z"], "'", "{", "}"], true, false);
var peg$c34 = /^[a-zA-Z]/;
var peg$c35 = peg$classExpectation([["a", "z"], ["A", "Z"]], false, false);
var peg$c36 = function (pattern) {
return __assign({ type: 1 /* dateTime */, pattern: pattern }, insertLocation());
};
var peg$c37 = "date";
var peg$c38 = peg$literalExpectation("date", false);
var peg$c39 = "time";
var peg$c40 = peg$literalExpectation("time", false);
var peg$c41 = "plural";
var peg$c42 = peg$literalExpectation("plural", false);
var peg$c43 = "selectordinal";
var peg$c44 = peg$literalExpectation("selectordinal", false);
var peg$c45 = "offset:";
var peg$c46 = peg$literalExpectation("offset:", false);
var peg$c47 = function (value, pluralType, offset, options) {
return __assign({ type: TYPE.plural, pluralType: pluralType === 'plural' ? 'cardinal' : 'ordinal', value: value, offset: offset ? offset[2] : 0, options: options.reduce(function (all, _a) {
var id = _a.id, value = _a.value, optionLocation = _a.location;
if (id in all) {
error("Duplicate option \"" + id + "\" in plural element: \"" + text() + "\"", location());
}
all[id] = {
value: value,
location: optionLocation
};
return all;
}, {}) }, insertLocation());
};
var peg$c48 = "select";
var peg$c49 = peg$literalExpectation("select", false);
var peg$c50 = function (value, options) {
return __assign({ type: TYPE.select, value: value, options: options.reduce(function (all, _a) {
var id = _a.id, value = _a.value, optionLocation = _a.location;
if (id in all) {
error("Duplicate option \"" + id + "\" in select element: \"" + text() + "\"", location());
}
all[id] = {
value: value,
location: optionLocation
};
return all;
}, {}) }, insertLocation());
};
var peg$c51 = "=";
var peg$c52 = peg$literalExpectation("=", false);
var peg$c53 = function (id, value) {
return __assign({ id: id,
value: value }, insertLocation());
};
var peg$c54 = function (id, value) {
return __assign({ id: id,
value: value }, insertLocation());
};
var peg$c55 = peg$otherExpectation("whitespace pattern");
var peg$c56 = /^[\t-\r \x85\u200E\u200F\u2028\u2029]/;
var peg$c57 = peg$classExpectation([["\t", "\r"], " ", "\x85", "\u200E", "\u200F", "\u2028", "\u2029"], false, false);
var peg$c58 = peg$otherExpectation("syntax pattern");
var peg$c59 = /^[!-\/:-@[-\^`{-~\xA1-\xA7\xA9\xAB\xAC\xAE\xB0\xB1\xB6\xBB\xBF\xD7\xF7\u2010-\u2027\u2030-\u203E\u2041-\u2053\u2055-\u205E\u2190-\u245F\u2500-\u2775\u2794-\u2BFF\u2E00-\u2E7F\u3001-\u3003\u3008-\u3020\u3030\uFD3E\uFD3F\uFE45\uFE46]/;
var peg$c60 = peg$classExpectation([["!", "/"], [":", "@"], ["[", "^"], "`", ["{", "~"], ["\xA1", "\xA7"], "\xA9", "\xAB", "\xAC", "\xAE", "\xB0", "\xB1", "\xB6", "\xBB", "\xBF", "\xD7", "\xF7", ["\u2010", "\u2027"], ["\u2030", "\u203E"], ["\u2041", "\u2053"], ["\u2055", "\u205E"], ["\u2190", "\u245F"], ["\u2500", "\u2775"], ["\u2794", "\u2BFF"], ["\u2E00", "\u2E7F"], ["\u3001", "\u3003"], ["\u3008", "\u3020"], "\u3030", "\uFD3E", "\uFD3F", "\uFE45", "\uFE46"], false, false);
var peg$c61 = peg$otherExpectation("optional whitespace");
var peg$c62 = peg$otherExpectation("number");
var peg$c63 = "-";
var peg$c64 = peg$literalExpectation("-", false);
var peg$c65 = function (negative, num) {
return num
? negative
? -num
: num
: 0;
};
var peg$c67 = peg$otherExpectation("double apostrophes");
var peg$c68 = "''";
var peg$c69 = peg$literalExpectation("''", false);
var peg$c70 = function () { return "'"; };
var peg$c71 = /^[{}]/;
var peg$c72 = peg$classExpectation(["{", "}"], false, false);
var peg$c73 = function (escapedChar, quotedChars) {
return escapedChar + quotedChars.replace("''", "'");
};
var peg$c74 = /^[^{}]/;
var peg$c75 = peg$classExpectation(["{", "}"], true, false);
var peg$c76 = peg$otherExpectation("argNameOrNumber");
var peg$c77 = peg$otherExpectation("argNumber");
var peg$c78 = "0";
var peg$c79 = peg$literalExpectation("0", false);
var peg$c80 = function () { return 0; };
var peg$c81 = /^[1-9]/;
var peg$c82 = peg$classExpectation([["1", "9"]], false, false);
var peg$c83 = /^[0-9]/;
var peg$c84 = peg$classExpectation([["0", "9"]], false, false);
var peg$c85 = function (digits) {
return parseInt(digits.join(''), 10);
};
var peg$c86 = peg$otherExpectation("argName");
var peg$currPos = 0;
var peg$savedPos = 0;
var peg$posDetailsCache = [{ line: 1, column: 1 }];
var peg$maxFailPos = 0;
var peg$maxFailExpected = [];
var peg$silentFails = 0;
var peg$result;
if (options.startRule !== undefined) {
if (!(options.startRule in peg$startRuleFunctions)) {
throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
}
peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
}
function text() {
return input.substring(peg$savedPos, peg$currPos);
}
function location() {
return peg$computeLocation(peg$savedPos, peg$currPos);
}
function error(message, location1) {
location1 = location1 !== undefined
? location1
: peg$computeLocation(peg$savedPos, peg$currPos);
throw peg$buildSimpleError(message, location1);
}
function peg$literalExpectation(text1, ignoreCase) {
return { type: "literal", text: text1, ignoreCase: ignoreCase };
}
function peg$classExpectation(parts, inverted, ignoreCase) {
return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
}
function peg$anyExpectation() {
return { type: "any" };
}
function peg$endExpectation() {
return { type: "end" };
}
function peg$otherExpectation(description) {
return { type: "other", description: description };
}
function peg$computePosDetails(pos) {
var details = peg$posDetailsCache[pos];
var p;
if (details) {
return details;
}
else {
p = pos - 1;
while (!peg$posDetailsCache[p]) {
p--;
}
details = peg$posDetailsCache[p];
details = {
line: details.line,
column: details.column
};
while (p < pos) {
if (input.charCodeAt(p) === 10) {
details.line++;
details.column = 1;
}
else {
details.column++;
}
p++;
}
peg$posDetailsCache[pos] = details;
return details;
}
}
function peg$computeLocation(startPos, endPos) {
var startPosDetails = peg$computePosDetails(startPos);
var endPosDetails = peg$computePosDetails(endPos);
return {
start: {
offset: startPos,
line: startPosDetails.line,
column: startPosDetails.column
},
end: {
offset: endPos,
line: endPosDetails.line,
column: endPosDetails.column
}
};
}
function peg$fail(expected1) {
if (peg$currPos < peg$maxFailPos) {
return;
}
if (peg$currPos > peg$maxFailPos) {
peg$maxFailPos = peg$currPos;
peg$maxFailExpected = [];
}
peg$maxFailExpected.push(expected1);
}
function peg$buildSimpleError(message, location1) {
return new SyntaxError(message, [], "", location1);
}
function peg$buildStructuredError(expected1, found, location1) {
return new SyntaxError(SyntaxError.buildMessage(expected1, found), expected1, found, location1);
}
function peg$parsestart() {
var s0;
s0 = peg$parsemessage();
return s0;
}
function peg$parsemessage() {
var s0, s1;
s0 = [];
s1 = peg$parsemessageElement();
while (s1 !== peg$FAILED) {
s0.push(s1);
s1 = peg$parsemessageElement();
}
return s0;
}
function peg$parsemessageElement() {
var s0;
s0 = peg$parseliteralElement();
if (s0 === peg$FAILED) {
s0 = peg$parseargumentElement();
if (s0 === peg$FAILED) {
s0 = peg$parsesimpleFormatElement();
if (s0 === peg$FAILED) {
s0 = peg$parsepluralElement();
if (s0 === peg$FAILED) {
s0 = peg$parseselectElement();
}
}
}
}
return s0;
}
function peg$parsemessageText() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
s2 = peg$parsedoubleApostrophes();
if (s2 === peg$FAILED) {
s2 = peg$parsequotedString();
if (s2 === peg$FAILED) {
s2 = peg$parseunquotedString();
}
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parsedoubleApostrophes();
if (s2 === peg$FAILED) {
s2 = peg$parsequotedString();
if (s2 === peg$FAILED) {
s2 = peg$parseunquotedString();
}
}
}
}
else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c0(s1);
}
s0 = s1;
return s0;
}
function peg$parseliteralElement() {
var s0, s1;
s0 = peg$currPos;
s1 = peg$parsemessageText();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c1(s1);
}
s0 = s1;
return s0;
}
function peg$parseargumentElement() {
var s0, s1, s2, s3, s4, s5;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 123) {
s1 = peg$c3;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c4);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = peg$parseargNameOrNumber();
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s5 = peg$c5;
peg$currPos++;
}
else {
s5 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c6);
}
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c7(s3);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c2);
}
}
return s0;
}
function peg$parsenumberSkeletonId() {
var s0, s1, s2, s3, s4;
peg$silentFails++;
s0 = peg$currPos;
s1 = [];
s2 = peg$currPos;
s3 = peg$currPos;
peg$silentFails++;
s4 = peg$parsepatternWhiteSpace();
if (s4 === peg$FAILED) {
if (peg$c9.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c10);
}
}
}
peg$silentFails--;
if (s4 === peg$FAILED) {
s3 = undefined;
}
else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 !== peg$FAILED) {
if (input.length > peg$currPos) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c11);
}
}
if (s4 !== peg$FAILED) {
s3 = [s3, s4];
s2 = s3;
}
else {
peg$currPos = s2;
s2 = peg$FAILED;
}
}
else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$currPos;
s3 = peg$currPos;
peg$silentFails++;
s4 = peg$parsepatternWhiteSpace();
if (s4 === peg$FAILED) {
if (peg$c9.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c10);
}
}
}
peg$silentFails--;
if (s4 === peg$FAILED) {
s3 = undefined;
}
else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 !== peg$FAILED) {
if (input.length > peg$currPos) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c11);
}
}
if (s4 !== peg$FAILED) {
s3 = [s3, s4];
s2 = s3;
}
else {
peg$currPos = s2;
s2 = peg$FAILED;
}
}
else {
peg$currPos = s2;
s2 = peg$FAILED;
}
}
}
else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s0 = input.substring(s0, peg$currPos);
}
else {
s0 = s1;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c8);
}
}
return s0;
}
function peg$parsenumberSkeletonTokenOption() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 47) {
s1 = peg$c13;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c14);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parsenumberSkeletonId();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c15(s2);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c12);
}
}
return s0;
}
function peg$parsenumberSkeletonToken() {
var s0, s1, s2, s3, s4;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$parse_();
if (s1 !== peg$FAILED) {
s2 = peg$parsenumberSkeletonId();
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$parsenumberSkeletonTokenOption();
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parsenumberSkeletonTokenOption();
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c17(s2, s3);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c16);
}
}
return s0;
}
function peg$parsenumberSkeleton() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
s2 = peg$parsenumberSkeletonToken();
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parsenumberSkeletonToken();
}
}
else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c18(s1);
}
s0 = s1;
return s0;
}
function peg$parsenumberArgStyle() {
var s0, s1, s2;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c19) {
s1 = peg$c19;
peg$currPos += 2;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c20);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parsenumberSkeleton();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c21(s2);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parsemessageText();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c22(s1);
}
s0 = s1;
}
return s0;
}
function peg$parsenumberFormatElement() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 123) {
s1 = peg$c3;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c4);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = peg$parseargNameOrNumber();
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s5 = peg$c23;
peg$currPos++;
}
else {
s5 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c24);
}
}
if (s5 !== peg$FAILED) {
s6 = peg$parse_();
if (s6 !== peg$FAILED) {
if (input.substr(peg$currPos, 6) === peg$c25) {
s7 = peg$c25;
peg$currPos += 6;
}
else {
s7 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c26);
}
}
if (s7 !== peg$FAILED) {
s8 = peg$parse_();
if (s8 !== peg$FAILED) {
s9 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 44) {
s10 = peg$c23;
peg$currPos++;
}
else {
s10 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c24);
}
}
if (s10 !== peg$FAILED) {
s11 = peg$parse_();
if (s11 !== peg$FAILED) {
s12 = peg$parsenumberArgStyle();
if (s12 !== peg$FAILED) {
s10 = [s10, s11, s12];
s9 = s10;
}
else {
peg$currPos = s9;
s9 = peg$FAILED;
}
}
else {
peg$currPos = s9;
s9 = peg$FAILED;
}
}
else {
peg$currPos = s9;
s9 = peg$FAILED;
}
if (s9 === peg$FAILED) {
s9 = null;
}
if (s9 !== peg$FAILED) {
s10 = peg$parse_();
if (s10 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s11 = peg$c5;
peg$currPos++;
}
else {
s11 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c6);
}
}
if (s11 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c27(s3, s7, s9);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsedateTimeSkeletonLiteral() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 39) {
s1 = peg$c28;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c29);
}
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parsedoubleApostrophes();
if (s3 === peg$FAILED) {
if (peg$c30.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c31);
}
}
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parsedoubleApostrophes();
if (s3 === peg$FAILED) {
if (peg$c30.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c31);
}
}
}
}
}
else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 39) {
s3 = peg$c28;
peg$currPos++;
}
else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c29);
}
}
if (s3 !== peg$FAILED) {
s1 = [s1, s2, s3];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = [];
s1 = peg$parsedoubleApostrophes();
if (s1 === peg$FAILED) {
if (peg$c32.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c33);
}
}
}
if (s1 !== peg$FAILED) {
while (s1 !== peg$FAILED) {
s0.push(s1);
s1 = peg$parsedoubleApostrophes();
if (s1 === peg$FAILED) {
if (peg$c32.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c33);
}
}
}
}
}
else {
s0 = peg$FAILED;
}
}
return s0;
}
function peg$parsedateTimeSkeletonPattern() {
var s0, s1;
s0 = [];
if (peg$c34.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c35);
}
}
if (s1 !== peg$FAILED) {
while (s1 !== peg$FAILED) {
s0.push(s1);
if (peg$c34.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c35);
}
}
}
}
else {
s0 = peg$FAILED;
}
return s0;
}
function peg$parsedateTimeSkeleton() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$currPos;
s2 = [];
s3 = peg$parsedateTimeSkeletonLiteral();
if (s3 === peg$FAILED) {
s3 = peg$parsedateTimeSkeletonPattern();
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parsedateTimeSkeletonLiteral();
if (s3 === peg$FAILED) {
s3 = peg$parsedateTimeSkeletonPattern();
}
}
}
else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s1 = input.substring(s1, peg$currPos);
}
else {
s1 = s2;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c36(s1);
}
s0 = s1;
return s0;
}
function peg$parsedateOrTimeArgStyle() {
var s0, s1, s2;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c19) {
s1 = peg$c19;
peg$currPos += 2;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c20);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parsedateTimeSkeleton();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c21(s2);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parsemessageText();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c22(s1);
}
s0 = s1;
}
return s0;
}
function peg$parsedateOrTimeFormatElement() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 123) {
s1 = peg$c3;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c4);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = peg$parseargNameOrNumber();
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s5 = peg$c23;
peg$currPos++;
}
else {
s5 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c24);
}
}
if (s5 !== peg$FAILED) {
s6 = peg$parse_();
if (s6 !== peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c37) {
s7 = peg$c37;
peg$currPos += 4;
}
else {
s7 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c38);
}
}
if (s7 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c39) {
s7 = peg$c39;
peg$currPos += 4;
}
else {
s7 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c40);
}
}
}
if (s7 !== peg$FAILED) {
s8 = peg$parse_();
if (s8 !== peg$FAILED) {
s9 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 44) {
s10 = peg$c23;
peg$currPos++;
}
else {
s10 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c24);
}
}
if (s10 !== peg$FAILED) {
s11 = peg$parse_();
if (s11 !== peg$FAILED) {
s12 = peg$parsedateOrTimeArgStyle();
if (s12 !== peg$FAILED) {
s10 = [s10, s11, s12];
s9 = s10;
}
else {
peg$currPos = s9;
s9 = peg$FAILED;
}
}
else {
peg$currPos = s9;
s9 = peg$FAILED;
}
}
else {
peg$currPos = s9;
s9 = peg$FAILED;
}
if (s9 === peg$FAILED) {
s9 = null;
}
if (s9 !== peg$FAILED) {
s10 = peg$parse_();
if (s10 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s11 = peg$c5;
peg$currPos++;
}
else {
s11 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c6);
}
}
if (s11 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c27(s3, s7, s9);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsesimpleFormatElement() {
var s0;
s0 = peg$parsenumberFormatElement();
if (s0 === peg$FAILED) {
s0 = peg$parsedateOrTimeFormatElement();
}
return s0;
}
function peg$parsepluralElement() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 123) {
s1 = peg$c3;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c4);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = peg$parseargNameOrNumber();
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s5 = peg$c23;
peg$currPos++;
}
else {
s5 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c24);
}
}
if (s5 !== peg$FAILED) {
s6 = peg$parse_();
if (s6 !== peg$FAILED) {
if (input.substr(peg$currPos, 6) === peg$c41) {
s7 = peg$c41;
peg$currPos += 6;
}
else {
s7 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c42);
}
}
if (s7 === peg$FAILED) {
if (input.substr(peg$currPos, 13) === peg$c43) {
s7 = peg$c43;
peg$currPos += 13;
}
else {
s7 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c44);
}
}
}
if (s7 !== peg$FAILED) {
s8 = peg$parse_();
if (s8 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s9 = peg$c23;
peg$currPos++;
}
else {
s9 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c24);
}
}
if (s9 !== peg$FAILED) {
s10 = peg$parse_();
if (s10 !== peg$FAILED) {
s11 = peg$currPos;
if (input.substr(peg$currPos, 7) === peg$c45) {
s12 = peg$c45;
peg$currPos += 7;
}
else {
s12 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c46);
}
}
if (s12 !== peg$FAILED) {
s13 = peg$parse_();
if (s13 !== peg$FAILED) {
s14 = peg$parsenumber();
if (s14 !== peg$FAILED) {
s12 = [s12, s13, s14];
s11 = s12;
}
else {
peg$currPos = s11;
s11 = peg$FAILED;
}
}
else {
peg$currPos = s11;
s11 = peg$FAILED;
}
}
else {
peg$currPos = s11;
s11 = peg$FAILED;
}
if (s11 === peg$FAILED) {
s11 = null;
}
if (s11 !== peg$FAILED) {
s12 = peg$parse_();
if (s12 !== peg$FAILED) {
s13 = [];
s14 = peg$parsepluralOption();
if (s14 !== peg$FAILED) {
while (s14 !== peg$FAILED) {
s13.push(s14);
s14 = peg$parsepluralOption();
}
}
else {
s13 = peg$FAILED;
}
if (s13 !== peg$FAILED) {
s14 = peg$parse_();
if (s14 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s15 = peg$c5;
peg$currPos++;
}
else {
s15 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c6);
}
}
if (s15 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c47(s3, s7, s11, s13);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseselectElement() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 123) {
s1 = peg$c3;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c4);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = peg$parseargNameOrNumber();
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s5 = peg$c23;
peg$currPos++;
}
else {
s5 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c24);
}
}
if (s5 !== peg$FAILED) {
s6 = peg$parse_();
if (s6 !== peg$FAILED) {
if (input.substr(peg$currPos, 6) === peg$c48) {
s7 = peg$c48;
peg$currPos += 6;
}
else {
s7 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c49);
}
}
if (s7 !== peg$FAILED) {
s8 = peg$parse_();
if (s8 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s9 = peg$c23;
peg$currPos++;
}
else {
s9 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c24);
}
}
if (s9 !== peg$FAILED) {
s10 = peg$parse_();
if (s10 !== peg$FAILED) {
s11 = [];
s12 = peg$parseselectOption();
if (s12 !== peg$FAILED) {
while (s12 !== peg$FAILED) {
s11.push(s12);
s12 = peg$parseselectOption();
}
}
else {
s11 = peg$FAILED;
}
if (s11 !== peg$FAILED) {
s12 = peg$parse_();
if (s12 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s13 = peg$c5;
peg$currPos++;
}
else {
s13 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c6);
}
}
if (s13 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c50(s3, s11);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsepluralRuleSelectValue() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 61) {
s2 = peg$c51;
peg$currPos++;
}
else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c52);
}
}
if (s2 !== peg$FAILED) {
s3 = peg$parsenumber();
if (s3 !== peg$FAILED) {
s2 = [s2, s3];
s1 = s2;
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s0 = input.substring(s0, peg$currPos);
}
else {
s0 = s1;
}
if (s0 === peg$FAILED) {
s0 = peg$parseargName();
}
return s0;
}
function peg$parseselectOption() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
s1 = peg$parse_();
if (s1 !== peg$FAILED) {
s2 = peg$parseargName();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 123) {
s4 = peg$c3;
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c4);
}
}
if (s4 !== peg$FAILED) {
s5 = peg$parsemessage();
if (s5 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s6 = peg$c5;
peg$currPos++;
}
else {
s6 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c6);
}
}
if (s6 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c53(s2, s5);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsepluralOption() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
s1 = peg$parse_();
if (s1 !== peg$FAILED) {
s2 = peg$parsepluralRuleSelectValue();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 123) {
s4 = peg$c3;
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c4);
}
}
if (s4 !== peg$FAILED) {
s5 = peg$parsemessage();
if (s5 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s6 = peg$c5;
peg$currPos++;
}
else {
s6 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c6);
}
}
if (s6 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c54(s2, s5);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsepatternWhiteSpace() {
var s0;
peg$silentFails++;
if (peg$c56.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c57);
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
if (peg$silentFails === 0) {
peg$fail(peg$c55);
}
}
return s0;
}
function peg$parsepatternSyntax() {
var s0;
peg$silentFails++;
if (peg$c59.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c60);
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
if (peg$silentFails === 0) {
peg$fail(peg$c58);
}
}
return s0;
}
function peg$parse_() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
s1 = [];
s2 = peg$parsepatternWhiteSpace();
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parsepatternWhiteSpace();
}
if (s1 !== peg$FAILED) {
s0 = input.substring(s0, peg$currPos);
}
else {
s0 = s1;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c61);
}
}
return s0;
}
function peg$parsenumber() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 45) {
s1 = peg$c63;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c64);
}
}
if (s1 === peg$FAILED) {
s1 = null;
}
if (s1 !== peg$FAILED) {
s2 = peg$parseargNumber();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c65(s1, s2);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c62);
}
}
return s0;
}
function peg$parsedoubleApostrophes() {
var s0, s1;
peg$silentFails++;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c68) {
s1 = peg$c68;
peg$currPos += 2;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c69);
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c70();
}
s0 = s1;
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c67);
}
}
return s0;
}
function peg$parsequotedString() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 39) {
s1 = peg$c28;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c29);
}
}
if (s1 !== peg$FAILED) {
if (peg$c71.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c72);
}
}
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
s4 = [];
if (input.substr(peg$currPos, 2) === peg$c68) {
s5 = peg$c68;
peg$currPos += 2;
}
else {
s5 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c69);
}
}
if (s5 === peg$FAILED) {
if (peg$c30.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s5 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c31);
}
}
}
while (s5 !== peg$FAILED) {
s4.push(s5);
if (input.substr(peg$currPos, 2) === peg$c68) {
s5 = peg$c68;
peg$currPos += 2;
}
else {
s5 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c69);
}
}
if (s5 === peg$FAILED) {
if (peg$c30.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s5 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c31);
}
}
}
}
if (s4 !== peg$FAILED) {
s3 = input.substring(s3, peg$currPos);
}
else {
s3 = s4;
}
if (s3 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 39) {
s4 = peg$c28;
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c29);
}
}
if (s4 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c73(s2, s3);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseunquotedString() {
var s0, s1;
s0 = peg$currPos;
if (peg$c74.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c75);
}
}
if (s1 !== peg$FAILED) {
s0 = input.substring(s0, peg$currPos);
}
else {
s0 = s1;
}
return s0;
}
function peg$parseargNameOrNumber() {
var s0, s1;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$parseargNumber();
if (s1 === peg$FAILED) {
s1 = peg$parseargName();
}
if (s1 !== peg$FAILED) {
s0 = input.substring(s0, peg$currPos);
}
else {
s0 = s1;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c76);
}
}
return s0;
}
function peg$parseargNumber() {
var s0, s1, s2, s3, s4;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 48) {
s1 = peg$c78;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c79);
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c80();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$currPos;
if (peg$c81.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c82);
}
}
if (s2 !== peg$FAILED) {
s3 = [];
if (peg$c83.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c84);
}
}
while (s4 !== peg$FAILED) {
s3.push(s4);
if (peg$c83.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c84);
}
}
}
if (s3 !== peg$FAILED) {
s2 = [s2, s3];
s1 = s2;
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c85(s1);
}
s0 = s1;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c77);
}
}
return s0;
}
function peg$parseargName() {
var s0, s1, s2, s3, s4;
peg$silentFails++;
s0 = peg$currPos;
s1 = [];
s2 = peg$currPos;
s3 = peg$currPos;
peg$silentFails++;
s4 = peg$parsepatternWhiteSpace();
if (s4 === peg$FAILED) {
s4 = peg$parsepatternSyntax();
}
peg$silentFails--;
if (s4 === peg$FAILED) {
s3 = undefined;
}
else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 !== peg$FAILED) {
if (input.length > peg$currPos) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c11);
}
}
if (s4 !== peg$FAILED) {
s3 = [s3, s4];
s2 = s3;
}
else {
peg$currPos = s2;
s2 = peg$FAILED;
}
}
else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$currPos;
s3 = peg$currPos;
peg$silentFails++;
s4 = peg$parsepatternWhiteSpace();
if (s4 === peg$FAILED) {
s4 = peg$parsepatternSyntax();
}
peg$silentFails--;
if (s4 === peg$FAILED) {
s3 = undefined;
}
else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 !== peg$FAILED) {
if (input.length > peg$currPos) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c11);
}
}
if (s4 !== peg$FAILED) {
s3 = [s3, s4];
s2 = s3;
}
else {
peg$currPos = s2;
s2 = peg$FAILED;
}
}
else {
peg$currPos = s2;
s2 = peg$FAILED;
}
}
}
else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s0 = input.substring(s0, peg$currPos);
}
else {
s0 = s1;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c86);
}
}
return s0;
}
function insertLocation() {
return options && options.captureLocation ? {
location: location()
} : {};
}
peg$result = peg$startRuleFunction();
if (peg$result !== peg$FAILED && peg$currPos === input.length) {
return peg$result;
}
else {
if (peg$result !== peg$FAILED && peg$currPos < input.length) {
peg$fail(peg$endExpectation());
}
throw peg$buildStructuredError(peg$maxFailExpected, peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, peg$maxFailPos < input.length
? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
: peg$computeLocation(peg$maxFailPos, peg$maxFailPos));
}
}
var parse = peg$parse;
var __spreadArrays = (undefined && undefined.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var PLURAL_HASHTAG_REGEX = /(^|[^\\])#/g;
/**
* Whether to convert `#` in plural rule options
* to `{var, number}`
* @param el AST Element
* @param pluralStack current plural stack
*/
function normalizeHashtagInPlural(els) {
els.forEach(function (el) {
// If we're encountering a plural el
if (!isPluralElement(el) && !isSelectElement(el)) {
return;
}
// Go down the options and search for # in any literal element
Object.keys(el.options).forEach(function (id) {
var _a;
var opt = el.options[id];
// If we got a match, we have to split this
// and inject a NumberElement in the middle
var matchingLiteralElIndex = -1;
var literalEl = undefined;
for (var i = 0; i < opt.value.length; i++) {
var el_1 = opt.value[i];
if (isLiteralElement(el_1) && PLURAL_HASHTAG_REGEX.test(el_1.value)) {
matchingLiteralElIndex = i;
literalEl = el_1;
break;
}
}
if (literalEl) {
var newValue = literalEl.value.replace(PLURAL_HASHTAG_REGEX, "$1{" + el.value + ", number}");
var newEls = parse(newValue);
(_a = opt.value).splice.apply(_a, __spreadArrays([matchingLiteralElIndex, 1], newEls));
}
normalizeHashtagInPlural(opt.value);
});
});
}
function parse$1(input, opts) {
var els = parse(input, opts);
if (!opts || opts.normalizeHashtagInPlural !== false) {
normalizeHashtagInPlural(els);
}
return els;
}
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
var __spreadArrays$1 = (undefined && undefined.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
// -- Utilities ----------------------------------------------------------------
function getCacheId(inputs) {
return JSON.stringify(inputs.map(function (input) {
return input && typeof input === 'object' ? orderedProps(input) : input;
}));
}
function orderedProps(obj) {
return Object.keys(obj)
.sort()
.map(function (k) {
var _a;
return (_a = {}, _a[k] = obj[k], _a);
});
}
var memoizeFormatConstructor = function (FormatConstructor, cache) {
if (cache === void 0) { cache = {}; }
return function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var cacheId = getCacheId(args);
var format = cacheId && cache[cacheId];
if (!format) {
format = new ((_a = FormatConstructor).bind.apply(_a, __spreadArrays$1([void 0], args)))();
if (cacheId) {
cache[cacheId] = format;
}
}
return format;
};
};
var __extends$1 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __spreadArrays$2 = (undefined && undefined.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var ESCAPE_HASH_REGEX = /\\#/g;
var PLURAL_HASH = /(^|[^\\])#/g;
var FormatError = /** @class */ (function (_super) {
__extends$1(FormatError, _super);
function FormatError(msg, variableId) {
var _this = _super.call(this, msg) || this;
_this.variableId = variableId;
return _this;
}
return FormatError;
}(Error));
function mergeLiteral(parts) {
if (parts.length < 2) {
return parts;
}
return parts.reduce(function (all, part) {
var lastPart = all[all.length - 1];
if (!lastPart ||
lastPart.type !== 0 /* literal */ ||
part.type !== 0 /* literal */) {
all.push(part);
}
else {
lastPart.value += part.value;
}
return all;
}, []);
}
// TODO(skeleton): add skeleton support
function formatToParts(els, locales, formatters, formats, values, currentPluralValue,
// For debugging
originalMessage) {
// Hot path for straight simple msg translations
if (els.length === 1 && isLiteralElement(els[0])) {
var value = els[0].value;
if (typeof currentPluralValue === 'number') {
value = value.replace(PLURAL_HASH, '$1' + formatters.getNumberFormat(locales).format(currentPluralValue));
}
return [
{
type: 0 /* literal */,
value: value.replace(ESCAPE_HASH_REGEX, '#'),
},
];
}
var result = [];
for (var _i = 0, els_1 = els; _i < els_1.length; _i++) {
var el = els_1[_i];
// Exit early for string parts.
if (isLiteralElement(el)) {
var value_1 = el.value;
if (typeof currentPluralValue === 'number') {
value_1 = value_1.replace(PLURAL_HASH, '$1' + formatters.getNumberFormat(locales).format(currentPluralValue));
}
result.push({
type: 0 /* literal */,
value: value_1.replace(ESCAPE_HASH_REGEX, '#'),
});
continue;
}
var varName = el.value;
// Enforce that all required values are provided by the caller.
if (!(values && varName in values)) {
throw new FormatError("The intl string context variable \"" + varName + "\" was not provided to the string \"" + originalMessage + "\"");
}
var value = values[varName];
if (isArgumentElement(el)) {
if (!value || typeof value === 'string' || typeof value === 'number') {
value =
typeof value === 'string' || typeof value === 'number'
? String(value)
: '';
}
result.push({
type: 1 /* argument */,
value: value,
});
continue;
}
// Recursively format plural and select parts' option — which can be a
// nested pattern structure. The choosing of the option to use is
// abstracted-by and delegated-to the part helper object.
if (isDateElement(el)) {
var style = typeof el.style === 'string' ? formats.date[el.style] : undefined;
result.push({
type: 0 /* literal */,
value: formatters
.getDateTimeFormat(locales, style)
.format(value),
});
continue;
}
if (isTimeElement(el)) {
var style = typeof el.style === 'string' ? formats.time[el.style] : undefined;
result.push({
type: 0 /* literal */,
value: formatters
.getDateTimeFormat(locales, style)
.format(value),
});
continue;
}
if (isNumberElement(el)) {
var style = typeof el.style === 'string' ? formats.number[el.style] : undefined;
result.push({
type: 0 /* literal */,
value: formatters
.getNumberFormat(locales, style)
.format(value),
});
continue;
}
if (isSelectElement(el)) {
var opt = el.options[value] || el.options.other;
if (!opt) {
throw new RangeError("Invalid values for \"" + el.value + "\": \"" + value + "\". Options are \"" + Object.keys(el.options).join('", "') + "\"");
}
result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values));
continue;
}
if (isPluralElement(el)) {
var opt = el.options["=" + value];
if (!opt) {
if (!Intl.PluralRules) {
throw new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n");
}
var rule = formatters
.getPluralRules(locales, { type: el.pluralType })
.select(value - (el.offset || 0));
opt = el.options[rule] || el.options.other;
}
if (!opt) {
throw new RangeError("Invalid values for \"" + el.value + "\": \"" + value + "\". Options are \"" + Object.keys(el.options).join('", "') + "\"");
}
result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values, value - (el.offset || 0)));
continue;
}
}
return mergeLiteral(result);
}
function formatToString(els, locales, formatters, formats, values,
// For debugging
originalMessage) {
var parts = formatToParts(els, locales, formatters, formats, values, undefined, originalMessage);
// Hot path for straight simple msg translations
if (parts.length === 1) {
return parts[0].value;
}
return parts.reduce(function (all, part) { return (all += part.value); }, '');
}
// Singleton
var domParser;
var TOKEN_DELIMITER = '@@';
var TOKEN_REGEX = /@@(\d+_\d+)@@/g;
var counter = 0;
function generateId() {
return Date.now() + "_" + ++counter;
}
function restoreRichPlaceholderMessage(text, objectParts) {
return text
.split(TOKEN_REGEX)
.filter(Boolean)
.map(function (c) { return (objectParts[c] != null ? objectParts[c] : c); })
.reduce(function (all, c) {
if (!all.length) {
all.push(c);
}
else if (typeof c === 'string' &&
typeof all[all.length - 1] === 'string') {
all[all.length - 1] += c;
}
else {
all.push(c);
}
return all;
}, []);
}
/**
* Not exhaustive, just for sanity check
*/
var SIMPLE_XML_REGEX = /(<([0-9a-zA-Z-_]*?)>(.*?)<\/([0-9a-zA-Z-_]*?)>)|(<[0-9a-zA-Z-_]*?\/>)/;
var TEMPLATE_ID = Date.now() + '@@';
var VOID_ELEMENTS = [
'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'link',
'meta',
'param',
'source',
'track',
'wbr',
];
function formatHTMLElement(el, objectParts, values) {
var tagName = el.tagName, outerHTML = el.outerHTML, textContent = el.textContent, childNodes = el.childNodes;
// Regular text
if (!tagName) {
return restoreRichPlaceholderMessage(textContent || '', objectParts);
}
tagName = tagName.toLowerCase();
var isVoidElement = ~VOID_ELEMENTS.indexOf(tagName);
var formatFnOrValue = values[tagName];
if (formatFnOrValue && isVoidElement) {
throw new FormatError(tagName + " is a self-closing tag and can not be used, please use another tag name.");
}
if (!childNodes.length) {
return [outerHTML];
}
var chunks = Array.prototype.slice.call(childNodes).reduce(function (all, child) {
return all.concat(formatHTMLElement(child, objectParts, values));
}, []);
// Legacy HTML
if (!formatFnOrValue) {
return __spreadArrays$2(["<" + tagName + ">"], chunks, ["" + tagName + ">"]);
}
// HTML Tag replacement
if (typeof formatFnOrValue === 'function') {
return [formatFnOrValue.apply(void 0, chunks)];
}
return [formatFnOrValue];
}
function formatHTMLMessage(els, locales, formatters, formats, values,
// For debugging
originalMessage) {
var parts = formatToParts(els, locales, formatters, formats, values, undefined, originalMessage);
var objectParts = {};
var formattedMessage = parts.reduce(function (all, part) {
if (part.type === 0 /* literal */) {
return (all += part.value);
}
var id = generateId();
objectParts[id] = part.value;
return (all += "" + TOKEN_DELIMITER + id + TOKEN_DELIMITER);
}, '');
// Not designed to filter out aggressively
if (!SIMPLE_XML_REGEX.test(formattedMessage)) {
return restoreRichPlaceholderMessage(formattedMessage, objectParts);
}
if (!values) {
throw new FormatError('Message has placeholders but no values was given');
}
if (typeof DOMParser === 'undefined') {
throw new FormatError('Cannot format XML message without DOMParser');
}
if (!domParser) {
domParser = new DOMParser();
}
var content = domParser
.parseFromString("" + formattedMessage + "", 'text/html')
.getElementById(TEMPLATE_ID);
if (!content) {
throw new FormatError("Malformed HTML message " + formattedMessage);
}
var tagsToFormat = Object.keys(values).filter(function (varName) { return !!content.getElementsByTagName(varName).length; });
// No tags to format
if (!tagsToFormat.length) {
return restoreRichPlaceholderMessage(formattedMessage, objectParts);
}
var caseSensitiveTags = tagsToFormat.filter(function (tagName) { return tagName !== tagName.toLowerCase(); });
if (caseSensitiveTags.length) {
throw new FormatError("HTML tag must be lowercased but the following tags are not: " + caseSensitiveTags.join(', '));
}
// We're doing this since top node is `` which does not have a formatter
return Array.prototype.slice
.call(content.childNodes)
.reduce(function (all, child) { return all.concat(formatHTMLElement(child, objectParts, values)); }, []);
}
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
var __assign$1 = (undefined && undefined.__assign) || function () {
__assign$1 = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign$1.apply(this, arguments);
};
var __spreadArrays$3 = (undefined && undefined.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
// -- MessageFormat --------------------------------------------------------
function resolveLocale(locales) {
try {
return __spreadArrays$3(Intl.NumberFormat.supportedLocalesOf(locales, {
// IE11 localeMatcher `lookup` seems to convert `en` -> `en-US`
// but not other browsers,
localeMatcher: 'best fit',
}), Intl.DateTimeFormat.supportedLocalesOf(locales, {
// IE11 localeMatcher `lookup` seems to convert `en` -> `en-US`
// but not other browsers,
localeMatcher: 'best fit',
}), Intl.PluralRules.supportedLocalesOf(locales, {
// IE11 localeMatcher `lookup` seems to convert `en` -> `en-US`
// but not other browsers,
localeMatcher: 'best fit',
}))[0];
}
catch (e) {
return IntlMessageFormat.defaultLocale;
}
}
function mergeConfig(c1, c2) {
if (!c2) {
return c1;
}
return __assign$1(__assign$1(__assign$1({}, (c1 || {})), (c2 || {})), Object.keys(c1).reduce(function (all, k) {
all[k] = __assign$1(__assign$1({}, c1[k]), (c2[k] || {}));
return all;
}, {}));
}
function mergeConfigs(defaultConfig, configs) {
if (!configs) {
return defaultConfig;
}
return Object.keys(defaultConfig).reduce(function (all, k) {
all[k] = mergeConfig(defaultConfig[k], configs[k]);
return all;
}, __assign$1({}, defaultConfig));
}
function createDefaultFormatters(cache) {
if (cache === void 0) { cache = {
number: {},
dateTime: {},
pluralRules: {},
}; }
return {
getNumberFormat: memoizeFormatConstructor(Intl.NumberFormat, cache.number),
getDateTimeFormat: memoizeFormatConstructor(Intl.DateTimeFormat, cache.dateTime),
getPluralRules: memoizeFormatConstructor(Intl.PluralRules, cache.pluralRules),
};
}
var IntlMessageFormat = /** @class */ (function () {
function IntlMessageFormat(message, locales, overrideFormats, opts) {
var _this = this;
if (locales === void 0) { locales = IntlMessageFormat.defaultLocale; }
this.formatterCache = {
number: {},
dateTime: {},
pluralRules: {},
};
this.format = function (values) {
return formatToString(_this.ast, _this.locale, _this.formatters, _this.formats, values, _this.message);
};
this.formatToParts = function (values) {
return formatToParts(_this.ast, _this.locale, _this.formatters, _this.formats, values, undefined, _this.message);
};
this.formatHTMLMessage = function (values) {
return formatHTMLMessage(_this.ast, _this.locale, _this.formatters, _this.formats, values, _this.message);
};
this.resolvedOptions = function () { return ({ locale: _this.locale }); };
this.getAst = function () { return _this.ast; };
if (typeof message === 'string') {
this.message = message;
if (!IntlMessageFormat.__parse) {
throw new TypeError('IntlMessageFormat.__parse must be set to process `message` of type `string`');
}
// Parse string messages into an AST.
this.ast = IntlMessageFormat.__parse(message, {
normalizeHashtagInPlural: false,
});
}
else {
this.ast = message;
}
if (!Array.isArray(this.ast)) {
throw new TypeError('A message must be provided as a String or AST.');
}
// Creates a new object with the specified `formats` merged with the default
// formats.
this.formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
this.locale = resolveLocale(locales || []);
this.formatters =
(opts && opts.formatters) || createDefaultFormatters(this.formatterCache);
}
IntlMessageFormat.defaultLocale = 'en';
IntlMessageFormat.__parse = parse$1;
// Default format options used as the prototype of the `formats` provided to the
// constructor. These are used when constructing the internal Intl.NumberFormat
// and Intl.DateTimeFormat instances.
IntlMessageFormat.formats = {
number: {
currency: {
style: 'currency',
},
percent: {
style: 'percent',
},
},
date: {
short: {
month: 'numeric',
day: 'numeric',
year: '2-digit',
},
medium: {
month: 'short',
day: 'numeric',
year: 'numeric',
},
long: {
month: 'long',
day: 'numeric',
year: 'numeric',
},
full: {
weekday: 'long',
month: 'long',
day: 'numeric',
year: 'numeric',
},
},
time: {
short: {
hour: 'numeric',
minute: 'numeric',
},
medium: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
},
long: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short',
},
full: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short',
},
},
};
return IntlMessageFormat;
}());
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
exports.IntlMessageFormat = IntlMessageFormat;
exports.createDefaultFormatters = createDefaultFormatters;
exports.default = IntlMessageFormat;
exports.formatHTMLMessage = formatHTMLMessage;
exports.formatToParts = formatToParts;
exports.formatToString = formatToString;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=intl-messageformat.js.map