intl-messageformat 8.2.1 → 8.3.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/CHANGELOG.md +52 -0
- package/dist/core.d.ts +2 -2
- package/dist/error.d.ts +16 -5
- package/dist/error.js +22 -4
- package/dist/formatters.d.ts +1 -1
- package/dist/formatters.js +9 -4
- package/dist/umd/intl-messageformat.js +34 -8
- package/dist/umd/intl-messageformat.js.map +1 -1
- package/dist/umd/intl-messageformat.min.js +1 -1
- package/dist/umd/intl-messageformat.min.js.map +1 -1
- package/lib/core.d.ts +2 -2
- package/lib/error.d.ts +16 -5
- package/lib/error.js +22 -4
- package/lib/formatters.d.ts +1 -1
- package/lib/formatters.js +10 -5
- package/lib/intl-messageformat.d.ts +20 -8
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +5 -5
- package/src/error.ts +33 -7
- package/src/formatters.ts +18 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,58 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [8.3.2](https://github.com/formatjs/formatjs/compare/intl-messageformat@8.3.1...intl-messageformat@8.3.2) (2020-03-28)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **intl-messageformat:** add FormatXMLElementFn generic return type ([9b4516c](https://github.com/formatjs/formatjs/commit/9b4516cd1be9fcc1d98fecef31949caa415530c2))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [8.3.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@8.3.0...intl-messageformat@8.3.1) (2020-03-26)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **intl-messageformat:** add missing import to formatters ([be26f59](https://github.com/formatjs/formatjs/commit/be26f591fb373cfca5c0469572bf6a24692bacdc))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# [8.3.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@8.2.3...intl-messageformat@8.3.0) (2020-03-26)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Features
|
|
32
|
+
|
|
33
|
+
* **intl-messageformat:** add more debug info to errors ([58dd475](https://github.com/formatjs/formatjs/commit/58dd475f90d1d11c8085fa554c9229b0f1f65a1d))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## [8.2.3](https://github.com/formatjs/formatjs/compare/intl-messageformat@8.2.2...intl-messageformat@8.2.3) (2020-03-21)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
* **intl-messageformat:** change ErrorCode to string enum ([db8662a](https://github.com/formatjs/formatjs/commit/db8662aaf7571ce035f716611901882a89e193da))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## [8.2.2](https://github.com/formatjs/formatjs/compare/intl-messageformat@8.2.1...intl-messageformat@8.2.2) (2020-03-18)
|
|
51
|
+
|
|
52
|
+
**Note:** Version bump only for package intl-messageformat
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
6
58
|
## [8.2.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@8.2.0...intl-messageformat@8.2.1) (2020-03-05)
|
|
7
59
|
|
|
8
60
|
|
package/dist/core.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export declare class IntlMessageFormat {
|
|
|
12
12
|
private readonly message;
|
|
13
13
|
private readonly formatterCache;
|
|
14
14
|
constructor(message: string | MessageFormatElement[], locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
|
|
15
|
-
format: <T = void>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T> | null | undefined> | undefined) => string | T | (string | T)[];
|
|
16
|
-
formatToParts: <T>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T> | null | undefined> | undefined) => MessageFormatPart<T>[];
|
|
15
|
+
format: <T = void>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T, string | (string | T)[]> | null | undefined> | undefined) => string | T | (string | T)[];
|
|
16
|
+
formatToParts: <T>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T, string | (string | T)[]> | null | undefined> | undefined) => MessageFormatPart<T>[];
|
|
17
17
|
resolvedOptions: () => {
|
|
18
18
|
locale: string;
|
|
19
19
|
};
|
package/dist/error.d.ts
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
export declare const enum ErrorCode {
|
|
2
|
-
MISSING_VALUE =
|
|
3
|
-
INVALID_VALUE =
|
|
4
|
-
MISSING_INTL_API =
|
|
2
|
+
MISSING_VALUE = "MISSING_VALUE",
|
|
3
|
+
INVALID_VALUE = "INVALID_VALUE",
|
|
4
|
+
MISSING_INTL_API = "MISSING_INTL_API"
|
|
5
5
|
}
|
|
6
6
|
export declare class FormatError extends Error {
|
|
7
7
|
readonly code: ErrorCode;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Original message we're trying to format
|
|
10
|
+
* `undefined` if we're only dealing w/ AST
|
|
11
|
+
*
|
|
12
|
+
* @type {(string | undefined)}
|
|
13
|
+
* @memberof FormatError
|
|
14
|
+
*/
|
|
15
|
+
readonly originalMessage: string | undefined;
|
|
16
|
+
constructor(msg: string, code: ErrorCode, originalMessage?: string);
|
|
9
17
|
toString(): string;
|
|
10
18
|
}
|
|
11
19
|
export declare class InvalidValueError extends FormatError {
|
|
12
|
-
constructor(variableId: string, value: any, options: string[]);
|
|
20
|
+
constructor(variableId: string, value: any, options: string[], originalMessage?: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class InvalidValueTypeError extends FormatError {
|
|
23
|
+
constructor(value: any, type: string, originalMessage?: string);
|
|
13
24
|
}
|
|
14
25
|
export declare class MissingValueError extends FormatError {
|
|
15
26
|
constructor(variableId: string, originalMessage?: string);
|
package/dist/error.js
CHANGED
|
@@ -13,11 +13,21 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
13
13
|
};
|
|
14
14
|
})();
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
var ErrorCode;
|
|
17
|
+
(function (ErrorCode) {
|
|
18
|
+
// When we have a placeholder but no value to format
|
|
19
|
+
ErrorCode["MISSING_VALUE"] = "MISSING_VALUE";
|
|
20
|
+
// When value supplied is invalid
|
|
21
|
+
ErrorCode["INVALID_VALUE"] = "INVALID_VALUE";
|
|
22
|
+
// When we need specific Intl API but it's not available
|
|
23
|
+
ErrorCode["MISSING_INTL_API"] = "MISSING_INTL_API";
|
|
24
|
+
})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
|
|
16
25
|
var FormatError = /** @class */ (function (_super) {
|
|
17
26
|
__extends(FormatError, _super);
|
|
18
|
-
function FormatError(msg, code) {
|
|
27
|
+
function FormatError(msg, code, originalMessage) {
|
|
19
28
|
var _this = _super.call(this, msg) || this;
|
|
20
29
|
_this.code = code;
|
|
30
|
+
_this.originalMessage = originalMessage;
|
|
21
31
|
return _this;
|
|
22
32
|
}
|
|
23
33
|
FormatError.prototype.toString = function () {
|
|
@@ -28,16 +38,24 @@ var FormatError = /** @class */ (function (_super) {
|
|
|
28
38
|
exports.FormatError = FormatError;
|
|
29
39
|
var InvalidValueError = /** @class */ (function (_super) {
|
|
30
40
|
__extends(InvalidValueError, _super);
|
|
31
|
-
function InvalidValueError(variableId, value, options) {
|
|
32
|
-
return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"",
|
|
41
|
+
function InvalidValueError(variableId, value, options, originalMessage) {
|
|
42
|
+
return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"", "INVALID_VALUE" /* INVALID_VALUE */, originalMessage) || this;
|
|
33
43
|
}
|
|
34
44
|
return InvalidValueError;
|
|
35
45
|
}(FormatError));
|
|
36
46
|
exports.InvalidValueError = InvalidValueError;
|
|
47
|
+
var InvalidValueTypeError = /** @class */ (function (_super) {
|
|
48
|
+
__extends(InvalidValueTypeError, _super);
|
|
49
|
+
function InvalidValueTypeError(value, type, originalMessage) {
|
|
50
|
+
return _super.call(this, "Value for \"" + value + "\" must be of type " + type, "INVALID_VALUE" /* INVALID_VALUE */, originalMessage) || this;
|
|
51
|
+
}
|
|
52
|
+
return InvalidValueTypeError;
|
|
53
|
+
}(FormatError));
|
|
54
|
+
exports.InvalidValueTypeError = InvalidValueTypeError;
|
|
37
55
|
var MissingValueError = /** @class */ (function (_super) {
|
|
38
56
|
__extends(MissingValueError, _super);
|
|
39
57
|
function MissingValueError(variableId, originalMessage) {
|
|
40
|
-
return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"",
|
|
58
|
+
return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"", "MISSING_VALUE" /* MISSING_VALUE */, originalMessage) || this;
|
|
41
59
|
}
|
|
42
60
|
return MissingValueError;
|
|
43
61
|
}(FormatError));
|
package/dist/formatters.d.ts
CHANGED
|
@@ -29,4 +29,4 @@ export interface ObjectPart<T = any> {
|
|
|
29
29
|
export declare type MessageFormatPart<T> = LiteralPart | ObjectPart<T>;
|
|
30
30
|
export declare type PrimitiveType = string | number | boolean | null | undefined | Date;
|
|
31
31
|
export declare function formatToParts<T>(els: MessageFormatElement[], locales: string | string[], formatters: Formatters, formats: Formats, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, currentPluralValue?: number, originalMessage?: string): MessageFormatPart<T>[];
|
|
32
|
-
export declare type FormatXMLElementFn<T
|
|
32
|
+
export declare type FormatXMLElementFn<T, R = string | Array<string | T>> = (...args: Array<string | T>) => R;
|
package/dist/formatters.js
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var intl_messageformat_parser_1 = require("intl-messageformat-parser");
|
|
4
4
|
var error_1 = require("./error");
|
|
5
|
+
var PART_TYPE;
|
|
6
|
+
(function (PART_TYPE) {
|
|
7
|
+
PART_TYPE[PART_TYPE["literal"] = 0] = "literal";
|
|
8
|
+
PART_TYPE[PART_TYPE["object"] = 1] = "object";
|
|
9
|
+
})(PART_TYPE = exports.PART_TYPE || (exports.PART_TYPE = {}));
|
|
5
10
|
function mergeLiteral(parts) {
|
|
6
11
|
if (parts.length < 2) {
|
|
7
12
|
return parts;
|
|
@@ -121,7 +126,7 @@ originalMessage) {
|
|
|
121
126
|
var children = el.children, value_1 = el.value;
|
|
122
127
|
var formatFn = values[value_1];
|
|
123
128
|
if (!isFormatXMLElementFn(formatFn)) {
|
|
124
|
-
throw new
|
|
129
|
+
throw new error_1.InvalidValueTypeError(value_1, 'function', originalMessage);
|
|
125
130
|
}
|
|
126
131
|
var parts = formatToParts(children, locales, formatters, formats, values);
|
|
127
132
|
var chunks = formatFn.apply(void 0, parts.map(function (p) { return p.value; }));
|
|
@@ -138,7 +143,7 @@ originalMessage) {
|
|
|
138
143
|
if (intl_messageformat_parser_1.isSelectElement(el)) {
|
|
139
144
|
var opt = el.options[value] || el.options.other;
|
|
140
145
|
if (!opt) {
|
|
141
|
-
throw new error_1.InvalidValueError(el.value, value, Object.keys(el.options));
|
|
146
|
+
throw new error_1.InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
|
|
142
147
|
}
|
|
143
148
|
result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values));
|
|
144
149
|
continue;
|
|
@@ -147,7 +152,7 @@ originalMessage) {
|
|
|
147
152
|
var opt = el.options["=" + value];
|
|
148
153
|
if (!opt) {
|
|
149
154
|
if (!Intl.PluralRules) {
|
|
150
|
-
throw new error_1.FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n",
|
|
155
|
+
throw new error_1.FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */, originalMessage);
|
|
151
156
|
}
|
|
152
157
|
var rule = formatters
|
|
153
158
|
.getPluralRules(locales, { type: el.pluralType })
|
|
@@ -155,7 +160,7 @@ originalMessage) {
|
|
|
155
160
|
opt = el.options[rule] || el.options.other;
|
|
156
161
|
}
|
|
157
162
|
if (!opt) {
|
|
158
|
-
throw new error_1.InvalidValueError(el.value, value, Object.keys(el.options));
|
|
163
|
+
throw new error_1.InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
|
|
159
164
|
}
|
|
160
165
|
result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values, value - (el.offset || 0)));
|
|
161
166
|
continue;
|
|
@@ -44,6 +44,11 @@
|
|
|
44
44
|
*/
|
|
45
45
|
TYPE[TYPE["tag"] = 8] = "tag";
|
|
46
46
|
})(TYPE || (TYPE = {}));
|
|
47
|
+
var SKELETON_TYPE;
|
|
48
|
+
(function (SKELETON_TYPE) {
|
|
49
|
+
SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number";
|
|
50
|
+
SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime";
|
|
51
|
+
})(SKELETON_TYPE || (SKELETON_TYPE = {}));
|
|
47
52
|
/**
|
|
48
53
|
* Type Guards
|
|
49
54
|
*/
|
|
@@ -3510,11 +3515,20 @@
|
|
|
3510
3515
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
3511
3516
|
};
|
|
3512
3517
|
})();
|
|
3518
|
+
(function (ErrorCode) {
|
|
3519
|
+
// When we have a placeholder but no value to format
|
|
3520
|
+
ErrorCode["MISSING_VALUE"] = "MISSING_VALUE";
|
|
3521
|
+
// When value supplied is invalid
|
|
3522
|
+
ErrorCode["INVALID_VALUE"] = "INVALID_VALUE";
|
|
3523
|
+
// When we need specific Intl API but it's not available
|
|
3524
|
+
ErrorCode["MISSING_INTL_API"] = "MISSING_INTL_API";
|
|
3525
|
+
})(exports.ErrorCode || (exports.ErrorCode = {}));
|
|
3513
3526
|
var FormatError = /** @class */ (function (_super) {
|
|
3514
3527
|
__extends$1(FormatError, _super);
|
|
3515
|
-
function FormatError(msg, code) {
|
|
3528
|
+
function FormatError(msg, code, originalMessage) {
|
|
3516
3529
|
var _this = _super.call(this, msg) || this;
|
|
3517
3530
|
_this.code = code;
|
|
3531
|
+
_this.originalMessage = originalMessage;
|
|
3518
3532
|
return _this;
|
|
3519
3533
|
}
|
|
3520
3534
|
FormatError.prototype.toString = function () {
|
|
@@ -3524,19 +3538,30 @@
|
|
|
3524
3538
|
}(Error));
|
|
3525
3539
|
var InvalidValueError = /** @class */ (function (_super) {
|
|
3526
3540
|
__extends$1(InvalidValueError, _super);
|
|
3527
|
-
function InvalidValueError(variableId, value, options) {
|
|
3528
|
-
return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"",
|
|
3541
|
+
function InvalidValueError(variableId, value, options, originalMessage) {
|
|
3542
|
+
return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"", "INVALID_VALUE" /* INVALID_VALUE */, originalMessage) || this;
|
|
3529
3543
|
}
|
|
3530
3544
|
return InvalidValueError;
|
|
3531
3545
|
}(FormatError));
|
|
3546
|
+
var InvalidValueTypeError = /** @class */ (function (_super) {
|
|
3547
|
+
__extends$1(InvalidValueTypeError, _super);
|
|
3548
|
+
function InvalidValueTypeError(value, type, originalMessage) {
|
|
3549
|
+
return _super.call(this, "Value for \"" + value + "\" must be of type " + type, "INVALID_VALUE" /* INVALID_VALUE */, originalMessage) || this;
|
|
3550
|
+
}
|
|
3551
|
+
return InvalidValueTypeError;
|
|
3552
|
+
}(FormatError));
|
|
3532
3553
|
var MissingValueError = /** @class */ (function (_super) {
|
|
3533
3554
|
__extends$1(MissingValueError, _super);
|
|
3534
3555
|
function MissingValueError(variableId, originalMessage) {
|
|
3535
|
-
return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"",
|
|
3556
|
+
return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"", "MISSING_VALUE" /* MISSING_VALUE */, originalMessage) || this;
|
|
3536
3557
|
}
|
|
3537
3558
|
return MissingValueError;
|
|
3538
3559
|
}(FormatError));
|
|
3539
3560
|
|
|
3561
|
+
(function (PART_TYPE) {
|
|
3562
|
+
PART_TYPE[PART_TYPE["literal"] = 0] = "literal";
|
|
3563
|
+
PART_TYPE[PART_TYPE["object"] = 1] = "object";
|
|
3564
|
+
})(exports.PART_TYPE || (exports.PART_TYPE = {}));
|
|
3540
3565
|
function mergeLiteral(parts) {
|
|
3541
3566
|
if (parts.length < 2) {
|
|
3542
3567
|
return parts;
|
|
@@ -3656,7 +3681,7 @@
|
|
|
3656
3681
|
var children = el.children, value_1 = el.value;
|
|
3657
3682
|
var formatFn = values[value_1];
|
|
3658
3683
|
if (!isFormatXMLElementFn(formatFn)) {
|
|
3659
|
-
throw new
|
|
3684
|
+
throw new InvalidValueTypeError(value_1, 'function', originalMessage);
|
|
3660
3685
|
}
|
|
3661
3686
|
var parts = formatToParts(children, locales, formatters, formats, values);
|
|
3662
3687
|
var chunks = formatFn.apply(void 0, parts.map(function (p) { return p.value; }));
|
|
@@ -3673,7 +3698,7 @@
|
|
|
3673
3698
|
if (isSelectElement(el)) {
|
|
3674
3699
|
var opt = el.options[value] || el.options.other;
|
|
3675
3700
|
if (!opt) {
|
|
3676
|
-
throw new InvalidValueError(el.value, value, Object.keys(el.options));
|
|
3701
|
+
throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
|
|
3677
3702
|
}
|
|
3678
3703
|
result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values));
|
|
3679
3704
|
continue;
|
|
@@ -3682,7 +3707,7 @@
|
|
|
3682
3707
|
var opt = el.options["=" + value];
|
|
3683
3708
|
if (!opt) {
|
|
3684
3709
|
if (!Intl.PluralRules) {
|
|
3685
|
-
throw new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n",
|
|
3710
|
+
throw new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */, originalMessage);
|
|
3686
3711
|
}
|
|
3687
3712
|
var rule = formatters
|
|
3688
3713
|
.getPluralRules(locales, { type: el.pluralType })
|
|
@@ -3690,7 +3715,7 @@
|
|
|
3690
3715
|
opt = el.options[rule] || el.options.other;
|
|
3691
3716
|
}
|
|
3692
3717
|
if (!opt) {
|
|
3693
|
-
throw new InvalidValueError(el.value, value, Object.keys(el.options));
|
|
3718
|
+
throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
|
|
3694
3719
|
}
|
|
3695
3720
|
result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values, value - (el.offset || 0)));
|
|
3696
3721
|
continue;
|
|
@@ -3881,6 +3906,7 @@
|
|
|
3881
3906
|
exports.FormatError = FormatError;
|
|
3882
3907
|
exports.IntlMessageFormat = IntlMessageFormat;
|
|
3883
3908
|
exports.InvalidValueError = InvalidValueError;
|
|
3909
|
+
exports.InvalidValueTypeError = InvalidValueTypeError;
|
|
3884
3910
|
exports.MissingValueError = MissingValueError;
|
|
3885
3911
|
exports.createDefaultFormatters = createDefaultFormatters;
|
|
3886
3912
|
exports.default = IntlMessageFormat;
|