react-intl
Version:
Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.
1,217 lines (1,202 loc) • 229 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactIntl = {}, global.React));
}(this, (function (exports, React) { 'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(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);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
/** @deprecated */
function __spreadArrays() {
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;
}
/**
* Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue
* @param x number
*/
function invariant(condition, message, Err) {
if (Err === void 0) { Err = Error; }
if (!condition) {
throw new Err(message);
}
}
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";
/**
* Only possible within plural argument.
* This is the `#` symbol that will be substituted with the count.
*/
TYPE[TYPE["pound"] = 7] = "pound";
/**
* XML-like tag
*/
TYPE[TYPE["tag"] = 8] = "tag";
})(TYPE || (TYPE = {}));
var SKELETON_TYPE;
(function (SKELETON_TYPE) {
SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number";
SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime";
})(SKELETON_TYPE || (SKELETON_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;
}
function isPoundElement(el) {
return el.type === TYPE.pound;
}
function isTagElement(el) {
return el.type === TYPE.tag;
}
function isNumberSkeleton(el) {
return !!(el && typeof el === 'object' && el.type === 0 /* number */);
}
function isDateTimeSkeleton(el) {
return !!(el && typeof el === 'object' && el.type === 1 /* dateTime */);
}
/**
* https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
* Credit: https://github.com/caridy/intl-datetimeformat-pattern/blob/master/index.js
* with some tweaks
*/
var DATE_TIME_REGEX = /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;
/**
* Parse Date time skeleton into Intl.DateTimeFormatOptions
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
* @public
* @param skeleton skeleton string
*/
function parseDateTimeSkeleton(skeleton) {
var result = {};
skeleton.replace(DATE_TIME_REGEX, function (match) {
var len = match.length;
switch (match[0]) {
// Era
case 'G':
result.era = len === 4 ? 'long' : len === 5 ? 'narrow' : 'short';
break;
// Year
case 'y':
result.year = len === 2 ? '2-digit' : 'numeric';
break;
case 'Y':
case 'u':
case 'U':
case 'r':
throw new RangeError('`Y/u/U/r` (year) patterns are not supported, use `y` instead');
// Quarter
case 'q':
case 'Q':
throw new RangeError('`q/Q` (quarter) patterns are not supported');
// Month
case 'M':
case 'L':
result.month = ['numeric', '2-digit', 'short', 'long', 'narrow'][len - 1];
break;
// Week
case 'w':
case 'W':
throw new RangeError('`w/W` (week) patterns are not supported');
case 'd':
result.day = ['numeric', '2-digit'][len - 1];
break;
case 'D':
case 'F':
case 'g':
throw new RangeError('`D/F/g` (day) patterns are not supported, use `d` instead');
// Weekday
case 'E':
result.weekday = len === 4 ? 'short' : len === 5 ? 'narrow' : 'short';
break;
case 'e':
if (len < 4) {
throw new RangeError('`e..eee` (weekday) patterns are not supported');
}
result.weekday = ['short', 'long', 'narrow', 'short'][len - 4];
break;
case 'c':
if (len < 4) {
throw new RangeError('`c..ccc` (weekday) patterns are not supported');
}
result.weekday = ['short', 'long', 'narrow', 'short'][len - 4];
break;
// Period
case 'a': // AM, PM
result.hour12 = true;
break;
case 'b': // am, pm, noon, midnight
case 'B': // flexible day periods
throw new RangeError('`b/B` (period) patterns are not supported, use `a` instead');
// Hour
case 'h':
result.hourCycle = 'h12';
result.hour = ['numeric', '2-digit'][len - 1];
break;
case 'H':
result.hourCycle = 'h23';
result.hour = ['numeric', '2-digit'][len - 1];
break;
case 'K':
result.hourCycle = 'h11';
result.hour = ['numeric', '2-digit'][len - 1];
break;
case 'k':
result.hourCycle = 'h24';
result.hour = ['numeric', '2-digit'][len - 1];
break;
case 'j':
case 'J':
case 'C':
throw new RangeError('`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead');
// Minute
case 'm':
result.minute = ['numeric', '2-digit'][len - 1];
break;
// Second
case 's':
result.second = ['numeric', '2-digit'][len - 1];
break;
case 'S':
case 'A':
throw new RangeError('`S/A` (second) patterns are not supported, use `s` instead');
// Zone
case 'z': // 1..3, 4: specific non-location format
result.timeZoneName = len < 4 ? 'short' : 'long';
break;
case 'Z': // 1..3, 4, 5: The ISO8601 varios formats
case 'O': // 1, 4: miliseconds in day short, long
case 'v': // 1, 4: generic non-location format
case 'V': // 1, 2, 3, 4: time zone ID or city
case 'X': // 1, 2, 3, 4: The ISO8601 varios formats
case 'x': // 1, 2, 3, 4: The ISO8601 varios formats
throw new RangeError('`Z/O/v/V/X/x` (timeZone) patterns are not supported, use `z` instead');
}
return '';
});
return result;
}
function icuUnitToEcma(unit) {
return unit.replace(/^(.*?)-/, '');
}
var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?$/g;
var INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g;
var CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/;
function parseSignificantPrecision(str) {
var result = {};
str.replace(SIGNIFICANT_PRECISION_REGEX, function (_, g1, g2) {
// @@@ case
if (typeof g2 !== 'string') {
result.minimumSignificantDigits = g1.length;
result.maximumSignificantDigits = g1.length;
}
// @@@+ case
else if (g2 === '+') {
result.minimumSignificantDigits = g1.length;
}
// .### case
else if (g1[0] === '#') {
result.maximumSignificantDigits = g1.length;
}
// .@@## or .@@@ case
else {
result.minimumSignificantDigits = g1.length;
result.maximumSignificantDigits =
g1.length + (typeof g2 === 'string' ? g2.length : 0);
}
return '';
});
return result;
}
function parseSign(str) {
switch (str) {
case 'sign-auto':
return {
signDisplay: 'auto',
};
case 'sign-accounting':
case '()':
return {
currencySign: 'accounting',
};
case 'sign-always':
case '+!':
return {
signDisplay: 'always',
};
case 'sign-accounting-always':
case '()!':
return {
signDisplay: 'always',
currencySign: 'accounting',
};
case 'sign-except-zero':
case '+?':
return {
signDisplay: 'exceptZero',
};
case 'sign-accounting-except-zero':
case '()?':
return {
signDisplay: 'exceptZero',
currencySign: 'accounting',
};
case 'sign-never':
case '+_':
return {
signDisplay: 'never',
};
}
}
function parseConciseScientificAndEngineeringStem(stem) {
// Engineering
var result;
if (stem[0] === 'E' && stem[1] === 'E') {
result = {
notation: 'engineering',
};
stem = stem.slice(2);
}
else if (stem[0] === 'E') {
result = {
notation: 'scientific',
};
stem = stem.slice(1);
}
if (result) {
var signDisplay = stem.slice(0, 2);
if (signDisplay === '+!') {
result.signDisplay = 'always';
stem = stem.slice(2);
}
else if (signDisplay === '+?') {
result.signDisplay = 'exceptZero';
stem = stem.slice(2);
}
if (!CONCISE_INTEGER_WIDTH_REGEX.test(stem)) {
throw new Error('Malformed concise eng/scientific notation');
}
result.minimumIntegerDigits = stem.length;
}
return result;
}
function parseNotationOptions(opt) {
var result = {};
var signOpts = parseSign(opt);
if (signOpts) {
return signOpts;
}
return result;
}
/**
* https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#skeleton-stems-and-options
*/
function parseNumberSkeleton(tokens) {
var result = {};
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
var token = tokens_1[_i];
switch (token.stem) {
case 'percent':
case '%':
result.style = 'percent';
continue;
case '%x100':
result.style = 'percent';
result.scale = 100;
continue;
case 'currency':
result.style = 'currency';
result.currency = token.options[0];
continue;
case 'group-off':
case ',_':
result.useGrouping = false;
continue;
case 'precision-integer':
case '.':
result.maximumFractionDigits = 0;
continue;
case 'measure-unit':
case 'unit':
result.style = 'unit';
result.unit = icuUnitToEcma(token.options[0]);
continue;
case 'compact-short':
case 'K':
result.notation = 'compact';
result.compactDisplay = 'short';
continue;
case 'compact-long':
case 'KK':
result.notation = 'compact';
result.compactDisplay = 'long';
continue;
case 'scientific':
result = __assign(__assign(__assign({}, result), { notation: 'scientific' }), token.options.reduce(function (all, opt) { return (__assign(__assign({}, all), parseNotationOptions(opt))); }, {}));
continue;
case 'engineering':
result = __assign(__assign(__assign({}, result), { notation: 'engineering' }), token.options.reduce(function (all, opt) { return (__assign(__assign({}, all), parseNotationOptions(opt))); }, {}));
continue;
case 'notation-simple':
result.notation = 'standard';
continue;
// https://github.com/unicode-org/icu/blob/master/icu4c/source/i18n/unicode/unumberformatter.h
case 'unit-width-narrow':
result.currencyDisplay = 'narrowSymbol';
result.unitDisplay = 'narrow';
continue;
case 'unit-width-short':
result.currencyDisplay = 'code';
result.unitDisplay = 'short';
continue;
case 'unit-width-full-name':
result.currencyDisplay = 'name';
result.unitDisplay = 'long';
continue;
case 'unit-width-iso-code':
result.currencyDisplay = 'symbol';
continue;
case 'scale':
result.scale = parseFloat(token.options[0]);
continue;
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#integer-width
case 'integer-width':
if (token.options.length > 1) {
throw new RangeError('integer-width stems only accept a single optional option');
}
token.options[0].replace(INTEGER_WIDTH_REGEX, function (_, g1, g2, g3, g4, g5) {
if (g1) {
result.minimumIntegerDigits = g2.length;
}
else if (g3 && g4) {
throw new Error('We currently do not support maximum integer digits');
}
else if (g5) {
throw new Error('We currently do not support exact integer digits');
}
return '';
});
continue;
}
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#integer-width
if (CONCISE_INTEGER_WIDTH_REGEX.test(token.stem)) {
result.minimumIntegerDigits = token.stem.length;
continue;
}
if (FRACTION_PRECISION_REGEX.test(token.stem)) {
// Precision
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#fraction-precision
// precision-integer case
if (token.options.length > 1) {
throw new RangeError('Fraction-precision stems only accept a single optional option');
}
token.stem.replace(FRACTION_PRECISION_REGEX, function (_, g1, g2, g3, g4, g5) {
// .000* case (before ICU67 it was .000+)
if (g2 === '*') {
result.minimumFractionDigits = g1.length;
}
// .### case
else if (g3 && g3[0] === '#') {
result.maximumFractionDigits = g3.length;
}
// .00## case
else if (g4 && g5) {
result.minimumFractionDigits = g4.length;
result.maximumFractionDigits = g4.length + g5.length;
}
else {
result.minimumFractionDigits = g1.length;
result.maximumFractionDigits = g1.length;
}
return '';
});
if (token.options.length) {
result = __assign(__assign({}, result), parseSignificantPrecision(token.options[0]));
}
continue;
}
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#significant-digits-precision
if (SIGNIFICANT_PRECISION_REGEX.test(token.stem)) {
result = __assign(__assign({}, result), parseSignificantPrecision(token.stem));
continue;
}
var signOpts = parseSign(token.stem);
if (signOpts) {
result = __assign(__assign({}, result), signOpts);
}
var conciseScientificAndEngineeringOpts = parseConciseScientificAndEngineeringStem(token.stem);
if (conciseScientificAndEngineeringOpts) {
result = __assign(__assign({}, result), conciseScientificAndEngineeringOpts);
}
}
return result;
}
// @ts-nocheck
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 () { return !ignoreTag; };
var peg$c1 = function (x) { return x; };
var peg$c2 = function () { return ignoreTag; };
var peg$c3 = "<";
var peg$c4 = peg$literalExpectation("<", false);
var peg$c5 = function (parts) {
return parts.join('');
};
var peg$c6 = function () { return '<'; };
var peg$c7 = function (messageText) {
return __assign({ type: TYPE.literal, value: messageText }, insertLocation());
};
var peg$c8 = "#";
var peg$c9 = peg$literalExpectation("#", false);
var peg$c10 = function () {
return __assign({ type: TYPE.pound }, insertLocation());
};
var peg$c11 = peg$otherExpectation("tagElement");
var peg$c12 = function (open, children, close) {
if (open !== close) {
error("Mismatch tag \"" + open + "\" !== \"" + close + "\"", location());
}
return __assign({ type: TYPE.tag, value: open, children: children }, insertLocation());
};
var peg$c13 = "/>";
var peg$c14 = peg$literalExpectation("/>", false);
var peg$c15 = function (value) {
return __assign({ type: TYPE.literal, value: value.join('') }, insertLocation());
};
var peg$c16 = ">";
var peg$c17 = peg$literalExpectation(">", false);
var peg$c18 = function (tag) { return tag; };
var peg$c19 = "</";
var peg$c20 = peg$literalExpectation("</", false);
var peg$c21 = peg$otherExpectation("argumentElement");
var peg$c22 = "{";
var peg$c23 = peg$literalExpectation("{", false);
var peg$c24 = "}";
var peg$c25 = peg$literalExpectation("}", false);
var peg$c26 = function (value) {
return __assign({ type: TYPE.argument, value: value }, insertLocation());
};
var peg$c27 = peg$otherExpectation("numberSkeletonId");
var peg$c28 = /^['\/{}]/;
var peg$c29 = peg$classExpectation(["'", "/", "{", "}"], false, false);
var peg$c30 = peg$anyExpectation();
var peg$c31 = peg$otherExpectation("numberSkeletonTokenOption");
var peg$c32 = "/";
var peg$c33 = peg$literalExpectation("/", false);
var peg$c34 = function (option) { return option; };
var peg$c35 = peg$otherExpectation("numberSkeletonToken");
var peg$c36 = function (stem, options) {
return { stem: stem, options: options };
};
var peg$c37 = function (tokens) {
return __assign({ type: 0 /* number */, tokens: tokens, parsedOptions: shouldParseSkeleton ? parseNumberSkeleton(tokens) : {} }, insertLocation());
};
var peg$c38 = "::";
var peg$c39 = peg$literalExpectation("::", false);
var peg$c40 = function (skeleton) { return skeleton; };
var peg$c41 = function () { messageCtx.push('numberArgStyle'); return true; };
var peg$c42 = function (style) {
messageCtx.pop();
return style.replace(/\s*$/, '');
};
var peg$c43 = ",";
var peg$c44 = peg$literalExpectation(",", false);
var peg$c45 = "number";
var peg$c46 = peg$literalExpectation("number", false);
var peg$c47 = 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$c48 = "'";
var peg$c49 = peg$literalExpectation("'", false);
var peg$c50 = /^[^']/;
var peg$c51 = peg$classExpectation(["'"], true, false);
var peg$c52 = /^[^a-zA-Z'{}]/;
var peg$c53 = peg$classExpectation([["a", "z"], ["A", "Z"], "'", "{", "}"], true, false);
var peg$c54 = /^[a-zA-Z]/;
var peg$c55 = peg$classExpectation([["a", "z"], ["A", "Z"]], false, false);
var peg$c56 = function (pattern) {
return __assign({ type: 1 /* dateTime */, pattern: pattern, parsedOptions: shouldParseSkeleton ? parseDateTimeSkeleton(pattern) : {} }, insertLocation());
};
var peg$c57 = function () { messageCtx.push('dateOrTimeArgStyle'); return true; };
var peg$c58 = "date";
var peg$c59 = peg$literalExpectation("date", false);
var peg$c60 = "time";
var peg$c61 = peg$literalExpectation("time", false);
var peg$c62 = "plural";
var peg$c63 = peg$literalExpectation("plural", false);
var peg$c64 = "selectordinal";
var peg$c65 = peg$literalExpectation("selectordinal", false);
var peg$c66 = "offset:";
var peg$c67 = peg$literalExpectation("offset:", false);
var peg$c68 = 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$c69 = "select";
var peg$c70 = peg$literalExpectation("select", false);
var peg$c71 = 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$c72 = "=";
var peg$c73 = peg$literalExpectation("=", false);
var peg$c74 = function (id) { messageCtx.push('select'); return true; };
var peg$c75 = function (id, value) {
messageCtx.pop();
return __assign({ id: id,
value: value }, insertLocation());
};
var peg$c76 = function (id) { messageCtx.push('plural'); return true; };
var peg$c77 = function (id, value) {
messageCtx.pop();
return __assign({ id: id,
value: value }, insertLocation());
};
var peg$c78 = peg$otherExpectation("whitespace");
var peg$c79 = /^[\t-\r \x85\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]/;
var peg$c80 = peg$classExpectation([["\t", "\r"], " ", "\x85", "\xA0", "\u1680", ["\u2000", "\u200A"], "\u2028", "\u2029", "\u202F", "\u205F", "\u3000"], false, false);
var peg$c81 = peg$otherExpectation("syntax pattern");
var peg$c82 = /^[!-\/:-@[-\^`{-~\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$c83 = 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$c84 = peg$otherExpectation("optional whitespace");
var peg$c85 = peg$otherExpectation("number");
var peg$c86 = "-";
var peg$c87 = peg$literalExpectation("-", false);
var peg$c88 = function (negative, num) {
return num
? negative
? -num
: num
: 0;
};
var peg$c90 = peg$otherExpectation("double apostrophes");
var peg$c91 = "''";
var peg$c92 = peg$literalExpectation("''", false);
var peg$c93 = function () { return "'"; };
var peg$c94 = function (escapedChar, quotedChars) {
return escapedChar + quotedChars.replace("''", "'");
};
var peg$c95 = function (x) {
return (x !== '<' &&
x !== '{' &&
!(isInPluralOption() && x === '#') &&
!(isNestedMessageText() && x === '}'));
};
var peg$c96 = "\n";
var peg$c97 = peg$literalExpectation("\n", false);
var peg$c98 = function (x) {
return x === '<' || x === '>' || x === '{' || x === '}' || (isInPluralOption() && x === '#');
};
var peg$c99 = peg$otherExpectation("argNameOrNumber");
var peg$c100 = peg$otherExpectation("validTag");
var peg$c101 = peg$otherExpectation("argNumber");
var peg$c102 = "0";
var peg$c103 = peg$literalExpectation("0", false);
var peg$c104 = function () { return 0; };
var peg$c105 = /^[1-9]/;
var peg$c106 = peg$classExpectation([["1", "9"]], false, false);
var peg$c107 = /^[0-9]/;
var peg$c108 = peg$classExpectation([["0", "9"]], false, false);
var peg$c109 = function (digits) {
return parseInt(digits.join(''), 10);
};
var peg$c110 = peg$otherExpectation("argName");
var peg$c111 = peg$otherExpectation("tagName");
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, s1, s2;
s0 = peg$currPos;
peg$savedPos = peg$currPos;
s1 = peg$c0();
if (s1) {
s1 = undefined;
}
else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parsetagElement();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c1(s2);
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
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();
if (s0 === peg$FAILED) {
s0 = peg$parsepoundElement();
}
}
}
}
}
}
return s0;
}
function peg$parsemessageText() {
var s0, s1, s2, s3;
s0 = peg$currPos;
peg$savedPos = peg$currPos;
s1 = peg$c2();
if (s1) {
s1 = undefined;
}
else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parsedoubleApostrophes();
if (s3 === peg$FAILED) {
s3 = peg$parsequotedString();
if (s3 === peg$FAILED) {
s3 = peg$parseunquotedString();
if (s3 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 60) {
s3 = peg$c3;
peg$currPos++;
}
else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c4);
}
}
}
}
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parsedoubleApostrophes();
if (s3 === peg$FAILED) {
s3 = peg$parsequotedString();
if (s3 === peg$FAILED) {
s3 = peg$parseunquotedString();
if (s3 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 60) {
s3 = peg$c3;
peg$currPos++;
}
else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c4);
}
}
}
}
}
}
}
else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c5(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 = [];
s2 = peg$parsedoubleApostrophes();
if (s2 === peg$FAILED) {
s2 = peg$parsequotedString();
if (s2 === peg$FAILED) {
s2 = peg$parseunquotedString();
if (s2 === peg$FAILED) {
s2 = peg$parsenonTagStartingAngleBracket();
}
}
}
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();
if (s2 === peg$FAILED) {
s2 = peg$parsenonTagStartingAngleBracket();
}
}
}
}
}
else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c5(s1);
}
s0 = s1;
}
return s0;
}
function peg$parsenonTagStartingAngleBracket() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$parseopeningTag();
if (s2 === peg$FAILED) {
s2 = peg$parseclosingTag();
if (s2 === peg$FAILED) {
s2 = peg$parseselfClosingTag();
}
}
peg$silentFails--;
if (s2 === peg$FAILED) {
s1 = undefined;
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 60) {
s2 = peg$c3;
peg$currPos++;
}
else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c4);
}
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6();
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseliteralElement() {
var s0, s1;
s0 = peg$currPos;
s1 = peg$parsemessageText();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c7(s1);
}
s0 = s1;
return s0;
}
function peg$parsepoundElement() {
var s0, s1;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 35) {
s1 = peg$c8;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c9);
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c10();
}
s0 = s1;
return s0;
}
function peg$parsetagElement() {
var s0, s1, s2, s3;
peg$silentFails++;
s0 = peg$parseselfClosingTag();
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseopeningTag();
if (s1 !== peg$FAILED) {
s2 = peg$parsemessage();
if (s2 !== peg$FAILED) {
s3 = peg$parseclosingTag();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c12(s1, s2, s3);
s0 = s1;