Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

intl-messageformat

Package Overview
Dependencies
Maintainers
10
Versions
268
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intl-messageformat - npm Package Compare versions

Comparing version 4.2.1 to 4.3.0

8

CHANGELOG.md

@@ -6,10 +6,12 @@ # Change Log

## [4.2.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.2.0...intl-messageformat@4.2.1) (2019-06-26)
# [4.3.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.2.1...intl-messageformat@4.3.0) (2019-06-27)
**Note:** Version bump only for package intl-messageformat
### Features
- **intl-messageformat:** allow passing in formatters ([#107](https://github.com/formatjs/formatjs/issues/107)) ([3605693](https://github.com/formatjs/formatjs/commit/3605693))
## [4.2.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.2.0...intl-messageformat@4.2.1) (2019-06-26)
**Note:** Version bump only for package intl-messageformat
# [4.2.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.1.2...intl-messageformat@4.2.0) (2019-06-27)

@@ -16,0 +18,0 @@

@@ -24,3 +24,3 @@ 'use strict';

var Compiler = /** @class */ (function () {
function Compiler(locales, formats) {
function Compiler(locales, formats, formatters) {
this.locales = [];

@@ -37,2 +37,3 @@ this.formats = {

this.formats = formats;
this.formatters = formatters;
}

@@ -82,2 +83,3 @@ Compiler.prototype.compile = function (ast) {

var format = element.format, id = element.id;
var formatters = this.formatters;
if (!format) {

@@ -91,4 +93,3 @@ return new StringFormat(id);

id: id,
format: new Intl.NumberFormat(locales, formats.number[format.style])
.format
format: formatters.getNumberFormat(locales, formats.number[format.style]).format
};

@@ -98,4 +99,3 @@ case 'dateFormat':

id: id,
format: new Intl.DateTimeFormat(locales, formats.date[format.style])
.format
format: formatters.getDateTimeFormat(locales, formats.date[format.style]).format
};

@@ -105,7 +105,8 @@ case 'timeFormat':

id: id,
format: new Intl.DateTimeFormat(locales, formats.time[format.style])
.format
format: formatters.getDateTimeFormat(locales, formats.time[format.style]).format
};
case 'pluralFormat':
return new PluralFormat(id, format.ordinal, format.offset, this.compileOptions(element), locales);
return new PluralFormat(id, format.offset, this.compileOptions(element), formatters.getPluralRules(locales, {
type: format.ordinal ? 'ordinal' : 'cardinal'
}));
case 'selectFormat':

@@ -158,9 +159,7 @@ return new SelectFormat(id, this.compileOptions(element));

var PluralFormat = /** @class */ (function () {
function PluralFormat(id, useOrdinal, offset, options, locales) {
function PluralFormat(id, offset, options, pluralRules) {
this.id = id;
this.offset = offset;
this.options = options;
this.pluralRules = new Intl.PluralRules(locales, {
type: useOrdinal ? 'ordinal' : 'cardinal'
});
this.pluralRules = pluralRules;
}

@@ -207,2 +206,1530 @@ PluralFormat.prototype.getOption = function (value) {

var parser = /*
* Generated by PEG.js 0.10.0.
*
* http://pegjs.org/
*/
(function() {
function peg$subclass(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor();
}
function peg$SyntaxError(message, expected, found, location) {
this.message = message;
this.expected = expected;
this.found = found;
this.location = location;
this.name = "SyntaxError";
if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(this, peg$SyntaxError);
}
}
peg$subclass(peg$SyntaxError, Error);
peg$SyntaxError.buildMessage = function(expected, found) {
var DESCRIBE_EXPECTATION_FNS = {
literal: function(expectation) {
return "\"" + literalEscape(expectation.text) + "\"";
},
"class": function(expectation) {
var escapedParts = "",
i;
for (i = 0; i < expectation.parts.length; i++) {
escapedParts += expectation.parts[i] instanceof Array
? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1])
: classEscape(expectation.parts[i]);
}
return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
},
any: function(expectation) {
return "any character";
},
end: function(expectation) {
return "end of input";
},
other: function(expectation) {
return expectation.description;
}
};
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) {
return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
}
function describeExpected(expected) {
var descriptions = new Array(expected.length),
i, j;
for (i = 0; i < expected.length; i++) {
descriptions[i] = describeExpectation(expected[i]);
}
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(found) {
return found ? "\"" + literalEscape(found) + "\"" : "end of input";
}
return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
};
function peg$parse(input, options) {
options = options !== void 0 ? options : {};
var peg$FAILED = {},
peg$startRuleFunctions = { start: peg$parsestart },
peg$startRuleFunction = peg$parsestart,
peg$c0 = function(elements) {
return {
type : 'messageFormatPattern',
elements: elements,
location: location()
};
},
peg$c1 = function(chunks) {
return chunks.reduce(function (all, chunk) {
return all.concat(chunk)
}, []).join('')
},
peg$c2 = function(messageText) {
return {
type : 'messageTextElement',
value: messageText,
location: location()
};
},
peg$c3 = function(chars) { return chars.join(''); },
peg$c4 = "{",
peg$c5 = peg$literalExpectation("{", false),
peg$c6 = ",",
peg$c7 = peg$literalExpectation(",", false),
peg$c8 = "}",
peg$c9 = peg$literalExpectation("}", false),
peg$c10 = function(id, format) {
return {
type : 'argumentElement',
id : id,
format: format && format[2],
location: location()
};
},
peg$c11 = "number",
peg$c12 = peg$literalExpectation("number", false),
peg$c13 = "date",
peg$c14 = peg$literalExpectation("date", false),
peg$c15 = "time",
peg$c16 = peg$literalExpectation("time", false),
peg$c17 = function(type, style) {
return {
type : type + 'Format',
style: style && style[2],
location: location()
};
},
peg$c18 = "plural",
peg$c19 = peg$literalExpectation("plural", false),
peg$c20 = function(pluralStyle) {
return {
type : pluralStyle.type,
ordinal: false,
offset : pluralStyle.offset || 0,
options: pluralStyle.options,
location: location()
};
},
peg$c21 = "selectordinal",
peg$c22 = peg$literalExpectation("selectordinal", false),
peg$c23 = function(pluralStyle) {
return {
type : pluralStyle.type,
ordinal: true,
offset : pluralStyle.offset || 0,
options: pluralStyle.options,
location: location()
}
},
peg$c24 = "select",
peg$c25 = peg$literalExpectation("select", false),
peg$c26 = function(options) {
return {
type : 'selectFormat',
options: options,
location: location()
};
},
peg$c27 = "=",
peg$c28 = peg$literalExpectation("=", false),
peg$c29 = function(selector, pattern) {
return {
type : 'optionalFormatPattern',
selector: selector,
value : pattern,
location: location()
};
},
peg$c30 = "offset:",
peg$c31 = peg$literalExpectation("offset:", false),
peg$c32 = function(number) {
return number;
},
peg$c33 = function(offset, options) {
return {
type : 'pluralFormat',
offset : offset,
options: options,
location: location()
};
},
peg$c34 = peg$otherExpectation("whitespace"),
peg$c35 = /^[ \t\n\r]/,
peg$c36 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false),
peg$c37 = peg$otherExpectation("optionalWhitespace"),
peg$c38 = /^[0-9]/,
peg$c39 = peg$classExpectation([["0", "9"]], false, false),
peg$c40 = /^[0-9a-f]/i,
peg$c41 = peg$classExpectation([["0", "9"], ["a", "f"]], false, true),
peg$c42 = "0",
peg$c43 = peg$literalExpectation("0", false),
peg$c44 = /^[1-9]/,
peg$c45 = peg$classExpectation([["1", "9"]], false, false),
peg$c46 = function(digits) {
return parseInt(digits, 10);
},
peg$c47 = "'",
peg$c48 = peg$literalExpectation("'", false),
peg$c49 = /^[ \t\n\r,.+={}#]/,
peg$c50 = peg$classExpectation([" ", "\t", "\n", "\r", ",", ".", "+", "=", "{", "}", "#"], false, false),
peg$c51 = peg$anyExpectation(),
peg$c52 = function(char) { return char; },
peg$c53 = function(sequence) { return sequence; },
peg$c54 = /^[^{}\\\0-\x1F\x7F \t\n\r]/,
peg$c55 = peg$classExpectation(["{", "}", "\\", ["\0", "\x1F"], "\x7F", " ", "\t", "\n", "\r"], true, false),
peg$c56 = "\\\\",
peg$c57 = peg$literalExpectation("\\\\", false),
peg$c58 = function() { return '\\'; },
peg$c59 = "\\#",
peg$c60 = peg$literalExpectation("\\#", false),
peg$c61 = function() { return '\\#'; },
peg$c62 = "\\{",
peg$c63 = peg$literalExpectation("\\{", false),
peg$c64 = function() { return '\u007B'; },
peg$c65 = "\\}",
peg$c66 = peg$literalExpectation("\\}", false),
peg$c67 = function() { return '\u007D'; },
peg$c68 = "\\u",
peg$c69 = peg$literalExpectation("\\u", false),
peg$c70 = function(digits) {
return String.fromCharCode(parseInt(digits, 16));
},
peg$currPos = 0,
peg$savedPos = 0,
peg$posDetailsCache = [{ line: 1, column: 1 }],
peg$maxFailPos = 0,
peg$maxFailExpected = [],
peg$silentFails = 0,
peg$result;
if ("startRule" in options) {
if (!(options.startRule in peg$startRuleFunctions)) {
throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
}
peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
}
function location() {
return peg$computeLocation(peg$savedPos, peg$currPos);
}
function peg$literalExpectation(text, ignoreCase) {
return { type: "literal", text: text, 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], 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),
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(expected) {
if (peg$currPos < peg$maxFailPos) { return; }
if (peg$currPos > peg$maxFailPos) {
peg$maxFailPos = peg$currPos;
peg$maxFailExpected = [];
}
peg$maxFailExpected.push(expected);
}
function peg$buildStructuredError(expected, found, location) {
return new peg$SyntaxError(
peg$SyntaxError.buildMessage(expected, found),
expected,
found,
location
);
}
function peg$parsestart() {
var s0;
s0 = peg$parsemessageFormatPattern();
return s0;
}
function peg$parsemessageFormatPattern() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
s2 = peg$parsemessageFormatElement();
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parsemessageFormatElement();
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c0(s1);
}
s0 = s1;
return s0;
}
function peg$parsemessageFormatElement() {
var s0;
s0 = peg$parsemessageTextElement();
if (s0 === peg$FAILED) {
s0 = peg$parseargumentElement();
}
return s0;
}
function peg$parsemessageText() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
s1 = [];
s2 = peg$currPos;
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
s4 = peg$parsechars();
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
s3 = [s3, s4, s5];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} 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$parse_();
if (s3 !== peg$FAILED) {
s4 = peg$parsechars();
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
s3 = [s3, s4, s5];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
}
} else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c1(s1);
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parsews();
if (s1 !== peg$FAILED) {
s0 = input.substring(s0, peg$currPos);
} else {
s0 = s1;
}
}
return s0;
}
function peg$parsemessageTextElement() {
var s0, s1;
s0 = peg$currPos;
s1 = peg$parsemessageText();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c2(s1);
}
s0 = s1;
return s0;
}
function peg$parseargument() {
var s0, s1, s2;
s0 = peg$parsenumber();
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = [];
s2 = peg$parsequoteEscapedChar();
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parsequoteEscapedChar();
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c3(s1);
}
s0 = s1;
}
return s0;
}
function peg$parseargumentElement() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 123) {
s1 = peg$c4;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c5); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = peg$parseargument();
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 44) {
s6 = peg$c6;
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c7); }
}
if (s6 !== peg$FAILED) {
s7 = peg$parse_();
if (s7 !== peg$FAILED) {
s8 = peg$parseelementFormat();
if (s8 !== peg$FAILED) {
s6 = [s6, s7, s8];
s5 = s6;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
if (s5 === peg$FAILED) {
s5 = null;
}
if (s5 !== peg$FAILED) {
s6 = peg$parse_();
if (s6 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s7 = peg$c8;
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c9); }
}
if (s7 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c10(s3, 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;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseelementFormat() {
var s0;
s0 = peg$parsesimpleFormat();
if (s0 === peg$FAILED) {
s0 = peg$parsepluralFormat();
if (s0 === peg$FAILED) {
s0 = peg$parseselectOrdinalFormat();
if (s0 === peg$FAILED) {
s0 = peg$parseselectFormat();
}
}
}
return s0;
}
function peg$parsesimpleFormat() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
if (input.substr(peg$currPos, 6) === peg$c11) {
s1 = peg$c11;
peg$currPos += 6;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c12); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c13) {
s1 = peg$c13;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c14); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c15) {
s1 = peg$c15;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c16); }
}
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 44) {
s4 = peg$c6;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c7); }
}
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
if (s5 !== peg$FAILED) {
s6 = peg$parsechars();
if (s6 !== peg$FAILED) {
s4 = [s4, s5, s6];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 === peg$FAILED) {
s3 = null;
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c17(s1, s3);
s0 = s1;
} 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$parsepluralFormat() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.substr(peg$currPos, 6) === peg$c18) {
s1 = peg$c18;
peg$currPos += 6;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c19); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s3 = peg$c6;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c7); }
}
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$parsepluralStyle();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c20(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;
}
return s0;
}
function peg$parseselectOrdinalFormat() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.substr(peg$currPos, 13) === peg$c21) {
s1 = peg$c21;
peg$currPos += 13;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c22); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s3 = peg$c6;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c7); }
}
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$parsepluralStyle();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c23(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;
}
return s0;
}
function peg$parseselectFormat() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
if (input.substr(peg$currPos, 6) === peg$c24) {
s1 = peg$c24;
peg$currPos += 6;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c25); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s3 = peg$c6;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c7); }
}
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = [];
s6 = peg$parseoptionalFormatPattern();
if (s6 !== peg$FAILED) {
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$parseoptionalFormatPattern();
}
} else {
s5 = peg$FAILED;
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c26(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;
}
return s0;
}
function peg$parseselector() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 61) {
s2 = peg$c27;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c28); }
}
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$parsechars();
}
return s0;
}
function peg$parseoptionalFormatPattern() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
s1 = peg$parse_();
if (s1 !== peg$FAILED) {
s2 = peg$parseselector();
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 123) {
s4 = peg$c4;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c5); }
}
if (s4 !== peg$FAILED) {
s5 = peg$parsemessageFormatPattern();
if (s5 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s6 = peg$c8;
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c9); }
}
if (s6 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c29(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$parseoffset() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.substr(peg$currPos, 7) === peg$c30) {
s1 = peg$c30;
peg$currPos += 7;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c31); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = peg$parsenumber();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c32(s3);
s0 = s1;
} 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$parsepluralStyle() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
s1 = peg$parseoffset();
if (s1 === peg$FAILED) {
s1 = null;
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$parseoptionalFormatPattern();
if (s4 !== peg$FAILED) {
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parseoptionalFormatPattern();
}
} else {
s3 = peg$FAILED;
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c33(s1, s3);
s0 = s1;
} 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$parsews() {
var s0, s1;
peg$silentFails++;
s0 = [];
if (peg$c35.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c36); }
}
if (s1 !== peg$FAILED) {
while (s1 !== peg$FAILED) {
s0.push(s1);
if (peg$c35.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c36); }
}
}
} else {
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c34); }
}
return s0;
}
function peg$parse_() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
s1 = [];
s2 = peg$parsews();
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parsews();
}
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$c37); }
}
return s0;
}
function peg$parsedigit() {
var s0;
if (peg$c38.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c39); }
}
return s0;
}
function peg$parsehexDigit() {
var s0;
if (peg$c40.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c41); }
}
return s0;
}
function peg$parsenumber() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 48) {
s1 = peg$c42;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c43); }
}
if (s1 === peg$FAILED) {
s1 = peg$currPos;
s2 = peg$currPos;
if (peg$c44.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c45); }
}
if (s3 !== peg$FAILED) {
s4 = [];
s5 = peg$parsedigit();
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parsedigit();
}
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) {
s1 = input.substring(s1, peg$currPos);
} else {
s1 = s2;
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c46(s1);
}
s0 = s1;
return s0;
}
function peg$parsequoteEscapedChar() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 39) {
s2 = peg$c47;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c48); }
}
if (s2 === peg$FAILED) {
if (peg$c49.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c50); }
}
}
peg$silentFails--;
if (s2 === peg$FAILED) {
s1 = void 0;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
if (input.length > peg$currPos) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c51); }
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c52(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 39) {
s1 = peg$c47;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c48); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parseescape();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c53(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
return s0;
}
function peg$parseapostrophe() {
var s0;
if (input.charCodeAt(peg$currPos) === 39) {
s0 = peg$c47;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c48); }
}
return s0;
}
function peg$parseescape() {
var s0;
if (peg$c49.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c50); }
}
if (s0 === peg$FAILED) {
s0 = peg$parseapostrophe();
}
return s0;
}
function peg$parsechar() {
var s0, s1, s2, s3, s4, s5, s6, s7;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 39) {
s1 = peg$c47;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c48); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parseapostrophe();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c53(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
if (peg$c54.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c55); }
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c56) {
s1 = peg$c56;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c57); }
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c58();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c59) {
s1 = peg$c59;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c60); }
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c61();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c62) {
s1 = peg$c62;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c63); }
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c64();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c65) {
s1 = peg$c65;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c66); }
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c67();
}
s0 = s1;
if (s0 === peg$FAILED) {
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) {
s2 = peg$currPos;
s3 = peg$currPos;
s4 = peg$parsehexDigit();
if (s4 !== peg$FAILED) {
s5 = peg$parsehexDigit();
if (s5 !== peg$FAILED) {
s6 = peg$parsehexDigit();
if (s6 !== peg$FAILED) {
s7 = peg$parsehexDigit();
if (s7 !== peg$FAILED) {
s4 = [s4, s5, s6, s7];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 !== peg$FAILED) {
s2 = input.substring(s2, peg$currPos);
} else {
s2 = s3;
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c70(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
}
}
}
}
}
return s0;
}
function peg$parsechars() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
s2 = peg$parsechar();
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parsechar();
}
} else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c3(s1);
}
s0 = s1;
return s0;
}
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)
);
}
}
return {
SyntaxError: peg$SyntaxError,
parse: peg$parse
};
})();
/*

@@ -250,3 +1777,3 @@ Copyright (c) 2014, Yahoo! Inc. All rights reserved.

catch (e) {
return MessageFormat.defaultLocale;
return IntlMessageFormat.defaultLocale;
}

@@ -308,28 +1835,41 @@ }

}(Error));
var MessageFormat = (function (message, locales, overrideFormats) {
if (locales === void 0) { locales = MessageFormat.defaultLocale; }
// Parse string messages into an AST.
var ast = typeof message === 'string' ? MessageFormat.__parse(message) : message;
if (!(ast && ast.type === 'messageFormatPattern')) {
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.
var formats = mergeConfigs(MessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
var locale = resolveLocale(locales || []);
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
var pattern = new Compiler(locales, formats).compile(ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
function createDefaultFormatters() {
return {
format: function (values) {
getNumberFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.NumberFormat).bind.apply(_a, [void 0].concat(args)))();
},
getDateTimeFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, [void 0].concat(args)))();
},
getPluralRules: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.PluralRules).bind.apply(_a, [void 0].concat(args)))();
}
};
}
var IntlMessageFormat = /** @class */ (function () {
function IntlMessageFormat(message, locales, overrideFormats, opts) {
var _this = this;
if (locales === void 0) { locales = IntlMessageFormat.defaultLocale; }
this.format = function (values) {
try {
return formatPatterns(pattern, values);
return formatPatterns(_this.pattern, values);
}
catch (e) {
if (e.variableId) {
throw new Error("The intl string context variable '" + e.variableId + "' was not provided to the string '" + message + "'");
throw new Error("The intl string context variable '" + e.variableId + "' was not provided to the string '" + _this.message + "'");
}

@@ -340,73 +1880,97 @@ else {

}
},
resolvedOptions: function () {
return { locale: locale };
},
getAst: function () {
return ast;
};
// Parse string messages into an AST.
this.ast =
typeof message === 'string'
? IntlMessageFormat.__parse(message)
: message;
this.message = typeof message === 'string' ? message : '';
if (!(this.ast && this.ast.type === 'messageFormatPattern')) {
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.
var formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
this.locale = resolveLocale(locales || []);
var formatters = (opts && opts.formatters) || createDefaultFormatters();
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
this.pattern = new Compiler(locales, formats, formatters).compile(this.ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
}
IntlMessageFormat.prototype.resolvedOptions = function () {
return { locale: this.locale };
};
});
MessageFormat.defaultLocale = 'en';
// 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.
MessageFormat.formats = {
number: {
currency: {
style: 'currency'
IntlMessageFormat.prototype.getAst = function () {
return this.ast;
};
IntlMessageFormat.defaultLocale = 'en';
IntlMessageFormat.__parse = parser.parse;
// 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'
}
},
percent: {
style: 'percent'
}
},
date: {
short: {
month: 'numeric',
day: 'numeric',
year: '2-digit'
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'
}
},
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'
}
}
},
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;
}());
exports.MessageFormat = MessageFormat;
exports.default = MessageFormat;
exports.IntlMessageFormat = IntlMessageFormat;
exports.createDefaultFormatters = createDefaultFormatters;
exports.default = IntlMessageFormat;

