intl-messageformat 9.8.1 → 9.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/intl-messageformat.esm.js +55 -40
- package/package.json +3 -3
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
|
|
1
8
|
// node_modules/tslib/tslib.es6.js
|
|
2
9
|
var __assign = function() {
|
|
3
10
|
__assign = Object.assign || function __assign2(t) {
|
|
@@ -1336,6 +1343,8 @@ var ErrorCode;
|
|
|
1336
1343
|
ErrorCode2["MISSING_INTL_API"] = "MISSING_INTL_API";
|
|
1337
1344
|
})(ErrorCode || (ErrorCode = {}));
|
|
1338
1345
|
var FormatError = class extends Error {
|
|
1346
|
+
code;
|
|
1347
|
+
originalMessage;
|
|
1339
1348
|
constructor(msg, code, originalMessage) {
|
|
1340
1349
|
super(msg);
|
|
1341
1350
|
this.code = code;
|
|
@@ -1563,42 +1572,24 @@ function createDefaultFormatters(cache = {
|
|
|
1563
1572
|
})
|
|
1564
1573
|
};
|
|
1565
1574
|
}
|
|
1566
|
-
var
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
const result = parts.reduce((all, part) => {
|
|
1579
|
-
if (!all.length || part.type !== PART_TYPE.literal || typeof all[all.length - 1] !== "string") {
|
|
1580
|
-
all.push(part.value);
|
|
1581
|
-
} else {
|
|
1582
|
-
all[all.length - 1] += part.value;
|
|
1583
|
-
}
|
|
1584
|
-
return all;
|
|
1585
|
-
}, []);
|
|
1586
|
-
if (result.length <= 1) {
|
|
1587
|
-
return result[0] || "";
|
|
1588
|
-
}
|
|
1589
|
-
return result;
|
|
1590
|
-
};
|
|
1591
|
-
this.formatToParts = (values) => formatToParts(this.ast, this.locales, this.formatters, this.formats, values, void 0, this.message);
|
|
1592
|
-
this.resolvedOptions = () => ({
|
|
1593
|
-
locale: Intl.NumberFormat.supportedLocalesOf(this.locales)[0]
|
|
1594
|
-
});
|
|
1595
|
-
this.getAst = () => this.ast;
|
|
1575
|
+
var _IntlMessageFormat = class {
|
|
1576
|
+
ast;
|
|
1577
|
+
locales;
|
|
1578
|
+
formatters;
|
|
1579
|
+
formats;
|
|
1580
|
+
message;
|
|
1581
|
+
formatterCache = {
|
|
1582
|
+
number: {},
|
|
1583
|
+
dateTime: {},
|
|
1584
|
+
pluralRules: {}
|
|
1585
|
+
};
|
|
1586
|
+
constructor(message, locales = _IntlMessageFormat.defaultLocale, overrideFormats, opts) {
|
|
1596
1587
|
if (typeof message === "string") {
|
|
1597
1588
|
this.message = message;
|
|
1598
|
-
if (!
|
|
1589
|
+
if (!_IntlMessageFormat.__parse) {
|
|
1599
1590
|
throw new TypeError("IntlMessageFormat.__parse must be set to process `message` of type `string`");
|
|
1600
1591
|
}
|
|
1601
|
-
this.ast =
|
|
1592
|
+
this.ast = _IntlMessageFormat.__parse(message, {
|
|
1602
1593
|
ignoreTag: opts?.ignoreTag
|
|
1603
1594
|
});
|
|
1604
1595
|
} else {
|
|
@@ -1607,20 +1598,44 @@ var IntlMessageFormat = class {
|
|
|
1607
1598
|
if (!Array.isArray(this.ast)) {
|
|
1608
1599
|
throw new TypeError("A message must be provided as a String or AST.");
|
|
1609
1600
|
}
|
|
1610
|
-
this.formats = mergeConfigs(
|
|
1601
|
+
this.formats = mergeConfigs(_IntlMessageFormat.formats, overrideFormats);
|
|
1611
1602
|
this.locales = locales;
|
|
1612
1603
|
this.formatters = opts && opts.formatters || createDefaultFormatters(this.formatterCache);
|
|
1613
1604
|
}
|
|
1605
|
+
format = (values) => {
|
|
1606
|
+
const parts = this.formatToParts(values);
|
|
1607
|
+
if (parts.length === 1) {
|
|
1608
|
+
return parts[0].value;
|
|
1609
|
+
}
|
|
1610
|
+
const result = parts.reduce((all, part) => {
|
|
1611
|
+
if (!all.length || part.type !== PART_TYPE.literal || typeof all[all.length - 1] !== "string") {
|
|
1612
|
+
all.push(part.value);
|
|
1613
|
+
} else {
|
|
1614
|
+
all[all.length - 1] += part.value;
|
|
1615
|
+
}
|
|
1616
|
+
return all;
|
|
1617
|
+
}, []);
|
|
1618
|
+
if (result.length <= 1) {
|
|
1619
|
+
return result[0] || "";
|
|
1620
|
+
}
|
|
1621
|
+
return result;
|
|
1622
|
+
};
|
|
1623
|
+
formatToParts = (values) => formatToParts(this.ast, this.locales, this.formatters, this.formats, values, void 0, this.message);
|
|
1624
|
+
resolvedOptions = () => ({
|
|
1625
|
+
locale: Intl.NumberFormat.supportedLocalesOf(this.locales)[0]
|
|
1626
|
+
});
|
|
1627
|
+
getAst = () => this.ast;
|
|
1614
1628
|
static get defaultLocale() {
|
|
1615
|
-
if (!
|
|
1616
|
-
|
|
1629
|
+
if (!_IntlMessageFormat.memoizedDefaultLocale) {
|
|
1630
|
+
_IntlMessageFormat.memoizedDefaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
|
|
1617
1631
|
}
|
|
1618
|
-
return
|
|
1632
|
+
return _IntlMessageFormat.memoizedDefaultLocale;
|
|
1619
1633
|
}
|
|
1620
1634
|
};
|
|
1621
|
-
IntlMessageFormat
|
|
1622
|
-
IntlMessageFormat
|
|
1623
|
-
IntlMessageFormat
|
|
1635
|
+
var IntlMessageFormat = _IntlMessageFormat;
|
|
1636
|
+
__publicField(IntlMessageFormat, "memoizedDefaultLocale", null);
|
|
1637
|
+
__publicField(IntlMessageFormat, "__parse", parse);
|
|
1638
|
+
__publicField(IntlMessageFormat, "formats", {
|
|
1624
1639
|
number: {
|
|
1625
1640
|
integer: {
|
|
1626
1641
|
maximumFractionDigits: 0
|
|
@@ -1678,7 +1693,7 @@ IntlMessageFormat.formats = {
|
|
|
1678
1693
|
timeZoneName: "short"
|
|
1679
1694
|
}
|
|
1680
1695
|
}
|
|
1681
|
-
};
|
|
1696
|
+
});
|
|
1682
1697
|
|
|
1683
1698
|
// bazel-out/darwin-fastbuild/bin/packages/intl-messageformat/lib_esnext/index.js
|
|
1684
1699
|
var lib_esnext_default = IntlMessageFormat;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intl-messageformat",
|
|
3
|
-
"version": "9.8.
|
|
3
|
+
"version": "9.8.2",
|
|
4
4
|
"description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"module": "lib/index.js",
|
|
32
32
|
"types": "index.d.ts",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@formatjs/fast-memoize": "1.1.
|
|
35
|
-
"@formatjs/icu-messageformat-parser": "2.0.
|
|
34
|
+
"@formatjs/fast-memoize": "1.1.2",
|
|
35
|
+
"@formatjs/icu-messageformat-parser": "2.0.9",
|
|
36
36
|
"tslib": "^2.1.0"
|
|
37
37
|
},
|
|
38
38
|
"sideEffects": false,
|