@@ -7,2 +7,7 @@ import { MessageFormatPattern, MessageTextElement, ArgumentElement } from 'intl-messageformat-parser';

}
export interface Formatters {
getNumberFormat(...args: ConstructorParameters<typeof Intl.NumberFormat>): Intl.NumberFormat;
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
}
export declare type Pattern = string | PluralOffsetString | PluralFormat | SelectFormat | StringFormat;

@@ -15,3 +20,4 @@ export default class Compiler {

private pluralStack;
constructor(locales: string | string[], formats: Formats);
private formatters;
constructor(locales: string | string[], formats: Formats, formatters: Formatters);
compile(ast: MessageFormatPattern): Pattern[];

@@ -28,6 +34,6 @@ compileMessage(ast: MessageFormatPattern): Pattern[];

}
export declare class StringFormat extends Formatter {
declare class StringFormat extends Formatter {
format(value: number | string): string;
}
export declare class PluralFormat {
declare class PluralFormat {
id: string;

@@ -37,3 +43,3 @@ private offset;

private pluralRules;
constructor(id: string, useOrdinal: boolean, offset: number, options: Record<string, Pattern[]>, locales: string | string[]);
constructor(id: string, offset: number, options: Record<string, Pattern[]>, pluralRules: Intl.PluralRules);
getOption(value: number): Pattern[];

@@ -40,0 +46,0 @@ }

@@ -22,3 +22,3 @@ "use strict";

var Compiler = /** @class */ (function () {
function Compiler(locales, formats) {
function Compiler(locales, formats, formatters) {
this.locales = [];

@@ -35,2 +35,3 @@ this.formats = {

this.formats = formats;
this.formatters = formatters;
}

@@ -80,2 +81,3 @@ Compiler.prototype.compile = function (ast) {

var format = element.format, id = element.id;
var formatters = this.formatters;
if (!format) {

@@ -89,4 +91,3 @@ return new StringFormat(id);

id: id,
format: new Intl.NumberFormat(locales, formats.number[format.style])
.format
format: formatters.getNumberFormat(locales, formats.number[format.style]).format
};

@@ -96,4 +97,3 @@ case 'dateFormat':

id: id,
format: new Intl.DateTimeFormat(locales, formats.date[format.style])
.format
format: formatters.getDateTimeFormat(locales, formats.date[format.style]).format
};

@@ -103,7 +103,8 @@ case 'timeFormat':

id: id,
format: new Intl.DateTimeFormat(locales, formats.time[format.style])
.format
format: formatters.getDateTimeFormat(locales, formats.time[format.style]).format
};
case 'pluralFormat':
return new PluralFormat(id, format.ordinal, format.offset, this.compileOptions(element), locales);
return new PluralFormat(id, format.offset, this.compileOptions(element), formatters.getPluralRules(locales, {
type: format.ordinal ? 'ordinal' : 'cardinal'
}));
case 'selectFormat':

@@ -156,11 +157,8 @@ return new SelectFormat(id, this.compileOptions(element));

}(Formatter));
exports.StringFormat = StringFormat;
var PluralFormat = /** @class */ (function () {
function PluralFormat(id, useOrdinal, offset, options, locales) {
function PluralFormat(id, offset, options, pluralRules) {
this.id = id;
this.offset = offset;
this.options = options;
this.pluralRules = new Intl.PluralRules(locales, {
type: useOrdinal ? 'ordinal' : 'cardinal'
});
this.pluralRules = pluralRules;
}

@@ -175,3 +173,2 @@ PluralFormat.prototype.getOption = function (value) {

}());
exports.PluralFormat = PluralFormat;
var PluralOffsetString = /** @class */ (function (_super) {

@@ -178,0 +175,0 @@ __extends(PluralOffsetString, _super);

@@ -1,17 +0,78 @@

import { Formats } from './compiler';
import parser, { MessageFormatPattern } from 'intl-messageformat-parser';
export interface IntlMessageFormat {
new (message: string | MessageFormatPattern, locales?: string | string[], overrideFormats?: Partial<Formats>): IntlMessageFormat;
(message: string | MessageFormatPattern, locales?: string | string[], overrideFormats?: Partial<Formats>): IntlMessageFormat;
format(values?: Record<string, string | number | boolean | null | undefined>): string;
import { Formats, Formatters } from './compiler';
import { MessageFormatPattern } from 'intl-messageformat-parser';
export interface Options {
formatters?: Formatters;
}
export declare function createDefaultFormatters(): Formatters;
export declare class IntlMessageFormat {
private ast;
private locale;
private pattern;
private message;
constructor(message: string | MessageFormatPattern, locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
format: (values?: Record<string, string | number | boolean | null | undefined> | undefined) => string;
resolvedOptions(): {
locale: string;
};
getAst(): ReturnType<typeof parser['parse']>;
defaultLocale: string;
formats: Formats;
__parse: typeof parser['parse'];
getAst(): MessageFormatPattern;
static defaultLocale: string;
static __parse: (msg: string) => MessageFormatPattern;
static formats: {
number: {
currency: {
style: string;
};
percent: {
style: string;
};
};
date: {
short: {
month: string;
day: string;
year: string;
};
medium: {
month: string;
day: string;
year: string;
};
long: {
month: string;
day: string;
year: string;
};
full: {
weekday: string;
month: string;
day: string;
year: string;
};
};
time: {
short: {
hour: string;
minute: string;
};
medium: {
hour: string;
minute: string;
second: string;
};
long: {
hour: string;
minute: string;
second: string;
timeZoneName: string;
};
full: {
hour: string;
minute: string;
second: string;
timeZoneName: string;
};
};
};
}
export declare const MessageFormat: IntlMessageFormat;
export { Formats, Pattern } from './compiler';
export default MessageFormat;
export default IntlMessageFormat;

@@ -34,2 +34,3 @@ "use strict";

var compiler_1 = require("./compiler");
var intl_messageformat_parser_1 = require("intl-messageformat-parser");
// -- MessageFormat --------------------------------------------------------

@@ -48,3 +49,3 @@ function resolveLocale(locales) {

catch (e) {
return exports.MessageFormat.defaultLocale;
return IntlMessageFormat.defaultLocale;
}

@@ -106,28 +107,42 @@ }

}(Error));
exports.MessageFormat = (function (message, locales, overrideFormats) {
if (locales === void 0) { locales = exports.MessageFormat.defaultLocale; }
// Parse string messages into an AST.
var ast = typeof message === 'string' ? exports.MessageFormat.__parse(message) : message;
if (!(ast && ast.type === 'messageFormatPattern')) {
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.
var formats = mergeConfigs(exports.MessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
var locale = resolveLocale(locales || []);
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
var pattern = new compiler_1.default(locales, formats).compile(ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
function createDefaultFormatters() {
return {
format: function (values) {
getNumberFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.NumberFormat).bind.apply(_a, [void 0].concat(args)))();
},
getDateTimeFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, [void 0].concat(args)))();
},
getPluralRules: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.PluralRules).bind.apply(_a, [void 0].concat(args)))();
}
};
}
exports.createDefaultFormatters = createDefaultFormatters;
var IntlMessageFormat = /** @class */ (function () {
function IntlMessageFormat(message, locales, overrideFormats, opts) {
var _this = this;
if (locales === void 0) { locales = IntlMessageFormat.defaultLocale; }
this.format = function (values) {
try {
return formatPatterns(pattern, values);
return formatPatterns(_this.pattern, values);
}
catch (e) {
if (e.variableId) {
throw new Error("The intl string context variable '" + e.variableId + "' was not provided to the string '" + message + "'");
throw new Error("The intl string context variable '" + e.variableId + "' was not provided to the string '" + _this.message + "'");
}

@@ -138,72 +153,96 @@ else {

}
},
resolvedOptions: function () {
return { locale: locale };
},
getAst: function () {
return ast;
};
// Parse string messages into an AST.
this.ast =
typeof message === 'string'
? IntlMessageFormat.__parse(message)
: message;
this.message = typeof message === 'string' ? message : '';
if (!(this.ast && this.ast.type === 'messageFormatPattern')) {
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.
var formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
this.locale = resolveLocale(locales || []);
var formatters = (opts && opts.formatters) || createDefaultFormatters();
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
this.pattern = new compiler_1.default(locales, formats, formatters).compile(this.ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
}
IntlMessageFormat.prototype.resolvedOptions = function () {
return { locale: this.locale };
};
});
exports.MessageFormat.defaultLocale = 'en';
// 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.
exports.MessageFormat.formats = {
number: {
currency: {
style: 'currency'
IntlMessageFormat.prototype.getAst = function () {
return this.ast;
};
IntlMessageFormat.defaultLocale = 'en';
IntlMessageFormat.__parse = intl_messageformat_parser_1.default.parse;
// 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'
}
},
percent: {
style: 'percent'
}
},
date: {
short: {
month: 'numeric',
day: 'numeric',
year: '2-digit'
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'
}
},
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'
}
}
},
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'
}
}
};
exports.default = exports.MessageFormat;
};
return IntlMessageFormat;
}());
exports.IntlMessageFormat = IntlMessageFormat;
exports.default = IntlMessageFormat;
//# sourceMappingURL=core.js.map

@@ -1,3 +0,5 @@

import MessageFormat from './core';
import IntlMessageFormat from './core';
export { Formats, Pattern } from './compiler';
export default MessageFormat;
export * from './core';
export { Formatters } from './compiler';
export default IntlMessageFormat;

@@ -7,2 +7,5 @@ "use strict";

*/
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });

@@ -12,3 +15,4 @@ var intl_messageformat_parser_1 = require("intl-messageformat-parser");

core_1.default.__parse = intl_messageformat_parser_1.default.parse;
__export(require("./core"));
exports.default = core_1.default;
//# sourceMappingURL=index.js.map
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.IntlMessageFormat = factory());
}(this, function () { 'use strict';
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';

@@ -1554,3 +1554,3 @@ var parser = /*

var Compiler = /** @class */ (function () {
function Compiler(locales, formats) {
function Compiler(locales, formats, formatters) {
this.locales = [];

@@ -1567,2 +1567,3 @@ this.formats = {

this.formats = formats;
this.formatters = formatters;
}

@@ -1612,2 +1613,3 @@ Compiler.prototype.compile = function (ast) {

var format = element.format, id = element.id;
var formatters = this.formatters;
if (!format) {

@@ -1621,4 +1623,3 @@ return new StringFormat(id);

id: id,
format: new Intl.NumberFormat(locales, formats.number[format.style])
.format
format: formatters.getNumberFormat(locales, formats.number[format.style]).format
};

@@ -1628,4 +1629,3 @@ case 'dateFormat':

id: id,
format: new Intl.DateTimeFormat(locales, formats.date[format.style])
.format
format: formatters.getDateTimeFormat(locales, formats.date[format.style]).format
};

@@ -1635,7 +1635,8 @@ case 'timeFormat':

id: id,
format: new Intl.DateTimeFormat(locales, formats.time[format.style])
.format
format: formatters.getDateTimeFormat(locales, formats.time[format.style]).format
};
case 'pluralFormat':
return new PluralFormat(id, format.ordinal, format.offset, this.compileOptions(element), locales);
return new PluralFormat(id, format.offset, this.compileOptions(element), formatters.getPluralRules(locales, {
type: format.ordinal ? 'ordinal' : 'cardinal'
}));
case 'selectFormat':

@@ -1688,9 +1689,7 @@ return new SelectFormat(id, this.compileOptions(element));

var PluralFormat = /** @class */ (function () {
function PluralFormat(id, useOrdinal, offset, options, locales) {
function PluralFormat(id, offset, options, pluralRules) {
this.id = id;
this.offset = offset;
this.options = options;
this.pluralRules = new Intl.PluralRules(locales, {
type: useOrdinal ? 'ordinal' : 'cardinal'
});
this.pluralRules = pluralRules;
}

@@ -1779,3 +1778,3 @@ PluralFormat.prototype.getOption = function (value) {

catch (e) {
return MessageFormat.defaultLocale;
return IntlMessageFormat.defaultLocale;
}

@@ -1837,28 +1836,41 @@ }

}(Error));
var MessageFormat = (function (message, locales, overrideFormats) {
if (locales === void 0) { locales = MessageFormat.defaultLocale; }
// Parse string messages into an AST.
var ast = typeof message === 'string' ? MessageFormat.__parse(message) : message;
if (!(ast && ast.type === 'messageFormatPattern')) {
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.
var formats = mergeConfigs(MessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
var locale = resolveLocale(locales || []);
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
var pattern = new Compiler(locales, formats).compile(ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
function createDefaultFormatters() {
return {
format: function (values) {
getNumberFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.NumberFormat).bind.apply(_a, [void 0].concat(args)))();
},
getDateTimeFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, [void 0].concat(args)))();
},
getPluralRules: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.PluralRules).bind.apply(_a, [void 0].concat(args)))();
}
};
}
var IntlMessageFormat = /** @class */ (function () {
function IntlMessageFormat(message, locales, overrideFormats, opts) {
var _this = this;
if (locales === void 0) { locales = IntlMessageFormat.defaultLocale; }
this.format = function (values) {
try {
return formatPatterns(pattern, values);
return formatPatterns(_this.pattern, values);
}
catch (e) {
if (e.variableId) {
throw new Error("The intl string context variable '" + e.variableId + "' was not provided to the string '" + message + "'");
throw new Error("The intl string context variable '" + e.variableId + "' was not provided to the string '" + _this.message + "'");
}

@@ -1869,71 +1881,94 @@ else {

}
},
resolvedOptions: function () {
return { locale: locale };
},
getAst: function () {
return ast;
};
// Parse string messages into an AST.
this.ast =
typeof message === 'string'
? IntlMessageFormat.__parse(message)
: message;
this.message = typeof message === 'string' ? message : '';
if (!(this.ast && this.ast.type === 'messageFormatPattern')) {
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.
var formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
this.locale = resolveLocale(locales || []);
var formatters = (opts && opts.formatters) || createDefaultFormatters();
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
this.pattern = new Compiler(locales, formats, formatters).compile(this.ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
}
IntlMessageFormat.prototype.resolvedOptions = function () {
return { locale: this.locale };
};
});
MessageFormat.defaultLocale = 'en';
// 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.
MessageFormat.formats = {
number: {
currency: {
style: 'currency'
IntlMessageFormat.prototype.getAst = function () {
return this.ast;
};
IntlMessageFormat.defaultLocale = 'en';
IntlMessageFormat.__parse = parser.parse;
// 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'
}
},
percent: {
style: 'percent'
}
},
date: {
short: {
month: 'numeric',
day: 'numeric',
year: '2-digit'
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'
}
},
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'
}
}
},
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;
}());

@@ -1945,7 +1980,11 @@ /*

*/
MessageFormat.__parse = parser.parse;
IntlMessageFormat.__parse = parser.parse;
return MessageFormat;
exports.IntlMessageFormat = IntlMessageFormat;
exports.createDefaultFormatters = createDefaultFormatters;
exports.default = IntlMessageFormat;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=intl-messageformat.js.map

@@ -1,2 +0,2 @@

!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t=t||self).IntlMessageFormat=r()}(this,function(){"use strict";var t,r,e=(t=Yt,r=Error,n.prototype=r.prototype,t.prototype=new n,Yt.buildMessage=function(t,r){var e,u={literal:function(t){return'"'+o(t.text)+'"'},class:function(t){var r,e="";for(r=0;r<t.parts.length;r++)e+=t.parts[r]instanceof Array?i(t.parts[r][0])+"-"+i(t.parts[r][1]):i(t.parts[r]);return"["+(t.inverted?"^":"")+e+"]"},any:function(t){return"any character"},end:function(t){return"end of input"},other:function(t){return t.description}};function n(t){return t.charCodeAt(0).toString(16).toUpperCase()}function o(t){return t.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(t){return"\\x0"+n(t)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(t){return"\\x"+n(t)})}function i(t){return t.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(t){return"\\x0"+n(t)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(t){return"\\x"+n(t)})}return"Expected "+function(t){var r,e,n,o=new Array(t.length);for(r=0;r<t.length;r++)o[r]=(n=t[r],u[n.type](n));if(o.sort(),0<o.length){for(e=r=1;r<o.length;r++)o[r-1]!==o[r]&&(o[e]=o[r],e++);o.length=e}switch(o.length){case 1:return o[0];case 2:return o[0]+" or "+o[1];default:return o.slice(0,-1).join(", ")+", or "+o[o.length-1]}}(t)+" but "+((e=r)?'"'+o(e)+'"':"end of input")+" found."},{SyntaxError:Yt,parse:function(c,t){t=void 0!==t?t:{};var r,e,n,o,s={},u={start:Zt},i=Zt,a=function(t){return{type:"messageFormatPattern",elements:t,location:It()}},l=function(t){return t.reduce(function(t,r){return t.concat(r)},[]).join("")},f=function(t){return{type:"messageTextElement",value:t,location:It()}},p=function(t){return t.join("")},h="{",m=Mt("{",!1),d=",",g=Mt(",",!1),y="}",v=Mt("}",!1),b=function(t,r){return{type:"argumentElement",id:t,format:r&&r[2],location:It()}},A="number",w=Mt("number",!1),F="date",x=Mt("date",!1),C="time",O=Mt("time",!1),_=function(t,r){return{type:t+"Format",style:r&&r[2],location:It()}},P="plural",E=Mt("plural",!1),S=function(t){return{type:t.type,ordinal:!1,offset:t.offset||0,options:t.options,location:It()}},T="selectordinal",j=Mt("selectordinal",!1),I=function(t){return{type:t.type,ordinal:!0,offset:t.offset||0,options:t.options,location:It()}},M="select",N=Mt("select",!1),k=function(t){return{type:"selectFormat",options:t,location:It()}},R="=",L=Mt("=",!1),D=function(t,r){return{type:"optionalFormatPattern",selector:t,value:r,location:It()}},Z="offset:",U=Mt("offset:",!1),W=function(t){return t},$=function(t,r){return{type:"pluralFormat",offset:t,options:r,location:It()}},q=kt("whitespace"),z=/^[ \t\n\r]/,B=Nt([" ","\t","\n","\r"],!1,!1),G=kt("optionalWhitespace"),H=/^[0-9]/,J=Nt([["0","9"]],!1,!1),K=/^[0-9a-f]/i,Q=Nt([["0","9"],["a","f"]],!1,!0),V="0",X=Mt("0",!1),Y=/^[1-9]/,tt=Nt([["1","9"]],!1,!1),rt=function(t){return parseInt(t,10)},et="'",nt=Mt("'",!1),ot=/^[ \t\n\r,.+={}#]/,ut=Nt([" ","\t","\n","\r",",",".","+","=","{","}","#"],!1,!1),it={type:"any"},at=function(t){return t},ct=function(t){return t},st=/^[^{}\\\0-\x1F\x7F \t\n\r]/,lt=Nt(["{","}","\\",["\0",""],""," ","\t","\n","\r"],!0,!1),ft="\\\\",pt=Mt("\\\\",!1),ht=function(){return"\\"},mt="\\#",dt=Mt("\\#",!1),gt=function(){return"\\#"},yt="\\{",vt=Mt("\\{",!1),bt=function(){return"{"},At="\\}",wt=Mt("\\}",!1),Ft=function(){return"}"},xt="\\u",Ct=Mt("\\u",!1),Ot=function(t){return String.fromCharCode(parseInt(t,16))},_t=0,Pt=0,Et=[{line:1,column:1}],St=0,Tt=[],jt=0;if("startRule"in t){if(!(t.startRule in u))throw new Error("Can't start parsing from rule \""+t.startRule+'".');i=u[t.startRule]}function It(){return Lt(Pt,_t)}function Mt(t,r){return{type:"literal",text:t,ignoreCase:r}}function Nt(t,r,e){return{type:"class",parts:t,inverted:r,ignoreCase:e}}function kt(t){return{type:"other",description:t}}function Rt(t){var r,e=Et[t];if(e)return e;for(r=t-1;!Et[r];)r--;for(e={line:(e=Et[r]).line,column:e.column};r<t;)10===c.charCodeAt(r)?(e.line++,e.column=1):e.column++,r++;return Et[t]=e}function Lt(t,r){var e=Rt(t),n=Rt(r);return{start:{offset:t,line:e.line,column:e.column},end:{offset:r,line:n.line,column:n.column}}}function Dt(t){_t<St||(St<_t&&(St=_t,Tt=[]),Tt.push(t))}function Zt(){return Ut()}function Ut(){var t,r,e;for(t=_t,r=[],e=Wt();e!==s;)r.push(e),e=Wt();return r!==s&&(Pt=t,r=a(r)),t=r}function Wt(){var t;return(t=function(){var t,r;return t=_t,(r=function(){var t,r,e,n,o,u;if(r=[],e=t=_t,(e=(n=Bt())!==s?(o=Xt())!==s&&(u=Bt())!==s?n=[n,o,u]:(_t=e,s):(_t=e,s))!==s)for(;e!==s;)r.push(e),e=_t,n=Bt(),e=n!==s&&(o=Xt())!==s&&(u=Bt())!==s?n=[n,o,u]:(_t=e,s);else r=s;return r!==s&&(Pt=t,r=l(r)),(t=r)===s&&(t=_t,r=zt(),t=r!==s?c.substring(t,_t):r),t}())!==s&&(Pt=t,r=f(r)),t=r}())===s&&(t=function(){var t,r,e,n,o,u,i;return t=_t,123===c.charCodeAt(_t)?(r=h,_t++):(r=s,0===jt&&Dt(m)),t=r!==s?Bt()!==s&&(e=function(){var t,r,e;if((t=Jt())===s){for(t=_t,r=[],e=Kt();e!==s;)r.push(e),e=Kt();r!==s&&(Pt=t,r=p(r)),t=r}return t}())!==s&&Bt()!==s?(n=_t,44===c.charCodeAt(_t)?(o=d,_t++):(o=s,0===jt&&Dt(g)),(n=o!==s&&(u=Bt())!==s&&(i=function(){var t;return(t=function(){var t,r,e,n,o,u;return t=_t,c.substr(_t,6)===A?(r=A,_t+=6):(r=s,0===jt&&Dt(w)),r===s&&(c.substr(_t,4)===F?(r=F,_t+=4):(r=s,0===jt&&Dt(x)),r===s&&(c.substr(_t,4)===C?(r=C,_t+=4):(r=s,0===jt&&Dt(O)))),t=r!==s?Bt()!==s?(e=_t,44===c.charCodeAt(_t)?(n=d,_t++):(n=s,0===jt&&Dt(g)),(e=n!==s&&(o=Bt())!==s&&(u=Xt())!==s?n=[n,o,u]:(_t=e,s))===s&&(e=null),e!==s?(Pt=t,r=_(r,e)):(_t=t,s)):(_t=t,s):(_t=t,s)}())===s&&(t=function(){var t,r,e,n;return t=_t,c.substr(_t,6)===P?(r=P,_t+=6):(r=s,0===jt&&Dt(E)),t=r!==s?Bt()!==s?(44===c.charCodeAt(_t)?(e=d,_t++):(e=s,0===jt&&Dt(g)),e!==s&&Bt()!==s&&(n=qt())!==s?(Pt=t,r=S(n)):(_t=t,s)):(_t=t,s):(_t=t,s)}())===s&&(t=function(){var t,r,e,n;return t=_t,c.substr(_t,13)===T?(r=T,_t+=13):(r=s,0===jt&&Dt(j)),t=r!==s?Bt()!==s?(44===c.charCodeAt(_t)?(e=d,_t++):(e=s,0===jt&&Dt(g)),e!==s&&Bt()!==s&&(n=qt())!==s?(Pt=t,r=I(n)):(_t=t,s)):(_t=t,s):(_t=t,s)}())===s&&(t=function(){var t,r,e,n,o;if(t=_t,c.substr(_t,6)===M?(r=M,_t+=6):(r=s,0===jt&&Dt(N)),r!==s)if(Bt()!==s)if(44===c.charCodeAt(_t)?(e=d,_t++):(e=s,0===jt&&Dt(g)),e!==s)if(Bt()!==s){if(n=[],(o=$t())!==s)for(;o!==s;)n.push(o),o=$t();else n=s;t=n!==s?(Pt=t,r=k(n)):(_t=t,s)}else _t=t,t=s;else _t=t,t=s;else _t=t,t=s;else _t=t,t=s;return t}()),t}())!==s?o=[o,u,i]:(_t=n,s))===s&&(n=null),n!==s&&(o=Bt())!==s?(125===c.charCodeAt(_t)?(u=y,_t++):(u=s,0===jt&&Dt(v)),u!==s?(Pt=t,r=b(e,n)):(_t=t,s)):(_t=t,s)):(_t=t,s):(_t=t,s)}()),t}function $t(){var t,r,e,n,o;return t=_t,t=Bt()!==s&&(r=function(){var t,r,e,n;return r=t=_t,61===c.charCodeAt(_t)?(e=R,_t++):(e=s,0===jt&&Dt(L)),(t=(r=e!==s&&(n=Jt())!==s?e=[e,n]:(_t=r,s))!==s?c.substring(t,_t):r)===s&&(t=Xt()),t}())!==s&&Bt()!==s?(123===c.charCodeAt(_t)?(e=h,_t++):(e=s,0===jt&&Dt(m)),e!==s&&(n=Ut())!==s?(125===c.charCodeAt(_t)?(o=y,_t++):(o=s,0===jt&&Dt(v)),o!==s?(Pt=t,D(r,n)):(_t=t,s)):(_t=t,s)):(_t=t,s)}function qt(){var t,r,e,n;if(t=_t,(r=function(){var t,r,e;return t=_t,c.substr(_t,7)===Z?(r=Z,_t+=7):(r=s,0===jt&&Dt(U)),t=r!==s&&Bt()!==s&&(e=Jt())!==s?(Pt=t,r=W(e)):(_t=t,s)}())===s&&(r=null),r!==s)if(Bt()!==s){if(e=[],(n=$t())!==s)for(;n!==s;)e.push(n),n=$t();else e=s;t=e!==s?(Pt=t,r=$(r,e)):(_t=t,s)}else _t=t,t=s;else _t=t,t=s;return t}function zt(){var t,r;if(jt++,t=[],z.test(c.charAt(_t))?(r=c.charAt(_t),_t++):(r=s,0===jt&&Dt(B)),r!==s)for(;r!==s;)t.push(r),z.test(c.charAt(_t))?(r=c.charAt(_t),_t++):(r=s,0===jt&&Dt(B));else t=s;return jt--,t===s&&(r=s,0===jt&&Dt(q)),t}function Bt(){var t,r,e;for(jt++,t=_t,r=[],e=zt();e!==s;)r.push(e),e=zt();return t=r!==s?c.substring(t,_t):r,jt--,t===s&&(r=s,0===jt&&Dt(G)),t}function Gt(){var t;return H.test(c.charAt(_t))?(t=c.charAt(_t),_t++):(t=s,0===jt&&Dt(J)),t}function Ht(){var t;return K.test(c.charAt(_t))?(t=c.charAt(_t),_t++):(t=s,0===jt&&Dt(Q)),t}function Jt(){var t,r,e,n,o,u;if(t=_t,48===c.charCodeAt(_t)?(r=V,_t++):(r=s,0===jt&&Dt(X)),r===s){if(e=r=_t,Y.test(c.charAt(_t))?(n=c.charAt(_t),_t++):(n=s,0===jt&&Dt(tt)),n!==s){for(o=[],u=Gt();u!==s;)o.push(u),u=Gt();e=o!==s?n=[n,o]:(_t=e,s)}else _t=e,e=s;r=e!==s?c.substring(r,_t):e}return r!==s&&(Pt=t,r=rt(r)),t=r}function Kt(){var t,r,e;return r=t=_t,jt++,39===c.charCodeAt(_t)?(e=et,_t++):(e=s,0===jt&&Dt(nt)),e===s&&(ot.test(c.charAt(_t))?(e=c.charAt(_t),_t++):(e=s,0===jt&&Dt(ut))),jt--,(t=(r=e===s?void 0:(_t=r,s))!==s?(c.length>_t?(e=c.charAt(_t),_t++):(e=s,0===jt&&Dt(it)),e!==s?(Pt=t,r=at(e)):(_t=t,s)):(_t=t,s))===s&&(t=_t,39===c.charCodeAt(_t)?(r=et,_t++):(r=s,0===jt&&Dt(nt)),t=r!==s&&(e=function(){var t;return ot.test(c.charAt(_t))?(t=c.charAt(_t),_t++):(t=s,0===jt&&Dt(ut)),t===s&&(t=Qt()),t}())!==s?(Pt=t,r=ct(e)):(_t=t,s)),t}function Qt(){var t;return 39===c.charCodeAt(_t)?(t=et,_t++):(t=s,0===jt&&Dt(nt)),t}function Vt(){var t,r,e,n,o,u,i,a;return t=_t,39===c.charCodeAt(_t)?(r=et,_t++):(r=s,0===jt&&Dt(nt)),(t=r!==s&&(e=Qt())!==s?(Pt=t,r=ct(e)):(_t=t,s))===s&&(st.test(c.charAt(_t))?(t=c.charAt(_t),_t++):(t=s,0===jt&&Dt(lt)),t===s&&(t=_t,c.substr(_t,2)===ft?(r=ft,_t+=2):(r=s,0===jt&&Dt(pt)),r!==s&&(Pt=t,r=ht()),(t=r)===s&&(t=_t,c.substr(_t,2)===mt?(r=mt,_t+=2):(r=s,0===jt&&Dt(dt)),r!==s&&(Pt=t,r=gt()),(t=r)===s&&(t=_t,c.substr(_t,2)===yt?(r=yt,_t+=2):(r=s,0===jt&&Dt(vt)),r!==s&&(Pt=t,r=bt()),(t=r)===s&&(t=_t,c.substr(_t,2)===At?(r=At,_t+=2):(r=s,0===jt&&Dt(wt)),r!==s&&(Pt=t,r=Ft()),(t=r)===s&&(t=_t,c.substr(_t,2)===xt?(r=xt,_t+=2):(r=s,0===jt&&Dt(Ct)),t=r!==s?(n=e=_t,(e=(n=(o=Ht())!==s&&(u=Ht())!==s&&(i=Ht())!==s&&(a=Ht())!==s?o=[o,u,i,a]:(_t=n,s))!==s?c.substring(e,_t):n)!==s?(Pt=t,r=Ot(e)):(_t=t,s)):(_t=t,s))))))),t}function Xt(){var t,r,e;if(t=_t,r=[],(e=Vt())!==s)for(;e!==s;)r.push(e),e=Vt();else r=s;return r!==s&&(Pt=t,r=p(r)),t=r}if((r=i())!==s&&_t===c.length)return r;throw r!==s&&_t<c.length&&Dt({type:"end"}),e=Tt,n=St<c.length?c.charAt(St):null,o=St<c.length?Lt(St,St+1):Lt(St,St),new Yt(Yt.buildMessage(e,n),e,n,o)}});function Yt(t,r,e,n){this.message=t,this.expected=r,this.found=e,this.location=n,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,Yt)}function n(){this.constructor=t}var o,u=(o=function(t,r){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(t,r)},function(t,r){function e(){this.constructor=t}o(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}),a=(i.prototype.compile=function(t){return this.pluralStack=[],this.currentPlural=null,this.pluralNumberFormat=null,this.compileMessage(t)},i.prototype.compileMessage=function(t){var r=this;if(!t||"messageFormatPattern"!==t.type)throw new Error('Message AST is not of type: "messageFormatPattern"');var e=t.elements,n=e.filter(function(t){return"messageTextElement"===t.type||"argumentElement"===t.type}).map(function(t){return"messageTextElement"===t.type?r.compileMessageText(t):r.compileArgument(t)});if(n.length!==e.length)throw new Error("Message element does not have a valid type");return n},i.prototype.compileMessageText=function(t){return this.currentPlural&&/(^|[^\\])#/g.test(t.value)?(this.pluralNumberFormat||(this.pluralNumberFormat=new Intl.NumberFormat(this.locales)),new d(this.currentPlural.id,this.currentPlural.format.offset,this.pluralNumberFormat,t.value)):t.value.replace(/\\#/g,"#")},i.prototype.compileArgument=function(t){var r=t.format,e=t.id;if(!r)return new l(e);var n=this.formats,o=this.locales;switch(r.type){case"numberFormat":return{id:e,format:new Intl.NumberFormat(o,n.number[r.style]).format};case"dateFormat":return{id:e,format:new Intl.DateTimeFormat(o,n.date[r.style]).format};case"timeFormat":return{id:e,format:new Intl.DateTimeFormat(o,n.time[r.style]).format};case"pluralFormat":return new p(e,r.ordinal,r.offset,this.compileOptions(t),o);case"selectFormat":return new y(e,this.compileOptions(t));default:throw new Error("Message element does not have a valid format type")}},i.prototype.compileOptions=function(t){var e=this,r=t.format,n=r.options;this.pluralStack.push(this.currentPlural),this.currentPlural="pluralFormat"===r.type?t:null;var o=n.reduce(function(t,r){return t[r.selector]=e.compileMessage(r.value),t},{});return this.currentPlural=this.pluralStack.pop(),o},i);function i(t,r){this.locales=[],this.formats={number:{},date:{},time:{}},this.pluralNumberFormat=null,this.currentPlural=null,this.pluralStack=[],this.locales=t,this.formats=r}function c(t){this.id=t}var s,l=(u(f,s=c),f.prototype.format=function(t){return t||"number"==typeof t?"string"==typeof t?t:String(t):""},f);function f(){return null!==s&&s.apply(this,arguments)||this}var p=(h.prototype.getOption=function(t){var r=this.options;return r["="+t]||r[this.pluralRules.select(t-this.offset)]||r.other},h);function h(t,r,e,n,o){this.id=t,this.offset=e,this.options=n,this.pluralRules=new Intl.PluralRules(o,{type:r?"ordinal":"cardinal"})}var m,d=(u(g,m=c),g.prototype.format=function(t){var r=this.numberFormat.format(t-this.offset);return this.string.replace(/(^|[^\\])#/g,"$1"+r).replace(/\\#/g,"#")},g);function g(t,r,e,n){var o=m.call(this,t)||this;return o.offset=r,o.numberFormat=e,o.string=n,o}var y=(v.prototype.getOption=function(t){var r=this.options;return r[t]||r.other},v);function v(t,r){this.id=t,this.options=r}var b,A=(b=function(t,r){return(b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(t,r)},function(t,r){function e(){this.constructor=t}b(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}),w=function(){return(w=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)};function F(e,n){return n?Object.keys(e).reduce(function(t,r){return t[r]=function(e,n){return n?w({},e||{},n||{},Object.keys(e).reduce(function(t,r){return t[r]=w({},e[r],n[r]||{}),t},{})):e}(e[r],n[r]),t},w({},e)):e}var x,C=(x=Error,A(O,x),O);function O(t,r){var e=x.call(this,t)||this;return e.variableId=r,e}var _=function(r,t,e){void 0===t&&(t=_.defaultLocale);var n="string"==typeof r?_.__parse(r):r;if(!n||"messageFormatPattern"!==n.type)throw new TypeError("A message must be provided as a String or AST.");var o=F(_.formats,e),u=function(t){"string"==typeof t&&(t=[t]);try{return Intl.NumberFormat.supportedLocalesOf(t,{localeMatcher:"best fit"})[0]}catch(t){return _.defaultLocale}}(t||[]),i=new a(t,o).compile(n);return{format:function(t){try{return function t(r,e){for(var n="",o=0,u=r;o<u.length;o++){var i=u[o];if("string"!=typeof i){var a=i.id;if(!(e&&a in e))throw new C("A value must be provided for: "+a,a);var c=e[a];i.options?n+=t(i.getOption(c),e):n+=i.format(c)}else n+=i}return n}(i,t)}catch(t){throw t.variableId?new Error("The intl string context variable '"+t.variableId+"' was not provided to the string '"+r+"'"):t}},resolvedOptions:function(){return{locale:u}},getAst:function(){return n}}};return _.defaultLocale="en",_.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"}}},_.__parse=e.parse,_});
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t=t||self).IntlMessageFormat={})}(this,function(t){"use strict";var r,e,n=(r=Yt,e=Error,o.prototype=e.prototype,r.prototype=new o,Yt.buildMessage=function(t,r){var e,u={literal:function(t){return'"'+o(t.text)+'"'},class:function(t){var r,e="";for(r=0;r<t.parts.length;r++)e+=t.parts[r]instanceof Array?a(t.parts[r][0])+"-"+a(t.parts[r][1]):a(t.parts[r]);return"["+(t.inverted?"^":"")+e+"]"},any:function(t){return"any character"},end:function(t){return"end of input"},other:function(t){return t.description}};function n(t){return t.charCodeAt(0).toString(16).toUpperCase()}function o(t){return t.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(t){return"\\x0"+n(t)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(t){return"\\x"+n(t)})}function a(t){return t.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(t){return"\\x0"+n(t)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(t){return"\\x"+n(t)})}return"Expected "+function(t){var r,e,n,o=new Array(t.length);for(r=0;r<t.length;r++)o[r]=(n=t[r],u[n.type](n));if(o.sort(),0<o.length){for(e=r=1;r<o.length;r++)o[r-1]!==o[r]&&(o[e]=o[r],e++);o.length=e}switch(o.length){case 1:return o[0];case 2:return o[0]+" or "+o[1];default:return o.slice(0,-1).join(", ")+", or "+o[o.length-1]}}(t)+" but "+((e=r)?'"'+o(e)+'"':"end of input")+" found."},{SyntaxError:Yt,parse:function(s,t){t=void 0!==t?t:{};var r,e,n,o,c={},u={start:Zt},a=Zt,i=function(t){return{type:"messageFormatPattern",elements:t,location:jt()}},l=function(t){return t.reduce(function(t,r){return t.concat(r)},[]).join("")},f=function(t){return{type:"messageTextElement",value:t,location:jt()}},p=function(t){return t.join("")},h="{",m=It("{",!1),d=",",g=It(",",!1),y="}",v=It("}",!1),b=function(t,r){return{type:"argumentElement",id:t,format:r&&r[2],location:jt()}},A="number",F=It("number",!1),w="date",x=It("date",!1),_="time",C=It("time",!1),O=function(t,r){return{type:t+"Format",style:r&&r[2],location:jt()}},P="plural",E=It("plural",!1),T=function(t){return{type:t.type,ordinal:!1,offset:t.offset||0,options:t.options,location:jt()}},M="selectordinal",S=It("selectordinal",!1),j=function(t){return{type:t.type,ordinal:!0,offset:t.offset||0,options:t.options,location:jt()}},I="select",N=It("select",!1),k=function(t){return{type:"selectFormat",options:t,location:jt()}},R="=",D=It("=",!1),L=function(t,r){return{type:"optionalFormatPattern",selector:t,value:r,location:jt()}},Z="offset:",U=It("offset:",!1),W=function(t){return t},$=function(t,r){return{type:"pluralFormat",offset:t,options:r,location:jt()}},q=kt("whitespace"),z=/^[ \t\n\r]/,B=Nt([" ","\t","\n","\r"],!1,!1),G=kt("optionalWhitespace"),H=/^[0-9]/,J=Nt([["0","9"]],!1,!1),K=/^[0-9a-f]/i,Q=Nt([["0","9"],["a","f"]],!1,!0),V="0",X=It("0",!1),Y=/^[1-9]/,tt=Nt([["1","9"]],!1,!1),rt=function(t){return parseInt(t,10)},et="'",nt=It("'",!1),ot=/^[ \t\n\r,.+={}#]/,ut=Nt([" ","\t","\n","\r",",",".","+","=","{","}","#"],!1,!1),at={type:"any"},it=function(t){return t},st=function(t){return t},ct=/^[^{}\\\0-\x1F\x7F \t\n\r]/,lt=Nt(["{","}","\\",["\0",""],""," ","\t","\n","\r"],!0,!1),ft="\\\\",pt=It("\\\\",!1),ht=function(){return"\\"},mt="\\#",dt=It("\\#",!1),gt=function(){return"\\#"},yt="\\{",vt=It("\\{",!1),bt=function(){return"{"},At="\\}",Ft=It("\\}",!1),wt=function(){return"}"},xt="\\u",_t=It("\\u",!1),Ct=function(t){return String.fromCharCode(parseInt(t,16))},Ot=0,Pt=0,Et=[{line:1,column:1}],Tt=0,Mt=[],St=0;if("startRule"in t){if(!(t.startRule in u))throw new Error("Can't start parsing from rule \""+t.startRule+'".');a=u[t.startRule]}function jt(){return Dt(Pt,Ot)}function It(t,r){return{type:"literal",text:t,ignoreCase:r}}function Nt(t,r,e){return{type:"class",parts:t,inverted:r,ignoreCase:e}}function kt(t){return{type:"other",description:t}}function Rt(t){var r,e=Et[t];if(e)return e;for(r=t-1;!Et[r];)r--;for(e={line:(e=Et[r]).line,column:e.column};r<t;)10===s.charCodeAt(r)?(e.line++,e.column=1):e.column++,r++;return Et[t]=e}function Dt(t,r){var e=Rt(t),n=Rt(r);return{start:{offset:t,line:e.line,column:e.column},end:{offset:r,line:n.line,column:n.column}}}function Lt(t){Ot<Tt||(Tt<Ot&&(Tt=Ot,Mt=[]),Mt.push(t))}function Zt(){return Ut()}function Ut(){var t,r,e;for(t=Ot,r=[],e=Wt();e!==c;)r.push(e),e=Wt();return r!==c&&(Pt=t,r=i(r)),t=r}function Wt(){var t;return(t=function(){var t,r;return t=Ot,(r=function(){var t,r,e,n,o,u;if(r=[],e=t=Ot,(e=(n=Bt())!==c?(o=Xt())!==c&&(u=Bt())!==c?n=[n,o,u]:(Ot=e,c):(Ot=e,c))!==c)for(;e!==c;)r.push(e),e=Ot,n=Bt(),e=n!==c&&(o=Xt())!==c&&(u=Bt())!==c?n=[n,o,u]:(Ot=e,c);else r=c;return r!==c&&(Pt=t,r=l(r)),(t=r)===c&&(t=Ot,r=zt(),t=r!==c?s.substring(t,Ot):r),t}())!==c&&(Pt=t,r=f(r)),t=r}())===c&&(t=function(){var t,r,e,n,o,u,a;return t=Ot,123===s.charCodeAt(Ot)?(r=h,Ot++):(r=c,0===St&&Lt(m)),t=r!==c?Bt()!==c&&(e=function(){var t,r,e;if((t=Jt())===c){for(t=Ot,r=[],e=Kt();e!==c;)r.push(e),e=Kt();r!==c&&(Pt=t,r=p(r)),t=r}return t}())!==c&&Bt()!==c?(n=Ot,44===s.charCodeAt(Ot)?(o=d,Ot++):(o=c,0===St&&Lt(g)),(n=o!==c&&(u=Bt())!==c&&(a=function(){var t;return(t=function(){var t,r,e,n,o,u;return t=Ot,s.substr(Ot,6)===A?(r=A,Ot+=6):(r=c,0===St&&Lt(F)),r===c&&(s.substr(Ot,4)===w?(r=w,Ot+=4):(r=c,0===St&&Lt(x)),r===c&&(s.substr(Ot,4)===_?(r=_,Ot+=4):(r=c,0===St&&Lt(C)))),t=r!==c?Bt()!==c?(e=Ot,44===s.charCodeAt(Ot)?(n=d,Ot++):(n=c,0===St&&Lt(g)),(e=n!==c&&(o=Bt())!==c&&(u=Xt())!==c?n=[n,o,u]:(Ot=e,c))===c&&(e=null),e!==c?(Pt=t,r=O(r,e)):(Ot=t,c)):(Ot=t,c):(Ot=t,c)}())===c&&(t=function(){var t,r,e,n;return t=Ot,s.substr(Ot,6)===P?(r=P,Ot+=6):(r=c,0===St&&Lt(E)),t=r!==c?Bt()!==c?(44===s.charCodeAt(Ot)?(e=d,Ot++):(e=c,0===St&&Lt(g)),e!==c&&Bt()!==c&&(n=qt())!==c?(Pt=t,r=T(n)):(Ot=t,c)):(Ot=t,c):(Ot=t,c)}())===c&&(t=function(){var t,r,e,n;return t=Ot,s.substr(Ot,13)===M?(r=M,Ot+=13):(r=c,0===St&&Lt(S)),t=r!==c?Bt()!==c?(44===s.charCodeAt(Ot)?(e=d,Ot++):(e=c,0===St&&Lt(g)),e!==c&&Bt()!==c&&(n=qt())!==c?(Pt=t,r=j(n)):(Ot=t,c)):(Ot=t,c):(Ot=t,c)}())===c&&(t=function(){var t,r,e,n,o;if(t=Ot,s.substr(Ot,6)===I?(r=I,Ot+=6):(r=c,0===St&&Lt(N)),r!==c)if(Bt()!==c)if(44===s.charCodeAt(Ot)?(e=d,Ot++):(e=c,0===St&&Lt(g)),e!==c)if(Bt()!==c){if(n=[],(o=$t())!==c)for(;o!==c;)n.push(o),o=$t();else n=c;t=n!==c?(Pt=t,r=k(n)):(Ot=t,c)}else Ot=t,t=c;else Ot=t,t=c;else Ot=t,t=c;else Ot=t,t=c;return t}()),t}())!==c?o=[o,u,a]:(Ot=n,c))===c&&(n=null),n!==c&&(o=Bt())!==c?(125===s.charCodeAt(Ot)?(u=y,Ot++):(u=c,0===St&&Lt(v)),u!==c?(Pt=t,r=b(e,n)):(Ot=t,c)):(Ot=t,c)):(Ot=t,c):(Ot=t,c)}()),t}function $t(){var t,r,e,n,o;return t=Ot,t=Bt()!==c&&(r=function(){var t,r,e,n;return r=t=Ot,61===s.charCodeAt(Ot)?(e=R,Ot++):(e=c,0===St&&Lt(D)),(t=(r=e!==c&&(n=Jt())!==c?e=[e,n]:(Ot=r,c))!==c?s.substring(t,Ot):r)===c&&(t=Xt()),t}())!==c&&Bt()!==c?(123===s.charCodeAt(Ot)?(e=h,Ot++):(e=c,0===St&&Lt(m)),e!==c&&(n=Ut())!==c?(125===s.charCodeAt(Ot)?(o=y,Ot++):(o=c,0===St&&Lt(v)),o!==c?(Pt=t,L(r,n)):(Ot=t,c)):(Ot=t,c)):(Ot=t,c)}function qt(){var t,r,e,n;if(t=Ot,(r=function(){var t,r,e;return t=Ot,s.substr(Ot,7)===Z?(r=Z,Ot+=7):(r=c,0===St&&Lt(U)),t=r!==c&&Bt()!==c&&(e=Jt())!==c?(Pt=t,r=W(e)):(Ot=t,c)}())===c&&(r=null),r!==c)if(Bt()!==c){if(e=[],(n=$t())!==c)for(;n!==c;)e.push(n),n=$t();else e=c;t=e!==c?(Pt=t,r=$(r,e)):(Ot=t,c)}else Ot=t,t=c;else Ot=t,t=c;return t}function zt(){var t,r;if(St++,t=[],z.test(s.charAt(Ot))?(r=s.charAt(Ot),Ot++):(r=c,0===St&&Lt(B)),r!==c)for(;r!==c;)t.push(r),z.test(s.charAt(Ot))?(r=s.charAt(Ot),Ot++):(r=c,0===St&&Lt(B));else t=c;return St--,t===c&&(r=c,0===St&&Lt(q)),t}function Bt(){var t,r,e;for(St++,t=Ot,r=[],e=zt();e!==c;)r.push(e),e=zt();return t=r!==c?s.substring(t,Ot):r,St--,t===c&&(r=c,0===St&&Lt(G)),t}function Gt(){var t;return H.test(s.charAt(Ot))?(t=s.charAt(Ot),Ot++):(t=c,0===St&&Lt(J)),t}function Ht(){var t;return K.test(s.charAt(Ot))?(t=s.charAt(Ot),Ot++):(t=c,0===St&&Lt(Q)),t}function Jt(){var t,r,e,n,o,u;if(t=Ot,48===s.charCodeAt(Ot)?(r=V,Ot++):(r=c,0===St&&Lt(X)),r===c){if(e=r=Ot,Y.test(s.charAt(Ot))?(n=s.charAt(Ot),Ot++):(n=c,0===St&&Lt(tt)),n!==c){for(o=[],u=Gt();u!==c;)o.push(u),u=Gt();e=o!==c?n=[n,o]:(Ot=e,c)}else Ot=e,e=c;r=e!==c?s.substring(r,Ot):e}return r!==c&&(Pt=t,r=rt(r)),t=r}function Kt(){var t,r,e;return r=t=Ot,St++,39===s.charCodeAt(Ot)?(e=et,Ot++):(e=c,0===St&&Lt(nt)),e===c&&(ot.test(s.charAt(Ot))?(e=s.charAt(Ot),Ot++):(e=c,0===St&&Lt(ut))),St--,(t=(r=e===c?void 0:(Ot=r,c))!==c?(s.length>Ot?(e=s.charAt(Ot),Ot++):(e=c,0===St&&Lt(at)),e!==c?(Pt=t,r=it(e)):(Ot=t,c)):(Ot=t,c))===c&&(t=Ot,39===s.charCodeAt(Ot)?(r=et,Ot++):(r=c,0===St&&Lt(nt)),t=r!==c&&(e=function(){var t;return ot.test(s.charAt(Ot))?(t=s.charAt(Ot),Ot++):(t=c,0===St&&Lt(ut)),t===c&&(t=Qt()),t}())!==c?(Pt=t,r=st(e)):(Ot=t,c)),t}function Qt(){var t;return 39===s.charCodeAt(Ot)?(t=et,Ot++):(t=c,0===St&&Lt(nt)),t}function Vt(){var t,r,e,n,o,u,a,i;return t=Ot,39===s.charCodeAt(Ot)?(r=et,Ot++):(r=c,0===St&&Lt(nt)),(t=r!==c&&(e=Qt())!==c?(Pt=t,r=st(e)):(Ot=t,c))===c&&(ct.test(s.charAt(Ot))?(t=s.charAt(Ot),Ot++):(t=c,0===St&&Lt(lt)),t===c&&(t=Ot,s.substr(Ot,2)===ft?(r=ft,Ot+=2):(r=c,0===St&&Lt(pt)),r!==c&&(Pt=t,r=ht()),(t=r)===c&&(t=Ot,s.substr(Ot,2)===mt?(r=mt,Ot+=2):(r=c,0===St&&Lt(dt)),r!==c&&(Pt=t,r=gt()),(t=r)===c&&(t=Ot,s.substr(Ot,2)===yt?(r=yt,Ot+=2):(r=c,0===St&&Lt(vt)),r!==c&&(Pt=t,r=bt()),(t=r)===c&&(t=Ot,s.substr(Ot,2)===At?(r=At,Ot+=2):(r=c,0===St&&Lt(Ft)),r!==c&&(Pt=t,r=wt()),(t=r)===c&&(t=Ot,s.substr(Ot,2)===xt?(r=xt,Ot+=2):(r=c,0===St&&Lt(_t)),t=r!==c?(n=e=Ot,(e=(n=(o=Ht())!==c&&(u=Ht())!==c&&(a=Ht())!==c&&(i=Ht())!==c?o=[o,u,a,i]:(Ot=n,c))!==c?s.substring(e,Ot):n)!==c?(Pt=t,r=Ct(e)):(Ot=t,c)):(Ot=t,c))))))),t}function Xt(){var t,r,e;if(t=Ot,r=[],(e=Vt())!==c)for(;e!==c;)r.push(e),e=Vt();else r=c;return r!==c&&(Pt=t,r=p(r)),t=r}if((r=a())!==c&&Ot===s.length)return r;throw r!==c&&Ot<s.length&&Lt({type:"end"}),e=Mt,n=Tt<s.length?s.charAt(Tt):null,o=Tt<s.length?Dt(Tt,Tt+1):Dt(Tt,Tt),new Yt(Yt.buildMessage(e,n),e,n,o)}});function Yt(t,r,e,n){this.message=t,this.expected=r,this.found=e,this.location=n,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,Yt)}function o(){this.constructor=r}var u,a=(u=function(t,r){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(t,r)},function(t,r){function e(){this.constructor=t}u(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}),i=(s.prototype.compile=function(t){return this.pluralStack=[],this.currentPlural=null,this.pluralNumberFormat=null,this.compileMessage(t)},s.prototype.compileMessage=function(t){var r=this;if(!t||"messageFormatPattern"!==t.type)throw new Error('Message AST is not of type: "messageFormatPattern"');var e=t.elements,n=e.filter(function(t){return"messageTextElement"===t.type||"argumentElement"===t.type}).map(function(t){return"messageTextElement"===t.type?r.compileMessageText(t):r.compileArgument(t)});if(n.length!==e.length)throw new Error("Message element does not have a valid type");return n},s.prototype.compileMessageText=function(t){return this.currentPlural&&/(^|[^\\])#/g.test(t.value)?(this.pluralNumberFormat||(this.pluralNumberFormat=new Intl.NumberFormat(this.locales)),new g(this.currentPlural.id,this.currentPlural.format.offset,this.pluralNumberFormat,t.value)):t.value.replace(/\\#/g,"#")},s.prototype.compileArgument=function(t){var r=t.format,e=t.id,n=this.formatters;if(!r)return new f(e);var o=this.formats,u=this.locales;switch(r.type){case"numberFormat":return{id:e,format:n.getNumberFormat(u,o.number[r.style]).format};case"dateFormat":return{id:e,format:n.getDateTimeFormat(u,o.date[r.style]).format};case"timeFormat":return{id:e,format:n.getDateTimeFormat(u,o.time[r.style]).format};case"pluralFormat":return new h(e,r.offset,this.compileOptions(t),n.getPluralRules(u,{type:r.ordinal?"ordinal":"cardinal"}));case"selectFormat":return new v(e,this.compileOptions(t));default:throw new Error("Message element does not have a valid format type")}},s.prototype.compileOptions=function(t){var e=this,r=t.format,n=r.options;this.pluralStack.push(this.currentPlural),this.currentPlural="pluralFormat"===r.type?t:null;var o=n.reduce(function(t,r){return t[r.selector]=e.compileMessage(r.value),t},{});return this.currentPlural=this.pluralStack.pop(),o},s);function s(t,r,e){this.locales=[],this.formats={number:{},date:{},time:{}},this.pluralNumberFormat=null,this.currentPlural=null,this.pluralStack=[],this.locales=t,this.formats=r,this.formatters=e}function c(t){this.id=t}var l,f=(a(p,l=c),p.prototype.format=function(t){return t||"number"==typeof t?"string"==typeof t?t:String(t):""},p);function p(){return null!==l&&l.apply(this,arguments)||this}var h=(m.prototype.getOption=function(t){var r=this.options;return r["="+t]||r[this.pluralRules.select(t-this.offset)]||r.other},m);function m(t,r,e,n){this.id=t,this.offset=r,this.options=e,this.pluralRules=n}var d,g=(a(y,d=c),y.prototype.format=function(t){var r=this.numberFormat.format(t-this.offset);return this.string.replace(/(^|[^\\])#/g,"$1"+r).replace(/\\#/g,"#")},y);function y(t,r,e,n){var o=d.call(this,t)||this;return o.offset=r,o.numberFormat=e,o.string=n,o}var v=(b.prototype.getOption=function(t){var r=this.options;return r[t]||r.other},b);function b(t,r){this.id=t,this.options=r}var A,F=(A=function(t,r){return(A=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(t,r)},function(t,r){function e(){this.constructor=t}A(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}),w=function(){return(w=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)};function x(e,n){return n?Object.keys(e).reduce(function(t,r){return t[r]=function(e,n){return n?w({},e||{},n||{},Object.keys(e).reduce(function(t,r){return t[r]=w({},e[r],n[r]||{}),t},{})):e}(e[r],n[r]),t},w({},e)):e}var _,C=(_=Error,F(O,_),O);function O(t,r){var e=_.call(this,t)||this;return e.variableId=r,e}function P(){return{getNumberFormat:function(){for(var t,r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return new((t=Intl.NumberFormat).bind.apply(t,[void 0].concat(r)))},getDateTimeFormat:function(){for(var t,r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return new((t=Intl.DateTimeFormat).bind.apply(t,[void 0].concat(r)))},getPluralRules:function(){for(var t,r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return new((t=Intl.PluralRules).bind.apply(t,[void 0].concat(r)))}}}var E=(T.prototype.resolvedOptions=function(){return{locale:this.locale}},T.prototype.getAst=function(){return this.ast},T.defaultLocale="en",T.__parse=n.parse,T.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"}}},T);function T(t,r,e,n){var o=this;if(void 0===r&&(r=T.defaultLocale),this.format=function(t){try{return function t(r,e){for(var n="",o=0,u=r;o<u.length;o++){var a=u[o];if("string"!=typeof a){var i=a.id;if(!(e&&i in e))throw new C("A value must be provided for: "+i,i);var s=e[i];a.options?n+=t(a.getOption(s),e):n+=a.format(s)}else n+=a}return n}(o.pattern,t)}catch(t){throw t.variableId?new Error("The intl string context variable '"+t.variableId+"' was not provided to the string '"+o.message+"'"):t}},this.ast="string"==typeof t?T.__parse(t):t,this.message="string"==typeof t?t:"",!this.ast||"messageFormatPattern"!==this.ast.type)throw new TypeError("A message must be provided as a String or AST.");var u=x(T.formats,e);this.locale=function(t){"string"==typeof t&&(t=[t]);try{return Intl.NumberFormat.supportedLocalesOf(t,{localeMatcher:"best fit"})[0]}catch(t){return E.defaultLocale}}(r||[]);var a=n&&n.formatters||P();this.pattern=new i(r,u,a).compile(this.ast)}E.__parse=n.parse,t.IntlMessageFormat=E,t.createDefaultFormatters=P,t.default=E,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=intl-messageformat.min.js.map

@@ -7,2 +7,7 @@ import { MessageFormatPattern, MessageTextElement, ArgumentElement } from 'intl-messageformat-parser';

}
export interface Formatters {
getNumberFormat(...args: ConstructorParameters<typeof Intl.NumberFormat>): Intl.NumberFormat;
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
}
export declare type Pattern = string | PluralOffsetString | PluralFormat | SelectFormat | StringFormat;

@@ -15,3 +20,4 @@ export default class Compiler {

private pluralStack;
constructor(locales: string | string[], formats: Formats);
private formatters;
constructor(locales: string | string[], formats: Formats, formatters: Formatters);
compile(ast: MessageFormatPattern): Pattern[];

@@ -28,6 +34,6 @@ compileMessage(ast: MessageFormatPattern): Pattern[];

}
export declare class StringFormat extends Formatter {
declare class StringFormat extends Formatter {
format(value: number | string): string;
}
export declare class PluralFormat {
declare class PluralFormat {
id: string;

@@ -37,3 +43,3 @@ private offset;

private pluralRules;
constructor(id: string, useOrdinal: boolean, offset: number, options: Record<string, Pattern[]>, locales: string | string[]);
constructor(id: string, offset: number, options: Record<string, Pattern[]>, pluralRules: Intl.PluralRules);
getOption(value: number): Pattern[];

@@ -40,0 +46,0 @@ }

@@ -20,3 +20,3 @@ /*

var Compiler = /** @class */ (function () {
function Compiler(locales, formats) {
function Compiler(locales, formats, formatters) {
this.locales = [];

@@ -33,2 +33,3 @@ this.formats = {

this.formats = formats;
this.formatters = formatters;
}

@@ -78,2 +79,3 @@ Compiler.prototype.compile = function (ast) {

var format = element.format, id = element.id;
var formatters = this.formatters;
if (!format) {

@@ -87,4 +89,3 @@ return new StringFormat(id);

id: id,
format: new Intl.NumberFormat(locales, formats.number[format.style])
.format
format: formatters.getNumberFormat(locales, formats.number[format.style]).format
};

@@ -94,4 +95,3 @@ case 'dateFormat':

id: id,
format: new Intl.DateTimeFormat(locales, formats.date[format.style])
.format
format: formatters.getDateTimeFormat(locales, formats.date[format.style]).format
};

@@ -101,7 +101,8 @@ case 'timeFormat':

id: id,
format: new Intl.DateTimeFormat(locales, formats.time[format.style])
.format
format: formatters.getDateTimeFormat(locales, formats.time[format.style]).format
};
case 'pluralFormat':
return new PluralFormat(id, format.ordinal, format.offset, this.compileOptions(element), locales);
return new PluralFormat(id, format.offset, this.compileOptions(element), formatters.getPluralRules(locales, {
type: format.ordinal ? 'ordinal' : 'cardinal'
}));
case 'selectFormat':

@@ -154,11 +155,8 @@ return new SelectFormat(id, this.compileOptions(element));

}(Formatter));
export { StringFormat };
var PluralFormat = /** @class */ (function () {
function PluralFormat(id, useOrdinal, offset, options, locales) {
function PluralFormat(id, offset, options, pluralRules) {
this.id = id;
this.offset = offset;
this.options = options;
this.pluralRules = new Intl.PluralRules(locales, {
type: useOrdinal ? 'ordinal' : 'cardinal'
});
this.pluralRules = pluralRules;
}

@@ -173,3 +171,2 @@ PluralFormat.prototype.getOption = function (value) {

}());
export { PluralFormat };
var PluralOffsetString = /** @class */ (function (_super) {

@@ -176,0 +173,0 @@ __extends(PluralOffsetString, _super);

@@ -1,17 +0,78 @@

import { Formats } from './compiler';
import parser, { MessageFormatPattern } from 'intl-messageformat-parser';
export interface IntlMessageFormat {
new (message: string | MessageFormatPattern, locales?: string | string[], overrideFormats?: Partial<Formats>): IntlMessageFormat;
(message: string | MessageFormatPattern, locales?: string | string[], overrideFormats?: Partial<Formats>): IntlMessageFormat;
format(values?: Record<string, string | number | boolean | null | undefined>): string;
import { Formats, Formatters } from './compiler';
import { MessageFormatPattern } from 'intl-messageformat-parser';
export interface Options {
formatters?: Formatters;
}
export declare function createDefaultFormatters(): Formatters;
export declare class IntlMessageFormat {
private ast;
private locale;
private pattern;
private message;
constructor(message: string | MessageFormatPattern, locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
format: (values?: Record<string, string | number | boolean | null | undefined> | undefined) => string;
resolvedOptions(): {
locale: string;
};
getAst(): ReturnType<typeof parser['parse']>;
defaultLocale: string;
formats: Formats;
__parse: typeof parser['parse'];
getAst(): MessageFormatPattern;
static defaultLocale: string;
static __parse: (msg: string) => MessageFormatPattern;
static formats: {
number: {
currency: {
style: string;
};
percent: {
style: string;
};
};
date: {
short: {
month: string;
day: string;
year: string;
};
medium: {
month: string;
day: string;
year: string;
};
long: {
month: string;
day: string;
year: string;
};
full: {
weekday: string;
month: string;
day: string;
year: string;
};
};
time: {
short: {
hour: string;
minute: string;
};
medium: {
hour: string;
minute: string;
second: string;
};
long: {
hour: string;
minute: string;
second: string;
timeZoneName: string;
};
full: {
hour: string;
minute: string;
second: string;
timeZoneName: string;
};
};
};
}
export declare const MessageFormat: IntlMessageFormat;
export { Formats, Pattern } from './compiler';
export default MessageFormat;
export default IntlMessageFormat;

@@ -32,2 +32,3 @@ /*

import Compiler, { isSelectOrPluralFormat } from './compiler';
import parser from 'intl-messageformat-parser';
// -- MessageFormat --------------------------------------------------------

@@ -46,3 +47,3 @@ function resolveLocale(locales) {

catch (e) {
return MessageFormat.defaultLocale;
return IntlMessageFormat.defaultLocale;
}

@@ -104,28 +105,41 @@ }

}(Error));
export var MessageFormat = (function (message, locales, overrideFormats) {
if (locales === void 0) { locales = MessageFormat.defaultLocale; }
// Parse string messages into an AST.
var ast = typeof message === 'string' ? MessageFormat.__parse(message) : message;
if (!(ast && ast.type === 'messageFormatPattern')) {
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.
var formats = mergeConfigs(MessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
var locale = resolveLocale(locales || []);
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
var pattern = new Compiler(locales, formats).compile(ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
export function createDefaultFormatters() {
return {
format: function (values) {
getNumberFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.NumberFormat).bind.apply(_a, [void 0].concat(args)))();
},
getDateTimeFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, [void 0].concat(args)))();
},
getPluralRules: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.PluralRules).bind.apply(_a, [void 0].concat(args)))();
}
};
}
var IntlMessageFormat = /** @class */ (function () {
function IntlMessageFormat(message, locales, overrideFormats, opts) {
var _this = this;
if (locales === void 0) { locales = IntlMessageFormat.defaultLocale; }
this.format = function (values) {
try {
return formatPatterns(pattern, values);
return formatPatterns(_this.pattern, values);
}
catch (e) {
if (e.variableId) {
throw new Error("The intl string context variable '" + e.variableId + "' was not provided to the string '" + message + "'");
throw new Error("The intl string context variable '" + e.variableId + "' was not provided to the string '" + _this.message + "'");
}

@@ -136,72 +150,96 @@ else {

}
},
resolvedOptions: function () {
return { locale: locale };
},
getAst: function () {
return ast;
};
// Parse string messages into an AST.
this.ast =
typeof message === 'string'
? IntlMessageFormat.__parse(message)
: message;
this.message = typeof message === 'string' ? message : '';
if (!(this.ast && this.ast.type === 'messageFormatPattern')) {
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.
var formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
this.locale = resolveLocale(locales || []);
var formatters = (opts && opts.formatters) || createDefaultFormatters();
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
this.pattern = new Compiler(locales, formats, formatters).compile(this.ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
}
IntlMessageFormat.prototype.resolvedOptions = function () {
return { locale: this.locale };
};
});
MessageFormat.defaultLocale = 'en';
// 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.
MessageFormat.formats = {
number: {
currency: {
style: 'currency'
IntlMessageFormat.prototype.getAst = function () {
return this.ast;
};
IntlMessageFormat.defaultLocale = 'en';
IntlMessageFormat.__parse = parser.parse;
// 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'
}
},
percent: {
style: 'percent'
}
},
date: {
short: {
month: 'numeric',
day: 'numeric',
year: '2-digit'
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'
}
},
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'
}
}
},
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'
}
}
};
export default MessageFormat;
};
return IntlMessageFormat;
}());
export { IntlMessageFormat };
export default IntlMessageFormat;
//# sourceMappingURL=core.js.map

@@ -1,3 +0,5 @@

import MessageFormat from './core';
import IntlMessageFormat from './core';
export { Formats, Pattern } from './compiler';
export default MessageFormat;
export * from './core';
export { Formatters } from './compiler';
export default IntlMessageFormat;

@@ -7,5 +7,6 @@ /*

import parser from 'intl-messageformat-parser';
import MessageFormat from './core';
MessageFormat.__parse = parser.parse;
export default MessageFormat;
import IntlMessageFormat from './core';
IntlMessageFormat.__parse = parser.parse;
export * from './core';
export default IntlMessageFormat;
//# sourceMappingURL=index.js.map
{
"name": "intl-messageformat",
"version": "4.2.1",
"version": "4.3.0",
"description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",

@@ -34,3 +34,3 @@ "keywords": [

"dependencies": {
"intl-messageformat-parser": "^1.7.1"
"intl-messageformat-parser": "^1.8.0"
},

@@ -50,3 +50,3 @@ "scripts": {

"license": "BSD-3-Clause",
"gitHead": "8b0baec8eda5002715cf893274fe59782fc2d371"
"gitHead": "bce3e9726f9d98613deca5761ffce481d824a885"
}

@@ -26,3 +26,3 @@ # Intl MessageFormat

```js
var msg = new IntlMessageFormat(message, locales, [formats]);
var msg = new IntlMessageFormat(message, locales, [formats], [opts]);
```

@@ -126,2 +126,5 @@

- **[opts]** - `{ formatters?: Formatters }`: Optional options.
- `formatters`: Map containing memoized formatters for performance.
```js

@@ -183,2 +186,4 @@ var msg = new IntlMessageFormat('My name is {name}.', 'en-US');

### Core entry point
We also expose another entry point via `intl-messageformat/core` that does not contain the parser from `intl-messageformat-parser`. This is significantly smaller than the regular package but expects the message passed in to be in `AST` form instead of string. E.g:

@@ -199,2 +204,21 @@

### Formatters
For complex messages, initializing `Intl.*` constructors can be expensive. Therefore, we allow user to pass in `formatters` to provide memoized instances of these `Intl` objects. This opts combines with passing in AST + using [core entry point](#core-entry-point) and `intl-format-cache` can speed things up by 30x per the benchmark down below.
For example:
```ts
import IntlMessageFormat from 'intl-messageformat';
import memoizeIntlConstructor from 'intl-format-cache';
const formatters = {
getNumberFormat: memoizeIntlConstructor(Intl.NumberFormat),
getDateTimeFormat: memoizeIntlConstructor(Intl.DateTimeFormat),
getPluralRules: memoizeIntlConstructor(Intl.PluralRules)
};
new IntlMessageFormat('hello {number, number}', 'en', undefined, {
formatters
}).format({ number: 3 }); // prints out `hello, 3`
```
## Examples

@@ -229,2 +253,15 @@

## Benchmark
```
format_cached_complex_msg x 539,674 ops/sec ±1.87% (87 runs sampled)
format_cached_string_msg x 99,311,640 ops/sec ±2.15% (87 runs sampled)
new_complex_msg_preparsed x 1,490 ops/sec ±8.37% (54 runs sampled)
new_complex_msg x 836 ops/sec ±31.96% (67 runs sampled)
new_string_msg x 27,752 ops/sec ±8.25% (65 runs sampled)
complex msg format x 799 ops/sec ±9.38% (55 runs sampled)
complex msg w/ formatters format x 1,878 ops/sec ±16.63% (64 runs sampled)
complex preparsed msg w/ formatters format x 26,482 ops/sec ±2.55% (84 runs sampled)
```
## License

@@ -231,0 +268,0 @@

@@ -21,2 +21,14 @@ /*

export interface Formatters {
getNumberFormat(
...args: ConstructorParameters<typeof Intl.NumberFormat>
): Intl.NumberFormat;
getDateTimeFormat(
...args: ConstructorParameters<typeof Intl.DateTimeFormat>
): Intl.DateTimeFormat;
getPluralRules(
...args: ConstructorParameters<typeof Intl.PluralRules>
): Intl.PluralRules;
}
export type Pattern =

@@ -39,6 +51,12 @@ | string

private pluralStack: Array<ArgumentElement | null | undefined> = [];
private formatters: Formatters;
constructor(locales: string | string[], formats: Formats) {
constructor(
locales: string | string[],
formats: Formats,
formatters: Formatters
) {
this.locales = locales;
this.formats = formats;
this.formatters = formatters;
}

@@ -101,2 +119,3 @@

const { format, id } = element;
const { formatters } = this;

@@ -112,4 +131,6 @@ if (!format) {

id,
format: new Intl.NumberFormat(locales, formats.number[format.style])
.format
format: formatters.getNumberFormat(
locales,
formats.number[format.style]
).format
};

@@ -120,4 +141,6 @@

id,
format: new Intl.DateTimeFormat(locales, formats.date[format.style])
.format
format: formatters.getDateTimeFormat(
locales,
formats.date[format.style]
).format
};

@@ -128,4 +151,6 @@

id,
format: new Intl.DateTimeFormat(locales, formats.time[format.style])
.format
format: formatters.getDateTimeFormat(
locales,
formats.time[format.style]
).format
};

@@ -136,6 +161,7 @@

id,
format.ordinal,
format.offset,
this.compileOptions(element),
locales
formatters.getPluralRules(locales, {
type: format.ordinal ? 'ordinal' : 'cardinal'
})
);

@@ -186,3 +212,3 @@

export class StringFormat extends Formatter {
class StringFormat extends Formatter {
format(value: number | string) {

@@ -197,3 +223,3 @@ if (!value && typeof value !== 'number') {

export class PluralFormat {
class PluralFormat {
public id: string;

@@ -205,6 +231,5 @@ private offset: number;

id: string,
useOrdinal: boolean,
offset: number,
options: Record<string, Pattern[]>,
locales: string | string[]
pluralRules: Intl.PluralRules
) {

@@ -214,5 +239,3 @@ this.id = id;

this.options = options;
this.pluralRules = new Intl.PluralRules(locales, {
type: useOrdinal ? 'ordinal' : 'cardinal'
});
this.pluralRules = pluralRules;
}

@@ -219,0 +242,0 @@

@@ -9,3 +9,8 @@ /*

import Compiler, { Formats, isSelectOrPluralFormat, Pattern } from './compiler';
import Compiler, {
Formats,
isSelectOrPluralFormat,
Pattern,
Formatters
} from './compiler';
import parser, { MessageFormatPattern } from 'intl-messageformat-parser';

@@ -26,3 +31,3 @@

} catch (e) {
return MessageFormat.defaultLocale;
return IntlMessageFormat.defaultLocale;
}

@@ -107,146 +112,154 @@ }

export interface IntlMessageFormat {
new (
message: string | MessageFormatPattern,
locales?: string | string[],
overrideFormats?: Partial<Formats>
): IntlMessageFormat;
(
message: string | MessageFormatPattern,
locales?: string | string[],
overrideFormats?: Partial<Formats>
): IntlMessageFormat;
format(
values?: Record<string, string | number | boolean | null | undefined>
): string;
resolvedOptions(): { locale: string };
getAst(): ReturnType<typeof parser['parse']>;
defaultLocale: string;
formats: Formats;
__parse: typeof parser['parse'];
export interface Options {
formatters?: Formatters;
}
export const MessageFormat: IntlMessageFormat = ((
message: string | MessageFormatPattern,
locales: string | string[] = MessageFormat.defaultLocale,
overrideFormats?: Partial<Formats>
) => {
// Parse string messages into an AST.
const ast =
typeof message === 'string' ? MessageFormat.__parse(message) : message;
export function createDefaultFormatters(): Formatters {
return {
getNumberFormat(...args) {
return new Intl.NumberFormat(...args);
},
getDateTimeFormat(...args) {
return new Intl.DateTimeFormat(...args);
},
getPluralRules(...args) {
return new Intl.PluralRules(...args);
}
};
}
if (!(ast && ast.type === 'messageFormatPattern')) {
throw new TypeError('A message must be provided as a String or AST.');
}
export class IntlMessageFormat {
private ast: MessageFormatPattern;
private locale: string;
private pattern: Pattern[];
private message: string;
constructor(
message: string | MessageFormatPattern,
locales: string | string[] = IntlMessageFormat.defaultLocale,
overrideFormats?: Partial<Formats>,
opts?: Options
) {
// Parse string messages into an AST.
this.ast =
typeof message === 'string'
? IntlMessageFormat.__parse(message)
: message;
this.message = typeof message === 'string' ? message : '';
// Creates a new object with the specified `formats` merged with the default
// formats.
const formats = mergeConfigs(MessageFormat.formats, overrideFormats);
if (!(this.ast && this.ast.type === 'messageFormatPattern')) {
throw new TypeError('A message must be provided as a String or AST.');
}
// Defined first because it's used to build the format pattern.
const locale = resolveLocale(locales || []);
// Creates a new object with the specified `formats` merged with the default
// formats.
const formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
const pattern = new Compiler(locales, formats).compile(ast);
// Defined first because it's used to build the format pattern.
this.locale = resolveLocale(locales || []);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
return {
format(
values?: Record<string, string | number | boolean | null | undefined>
) {
try {
return formatPatterns(pattern, values);
} catch (e) {
if (e.variableId) {
throw new Error(
`The intl string context variable '${e.variableId}' was not provided to the string '${message}'`
);
} else {
throw e;
}
let formatters = (opts && opts.formatters) || createDefaultFormatters();
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
this.pattern = new Compiler(locales, formats, formatters).compile(this.ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
}
format = (
values?: Record<string, string | number | boolean | null | undefined>
) => {
try {
return formatPatterns(this.pattern, values);
} catch (e) {
if (e.variableId) {
throw new Error(
`The intl string context variable '${e.variableId}' was not provided to the string '${this.message}'`
);
} else {
throw e;
}
},
resolvedOptions() {
return { locale };
},
getAst() {
return ast;
}
};
}) as any;
resolvedOptions() {
return { locale: this.locale };
}
getAst() {
return this.ast;
}
static defaultLocale = 'en';
static __parse = parser.parse;
// 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.
static formats = {
number: {
currency: {
style: 'currency'
},
MessageFormat.defaultLocale = 'en';
// 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.
MessageFormat.formats = {
number: {
currency: {
style: 'currency'
percent: {
style: 'percent'
}
},
percent: {
style: 'percent'
}
},
date: {
short: {
month: 'numeric',
day: 'numeric',
year: '2-digit'
},
date: {
short: {
month: 'numeric',
day: 'numeric',
year: '2-digit'
},
medium: {
month: 'short',
day: 'numeric',
year: 'numeric'
},
medium: {
month: 'short',
day: 'numeric',
year: 'numeric'
},
long: {
month: 'long',
day: 'numeric',
year: 'numeric'
},
long: {
month: 'long',
day: 'numeric',
year: 'numeric'
full: {
weekday: 'long',
month: 'long',
day: 'numeric',
year: 'numeric'
}
},
full: {
weekday: 'long',
month: 'long',
day: 'numeric',
year: 'numeric'
}
},
time: {
short: {
hour: 'numeric',
minute: 'numeric'
},
time: {
short: {
hour: 'numeric',
minute: 'numeric'
},
medium: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
},
medium: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
},
long: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
},
long: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
},
full: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
full: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
}
}
}
};
};
}
export { Formats, Pattern } from './compiler';
export default MessageFormat;
export default IntlMessageFormat;

@@ -8,7 +8,9 @@ /*

import parser from 'intl-messageformat-parser';
import MessageFormat from './core';
import IntlMessageFormat from './core';
MessageFormat.__parse = parser.parse;
IntlMessageFormat.__parse = parser.parse;
export { Formats, Pattern } from './compiler';
export default MessageFormat;
export * from './core';
export { Formatters } from './compiler';
export default IntlMessageFormat;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc