intl-messageformat 4.1.1 → 4.4.0

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +32 -44
  2. package/LICENSE +0 -0
  3. package/README.md +108 -59
  4. package/core.js +1 -0
  5. package/dist/compiler.d.ts +10 -4
  6. package/dist/compiler.js +11 -14
  7. package/dist/compiler.js.map +1 -1
  8. package/dist/core.d.ts +78 -0
  9. package/dist/core.js +248 -0
  10. package/dist/core.js.map +1 -0
  11. package/dist/index.d.ts +4 -16
  12. package/dist/index.js +7 -198
  13. package/dist/index.js.map +1 -1
  14. package/dist/umd/intl-messageformat.js +1548 -1373
  15. package/dist/umd/intl-messageformat.js.map +1 -1
  16. package/dist/umd/intl-messageformat.min.js +1 -1
  17. package/dist/umd/intl-messageformat.min.js.map +1 -1
  18. package/index.js +0 -0
  19. package/lib/compiler.d.ts +10 -4
  20. package/lib/compiler.js +11 -14
  21. package/lib/compiler.js.map +1 -1
  22. package/lib/core.d.ts +78 -0
  23. package/lib/core.js +245 -0
  24. package/lib/core.js.map +1 -0
  25. package/lib/index.d.ts +4 -16
  26. package/lib/index.js +4 -198
  27. package/lib/index.js.map +1 -1
  28. package/package.json +4 -4
  29. package/src/compiler.ts +39 -16
  30. package/src/core.ts +269 -0
  31. package/src/index.ts +6 -242
  32. package/.nyc_output/34ec6f1e-d2e9-445f-8813-bd6e8b5975bb.json +0 -1
  33. package/.nyc_output/9b57550b-ff23-4ed6-b289-f7ff8d2beb4f.json +0 -1
  34. package/.nyc_output/b696f16a-7b55-4692-a441-41aa11ca2fb0.json +0 -1
  35. package/.nyc_output/processinfo/34ec6f1e-d2e9-445f-8813-bd6e8b5975bb.json +0 -1
  36. package/.nyc_output/processinfo/9b57550b-ff23-4ed6-b289-f7ff8d2beb4f.json +0 -1
  37. package/.nyc_output/processinfo/b696f16a-7b55-4692-a441-41aa11ca2fb0.json +0 -1
  38. package/.nyc_output/processinfo/index.json +0 -1
package/CHANGELOG.md CHANGED
@@ -3,98 +3,86 @@
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
- ## [4.1.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.1.0...intl-messageformat@4.1.1) (2019-06-18)
7
-
8
- **Note:** Version bump only for package intl-messageformat
6
+ # [4.4.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.3.0...intl-messageformat@4.4.0) (2019-06-28)
9
7
 
8
+ ### Features
10
9
 
10
+ - **intl-messageformat:** export core entry point ([ca7eeae](https://github.com/formatjs/formatjs/commit/ca7eeae))
11
11
 
12
+ # [4.3.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.2.1...intl-messageformat@4.3.0) (2019-06-27)
12
13
 
14
+ ### Features
13
15
 
14
- # [4.1.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.0.1...intl-messageformat@4.1.0) (2019-06-18)
16
+ - **intl-messageformat:** allow passing in formatters ([#107](https://github.com/formatjs/formatjs/issues/107)) ([3605693](https://github.com/formatjs/formatjs/commit/3605693))
15
17
 
18
+ ## [4.2.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.2.0...intl-messageformat@4.2.1) (2019-06-26)
16
19
 
17
- ### Features
20
+ **Note:** Version bump only for package intl-messageformat
18
21
 
19
- * **intl-format-cache:** fix TS definition ([71ae9eb](https://github.com/formatjs/formatjs/commit/71ae9eb))
22
+ # [4.2.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.1.2...intl-messageformat@4.2.0) (2019-06-27)
20
23
 
24
+ ### Features
21
25
 
26
+ - **intl-relativetimeformat:** make intl-relativetimeformat test262-compliant ([#95](https://github.com/formatjs/formatjs/issues/95)) ([91669a3](https://github.com/formatjs/formatjs/commit/91669a3))
27
+ - **intl-utils:** Add intl-utils ([#98](https://github.com/formatjs/formatjs/issues/98)) ([2329c57](https://github.com/formatjs/formatjs/commit/2329c57))
22
28
 
29
+ ## [4.1.2](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.1.1...intl-messageformat@4.1.2) (2019-06-18)
23
30
 
31
+ **Note:** Version bump only for package intl-messageformat
24
32
 
25
- ## [4.0.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.0.0...intl-messageformat@4.0.1) (2019-06-12)
33
+ ## [4.1.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.1.0...intl-messageformat@4.1.1) (2019-06-18)
26
34
 
27
35
  **Note:** Version bump only for package intl-messageformat
28
36
 
37
+ # [4.1.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.0.1...intl-messageformat@4.1.0) (2019-06-18)
29
38
 
39
+ ### Features
30
40
 
41
+ - **intl-format-cache:** fix TS definition ([71ae9eb](https://github.com/formatjs/formatjs/commit/71ae9eb))
31
42
 
43
+ ## [4.0.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.0.0...intl-messageformat@4.0.1) (2019-06-12)
32
44
 
33
- # [4.0.0](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.3.0...intl-messageformat@4.0.0) (2019-06-05)
45
+ **Note:** Version bump only for package intl-messageformat
34
46
 
47
+ # [4.0.0](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.3.0...intl-messageformat@4.0.0) (2019-06-05)
35
48
 
36
49
  ### Features
37
50
 
38
- * add package intl-relativetimeformat ([#51](https://github.com/formatjs/intl-messageformat/issues/51)) ([48c0f43](https://github.com/formatjs/intl-messageformat/commit/48c0f43))
39
- * **intl-messageformat:** rm bundled intl-pluralrules ([a8526c3](https://github.com/formatjs/intl-messageformat/commit/a8526c3))
40
- * **intl-messageformat:** rm rolluped dist ([a126939](https://github.com/formatjs/intl-messageformat/commit/a126939))
41
-
51
+ - add package intl-relativetimeformat ([#51](https://github.com/formatjs/intl-messageformat/issues/51)) ([48c0f43](https://github.com/formatjs/intl-messageformat/commit/48c0f43))
52
+ - **intl-messageformat:** rm bundled intl-pluralrules ([a8526c3](https://github.com/formatjs/intl-messageformat/commit/a8526c3))
53
+ - **intl-messageformat:** rm rolluped dist ([a126939](https://github.com/formatjs/intl-messageformat/commit/a126939))
42
54
 
43
55
  ### BREAKING CHANGES
44
56
 
45
- * **intl-messageformat:** Change dist files packaged. Entry point should stay the
46
- same though.
47
- * **intl-messageformat:** We no longer include intl-pluralrules in our main index
48
- file. Consumer should polyfill accordingly.
49
-
50
-
51
-
52
-
57
+ - **intl-messageformat:** Change dist files packaged. Entry point should stay the
58
+ same though.
59
+ - **intl-messageformat:** We no longer include intl-pluralrules in our main index
60
+ file. Consumer should polyfill accordingly.
53
61
 
54
62
  # [3.3.0](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.1.4...intl-messageformat@3.3.0) (2019-06-03)
55
63
 
56
-
57
64
  ### Features
58
65
 
59
- * **intl-messageformat:** Add `getAst` method ([3d6c289](https://github.com/formatjs/intl-messageformat/commit/3d6c289))
60
-
61
-
62
-
63
-
66
+ - **intl-messageformat:** Add `getAst` method ([3d6c289](https://github.com/formatjs/intl-messageformat/commit/3d6c289))
64
67
 
65
68
  # [3.2.0](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.1.4...intl-messageformat@3.2.0) (2019-06-03)
66
69
 
67
-
68
70
  ### Features
69
71
 
70
- * **intl-messageformat:** Add `getAst` method ([3d6c289](https://github.com/formatjs/intl-messageformat/commit/3d6c289))
71
-
72
-
73
-
74
-
72
+ - **intl-messageformat:** Add `getAst` method ([3d6c289](https://github.com/formatjs/intl-messageformat/commit/3d6c289))
75
73
 
76
74
  ## [3.1.4](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.1.3...intl-messageformat@3.1.4) (2019-05-31)
77
75
 
78
76
  **Note:** Version bump only for package intl-messageformat
79
77
 
80
-
81
-
82
-
83
-
84
78
  ## [3.1.3](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.1.2...intl-messageformat@3.1.3) (2019-05-28)
85
79
 
86
-
87
80
  ### Bug Fixes
88
81
 
89
- * **intl-messageformat:** fix [#36](https://github.com/formatjs/intl-messageformat/issues/36) and config merging ([#40](https://github.com/formatjs/intl-messageformat/issues/40)) ([4a9969f](https://github.com/formatjs/intl-messageformat/commit/4a9969f))
90
-
91
-
92
-
93
-
82
+ - **intl-messageformat:** fix [#36](https://github.com/formatjs/intl-messageformat/issues/36) and config merging ([#40](https://github.com/formatjs/intl-messageformat/issues/40)) ([4a9969f](https://github.com/formatjs/intl-messageformat/commit/4a9969f))
94
83
 
95
84
  ## [3.1.2](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.1.2...intl-messageformat@3.1.2) (2019-05-28)
96
85
 
97
-
98
86
  ### Bug Fixes
99
87
 
100
- * **intl-messageformat:** fix [#36](https://github.com/formatjs/intl-messageformat/issues/36) and config merging ([#40](https://github.com/formatjs/intl-messageformat/issues/40)) ([4a9969f](https://github.com/formatjs/intl-messageformat/commit/4a9969f))
88
+ - **intl-messageformat:** fix [#36](https://github.com/formatjs/intl-messageformat/issues/36) and config merging ([#40](https://github.com/formatjs/intl-messageformat/issues/40)) ([4a9969f](https://github.com/formatjs/intl-messageformat/commit/4a9969f))
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -1,16 +1,15 @@
1
- Intl MessageFormat
2
- ==================
1
+ # Intl MessageFormat
3
2
 
4
3
  Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.
5
4
 
6
5
  [![npm Version][npm-badge]][npm]
7
6
 
8
- ![gzip size](https://img.badgesize.io/formatjs/intl-messageformat/master/dist/intl-messageformat.min.js?compression=gzip&label=core+gzip+size)
7
+ | Package | Minzipped Size |
8
+ | ------------------------- | -------------- |
9
+ | `intl-messageformat` | `5.14kB` |
10
+ | `intl-messageformat/core` | `2.19kB` |
9
11
 
10
- [![Sauce Test Status](https://saucelabs.com/browser-matrix/formatjsproject.svg)](https://saucelabs.com/u/formatjsproject)
11
-
12
- Overview
13
- --------
12
+ ## Overview
14
13
 
15
14
  ### Goals
16
15
 
@@ -25,7 +24,7 @@ _Note: This `IntlMessageFormat` API may change to stay in sync with ECMA-402, bu
25
24
  Messages are provided into the constructor as a `String` message, or a [pre-parsed AST][parser] object.
26
25
 
27
26
  ```js
28
- var msg = new IntlMessageFormat(message, locales, [formats]);
27
+ var msg = new IntlMessageFormat(message, locales, [formats], [opts]);
29
28
  ```
30
29
 
31
30
  The string `message` is parsed, then stored internally in a compiled form that is optimized for the `format()` method to produce the formatted string for displaying to the user.
@@ -40,57 +39,57 @@ A very common example is formatting messages that have numbers with plural label
40
39
 
41
40
  ```js
42
41
  var MESSAGES = {
43
- 'en-US': {
44
- NUM_PHOTOS: 'You have {numPhotos, plural, ' +
45
- '=0 {no photos.}' +
46
- '=1 {one photo.}' +
47
- 'other {# photos.}}'
48
- },
49
-
50
- 'es-MX': {
51
- NUM_PHOTOS: 'Usted {numPhotos, plural, ' +
52
- '=0 {no tiene fotos.}' +
53
- '=1 {tiene una foto.}' +
54
- 'other {tiene # fotos.}}'
55
- }
42
+ 'en-US': {
43
+ NUM_PHOTOS:
44
+ 'You have {numPhotos, plural, ' +
45
+ '=0 {no photos.}' +
46
+ '=1 {one photo.}' +
47
+ 'other {# photos.}}'
48
+ },
49
+
50
+ 'es-MX': {
51
+ NUM_PHOTOS:
52
+ 'Usted {numPhotos, plural, ' +
53
+ '=0 {no tiene fotos.}' +
54
+ '=1 {tiene una foto.}' +
55
+ 'other {tiene # fotos.}}'
56
+ }
56
57
  };
57
58
 
58
59
  var output;
59
60
 
60
61
  var enNumPhotos = new IntlMessageFormat(MESSAGES['en-US'].NUM_PHOTOS, 'en-US');
61
- output = enNumPhotos.format({numPhotos: 1000});
62
+ output = enNumPhotos.format({ numPhotos: 1000 });
62
63
  console.log(output); // => "You have 1,000 photos."
63
64
 
64
65
  var esNumPhotos = new IntlMessageFormat(MESSAGES['es-MX'].NUM_PHOTOS, 'es-MX');
65
- output = esNumPhotos.format({numPhotos: 1000});
66
+ output = esNumPhotos.format({ numPhotos: 1000 });
66
67
  console.log(output); // => "Usted tiene 1,000 fotos."
67
68
  ```
68
69
 
69
70
  ### Message Syntax
70
71
 
71
- The message syntax that this package uses is not proprietary, in fact it's a common standard message syntax that works across programming languages and one that professional translators are familiar with. This package uses the **[ICU Message syntax][ICU]** and works for all [CLDR languages][CLDR] which have pluralization rules defined.
72
+ The message syntax that this package uses is not proprietary, in fact it's a common standard message syntax that works across programming languages and one that professional translators are familiar with. This package uses the **[ICU Message syntax][icu]** and works for all [CLDR languages][cldr] which have pluralization rules defined.
72
73
 
73
74
  ### Features
74
75
 
75
- * Uses industry standards: [ICU Message syntax][ICU] and [CLDR locale data][CLDR].
76
-
77
- * Supports **plural**, **select**, and **selectordinal** message arguments.
76
+ - Uses industry standards: [ICU Message syntax][icu] and [CLDR locale data][cldr].
78
77
 
79
- * Formats numbers and dates/times in messages using [`Intl.NumberFormat`][Intl-NF] and [`Intl.DateTimeFormat`][Intl-DTF], respectively.
78
+ - Supports **plural**, **select**, and **selectordinal** message arguments.
80
79
 
81
- * Optimized for repeated calls to an `IntlMessageFormat` instance's `format()` method.
80
+ - Formats numbers and dates/times in messages using [`Intl.NumberFormat`][intl-nf] and [`Intl.DateTimeFormat`][intl-dtf], respectively.
82
81
 
83
- * Supports defining custom format styles/options.
82
+ - Optimized for repeated calls to an `IntlMessageFormat` instance's `format()` method.
84
83
 
85
- * Supports escape sequences for message syntax chars, e.g.: `"\\{foo\\}"` will output: `"{foo}"` in the formatted output instead of interpreting it as a `foo` argument.
84
+ - Supports defining custom format styles/options.
86
85
 
86
+ - Supports escape sequences for message syntax chars, e.g.: `"\\{foo\\}"` will output: `"{foo}"` in the formatted output instead of interpreting it as a `foo` argument.
87
87
 
88
- Usage
89
- -----
88
+ ## Usage
90
89
 
91
90
  ### Modern `Intl` Dependency
92
91
 
93
- This package assumes that the [`Intl`][Intl] global object exists in the runtime. `Intl` is present in all modern browsers (IE11+) and Node (with full ICU). The `Intl` methods we rely on are:
92
+ This package assumes that the [`Intl`][intl] global object exists in the runtime. `Intl` is present in all modern browsers (IE11+) and Node (with full ICU). The `Intl` methods we rely on are:
94
93
 
95
94
  1. `Intl.NumberFormat` for number formatting (can be polyfilled using [Intl.js][])
96
95
  2. `Intl.DateTimeFormat` for date time formatting (can be polyfilled using [Intl.js][])
@@ -115,13 +114,17 @@ var IntlMessageFormat = require('intl-messageformat');
115
114
  ### Public API
116
115
 
117
116
  #### `IntlMessageFormat` Constructor
117
+
118
118
  To create a message to format, use the `IntlMessageFormat` constructor. The constructor takes three parameters:
119
119
 
120
- - **message** - _{String | AST}_ - String message (or pre-parsed AST) that serves as formatting pattern.
120
+ - **message** - _{String | AST}_ - String message (or pre-parsed AST) that serves as formatting pattern.
121
+
122
+ - **locales** - _{String | String[]}_ - A string with a BCP 47 language tag, or an array of such strings. If you do not provide a locale, the default locale will be used. When an array of locales is provided, each item and its ancestor locales are checked and the first one with registered locale data is returned. **See: [Locale Resolution](#locale-resolution) for more details.**
121
123
 
122
- - **locales** - _{String | String[]}_ - A string with a BCP 47 language tag, or an array of such strings. If you do not provide a locale, the default locale will be used. When an array of locales is provided, each item and its ancestor locales are checked and the first one with registered locale data is returned. **See: [Locale Resolution](#locale-resolution) for more details.**
124
+ - **[formats]** - _{Object}_ - Optional object with user defined options for format styles.
123
125
 
124
- - **[formats]** - _{Object}_ - Optional object with user defined options for format styles.
126
+ - **[opts]** - `{ formatters?: Formatters }`: Optional options.
127
+ - `formatters`: Map containing memoized formatters for performance.
125
128
 
126
129
  ```js
127
130
  var msg = new IntlMessageFormat('My name is {name}.', 'en-US');
@@ -147,7 +150,7 @@ Notice how the specified locale was the all lower-case value: `"en-us"`, but it
147
150
  Once the message is created, formatting the message is done by calling the `format()` method on the instance and passing a collection of `values`:
148
151
 
149
152
  ```js
150
- var output = msg.format({name: "Eric"});
153
+ var output = msg.format({ name: 'Eric' });
151
154
  console.log(output); // => "My name is Eric."
152
155
  ```
153
156
 
@@ -163,27 +166,63 @@ Define custom format styles is useful you need supply a set of options to the un
163
166
 
164
167
  ```js
165
168
  var msg = new IntlMessageFormat('The price is: {price, number, USD}', 'en-US', {
166
- number: {
167
- USD: {
168
- style : 'currency',
169
- currency: 'USD'
170
- }
169
+ number: {
170
+ USD: {
171
+ style: 'currency',
172
+ currency: 'USD'
171
173
  }
174
+ }
172
175
  });
173
176
 
174
- var output = msg.format({price: 100});
177
+ var output = msg.format({ price: 100 });
175
178
  console.log(output); // => "The price is: $100.00"
176
179
  ```
177
180
 
178
181
  In this example, we're defining a `USD` number format style which is passed to the underlying `Intl.NumberFormat` instance as its options.
179
182
 
183
+ ## Advanced Usage
184
+
185
+ ### Core entry point
186
+
187
+ 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:
188
+
189
+ ```ts
190
+ import IntlMessageFormat from 'intl-messageformat';
191
+ new IntlMessageFormat('hello').format(); // prints out hello
192
+
193
+ // is equivalent to
194
+
195
+ import IntlMessageFormat from 'intl-messageformat/core';
196
+ import parser from 'intl-messageformat-parser';
197
+ new IntlMessageFormat(parser.parse('hello')).format(); // prints out hello
198
+ ```
199
+
200
+ This helps performance for cases like SSR or preload/precompilation-supported platforms since `AST` can be cached.
201
+
202
+ ### Formatters
203
+
204
+ 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.
180
205
 
181
- Examples
182
- --------
206
+ For example:
207
+
208
+ ```ts
209
+ import IntlMessageFormat from 'intl-messageformat';
210
+ import memoizeIntlConstructor from 'intl-format-cache';
211
+ const formatters = {
212
+ getNumberFormat: memoizeIntlConstructor(Intl.NumberFormat),
213
+ getDateTimeFormat: memoizeIntlConstructor(Intl.DateTimeFormat),
214
+ getPluralRules: memoizeIntlConstructor(Intl.PluralRules)
215
+ };
216
+ new IntlMessageFormat('hello {number, number}', 'en', undefined, {
217
+ formatters
218
+ }).format({ number: 3 }); // prints out `hello, 3`
219
+ ```
220
+
221
+ ## Examples
183
222
 
184
223
  ### Plural Label
185
224
 
186
- This example shows how to use the [ICU Message syntax][ICU] to define a message that has a plural label; e.g., ``"You have 10 photos"``:
225
+ This example shows how to use the [ICU Message syntax][icu] to define a message that has a plural label; e.g., `"You have 10 photos"`:
187
226
 
188
227
  ```
189
228
  You have {numPhotos, plural,
@@ -208,26 +247,36 @@ console.log(msg.format({numPhotos: 1000})); // => "You have 1,000 photos."
208
247
 
209
248
  _Note: how when `numPhotos` was `1000`, the number is formatted with the correct thousands separator._
210
249
 
250
+ ## Benchmark
211
251
 
212
- License
213
- -------
252
+ ```
253
+ format_cached_complex_msg x 539,674 ops/sec ±1.87% (87 runs sampled)
254
+ format_cached_string_msg x 99,311,640 ops/sec ±2.15% (87 runs sampled)
255
+ new_complex_msg_preparsed x 1,490 ops/sec ±8.37% (54 runs sampled)
256
+ new_complex_msg x 836 ops/sec ±31.96% (67 runs sampled)
257
+ new_string_msg x 27,752 ops/sec ±8.25% (65 runs sampled)
258
+ complex msg format x 799 ops/sec ±9.38% (55 runs sampled)
259
+ complex msg w/ formatters format x 1,878 ops/sec ±16.63% (64 runs sampled)
260
+ complex preparsed msg w/ formatters format x 26,482 ops/sec ±2.55% (84 runs sampled)
261
+ ```
214
262
 
215
- This software is free to use under the Yahoo! Inc. BSD license.
216
- See the [LICENSE file][LICENSE] for license text and copyright information.
263
+ ## License
217
264
 
265
+ This software is free to use under the Yahoo! Inc. BSD license.
266
+ See the [LICENSE file][license] for license text and copyright information.
218
267
 
219
268
  [npm]: https://www.npmjs.org/package/intl-messageformat
220
269
  [npm-badge]: https://img.shields.io/npm/v/intl-messageformat.svg?style=flat-square
221
270
  [strawman]: http://wiki.ecmascript.org/doku.php?id=globalization:messageformatting
222
271
  [parser]: https://github.com/formatjs/formatjs/blob/master/packages/intl-messageformat-parser
223
- [ICU]: http://userguide.icu-project.org/formatparse/messages
224
- [CLDR]: http://cldr.unicode.org/
225
- [Intl]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl
226
- [Intl-NF]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
227
- [Intl-DTF]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
228
- [Intl-Node]: https://github.com/joyent/node/issues/6371
229
- [Intl.js]: https://github.com/andyearnshaw/Intl.js
272
+ [icu]: http://userguide.icu-project.org/formatparse/messages
273
+ [cldr]: http://cldr.unicode.org/
274
+ [intl]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl
275
+ [intl-nf]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
276
+ [intl-dtf]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
277
+ [intl-node]: https://github.com/joyent/node/issues/6371
278
+ [intl.js]: https://github.com/andyearnshaw/Intl.js
230
279
  [rawgit]: https://rawgit.com/
231
280
  [semver]: http://semver.org/
232
- [LICENSE]: https://github.com/formatjs/formatjs/blob/master/LICENSE
281
+ [license]: https://github.com/formatjs/formatjs/blob/master/LICENSE
233
282
  [intl-pluralrules]: https://github.com/eemeli/intl-pluralrules
package/core.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __extends=function(){var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),Compiler=function(){function t(t,e,r){this.locales=[],this.formats={number:{},date:{},time:{}},this.pluralNumberFormat=null,this.currentPlural=null,this.pluralStack=[],this.locales=t,this.formats=e,this.formatters=r}return t.prototype.compile=function(t){return this.pluralStack=[],this.currentPlural=null,this.pluralNumberFormat=null,this.compileMessage(t)},t.prototype.compileMessage=function(t){var e=this;if(!t||"messageFormatPattern"!==t.type)throw new Error('Message AST is not of type: "messageFormatPattern"');var r=t.elements,n=r.filter(function(t){return"messageTextElement"===t.type||"argumentElement"===t.type}).map(function(t){return"messageTextElement"===t.type?e.compileMessageText(t):e.compileArgument(t)});if(n.length!==r.length)throw new Error("Message element does not have a valid type");return n},t.prototype.compileMessageText=function(t){return this.currentPlural&&/(^|[^\\])#/g.test(t.value)?(this.pluralNumberFormat||(this.pluralNumberFormat=new Intl.NumberFormat(this.locales)),new PluralOffsetString(this.currentPlural.id,this.currentPlural.format.offset,this.pluralNumberFormat,t.value)):t.value.replace(/\\#/g,"#")},t.prototype.compileArgument=function(t){var e=t.format,r=t.id,n=this.formatters;if(!e)return new StringFormat(r);var o=this.formats,a=this.locales;switch(e.type){case"numberFormat":return{id:r,format:n.getNumberFormat(a,o.number[e.style]).format};case"dateFormat":return{id:r,format:n.getDateTimeFormat(a,o.date[e.style]).format};case"timeFormat":return{id:r,format:n.getDateTimeFormat(a,o.time[e.style]).format};case"pluralFormat":return new PluralFormat(r,e.offset,this.compileOptions(t),n.getPluralRules(a,{type:e.ordinal?"ordinal":"cardinal"}));case"selectFormat":return new SelectFormat(r,this.compileOptions(t));default:throw new Error("Message element does not have a valid format type")}},t.prototype.compileOptions=function(t){var r=this,e=t.format,n=e.options;this.pluralStack.push(this.currentPlural),this.currentPlural="pluralFormat"===e.type?t:null;var o=n.reduce(function(t,e){return t[e.selector]=r.compileMessage(e.value),t},{});return this.currentPlural=this.pluralStack.pop(),o},t}(),Formatter=function(t){this.id=t},StringFormat=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.format=function(t){return t||"number"==typeof t?"string"==typeof t?t:String(t):""},e}(Formatter),PluralFormat=function(){function t(t,e,r,n){this.id=t,this.offset=e,this.options=r,this.pluralRules=n}return t.prototype.getOption=function(t){var e=this.options;return e["="+t]||e[this.pluralRules.select(t-this.offset)]||e.other},t}(),PluralOffsetString=function(a){function t(t,e,r,n){var o=a.call(this,t)||this;return o.offset=e,o.numberFormat=r,o.string=n,o}return __extends(t,a),t.prototype.format=function(t){var e=this.numberFormat.format(t-this.offset);return this.string.replace(/(^|[^\\])#/g,"$1"+e).replace(/\\#/g,"#")},t}(Formatter),SelectFormat=function(){function t(t,e){this.id=t,this.options=e}return t.prototype.getOption=function(t){var e=this.options;return e[t]||e.other},t}();function isSelectOrPluralFormat(t){return!!t.options}var __extends$1=function(){var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),__assign=function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function resolveLocale(t){"string"==typeof t&&(t=[t]);try{return Intl.NumberFormat.supportedLocalesOf(t,{localeMatcher:"best fit"})[0]}catch(t){return IntlMessageFormat.defaultLocale}}function formatPatterns(t,e){for(var r="",n=0,o=t;n<o.length;n++){var a=o[n];if("string"!=typeof a){var i=a.id;if(!(e&&i in e))throw new FormatError("A value must be provided for: "+i,i);var s=e[i];isSelectOrPluralFormat(a)?r+=formatPatterns(a.getOption(s),e):r+=a.format(s)}else r+=a}return r}function mergeConfig(r,n){return n?__assign({},r||{},n||{},Object.keys(r).reduce(function(t,e){return t[e]=__assign({},r[e],n[e]||{}),t},{})):r}function mergeConfigs(r,n){return n?Object.keys(r).reduce(function(t,e){return t[e]=mergeConfig(r[e],n[e]),t},__assign({},r)):r}var FormatError=function(n){function t(t,e){var r=n.call(this,t)||this;return r.variableId=e,r}return __extends$1(t,n),t}(Error);function createDefaultFormatters(){return{getNumberFormat:function(){for(var t,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return new((t=Intl.NumberFormat).bind.apply(t,[void 0].concat(e)))},getDateTimeFormat:function(){for(var t,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return new((t=Intl.DateTimeFormat).bind.apply(t,[void 0].concat(e)))},getPluralRules:function(){for(var t,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return new((t=Intl.PluralRules).bind.apply(t,[void 0].concat(e)))}}}var IntlMessageFormat=function(){function s(t,e,r,n){var o=this;if(void 0===e&&(e=s.defaultLocale),this.format=function(t){try{return formatPatterns(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}},"string"==typeof t){if(!s.__parse)throw new TypeError("IntlMessageFormat.__parse must be set to process `message` of type `string`");this.ast=s.__parse(t)}else this.ast=t;if(this.message=t,!this.ast||"messageFormatPattern"!==this.ast.type)throw new TypeError("A message must be provided as a String or AST.");var a=mergeConfigs(s.formats,r);this.locale=resolveLocale(e||[]);var i=n&&n.formatters||createDefaultFormatters();this.pattern=new Compiler(e,a,i).compile(this.ast)}return s.prototype.resolvedOptions=function(){return{locale:this.locale}},s.prototype.getAst=function(){return this.ast},s.defaultLocale="en",s.__parse=void 0,s.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"}}},s}();exports.IntlMessageFormat=IntlMessageFormat,exports.createDefaultFormatters=createDefaultFormatters,exports.default=IntlMessageFormat;
@@ -4,6 +4,11 @@ export interface Formats {
4
4
  date: Record<string, Intl.DateTimeFormatOptions>;
5
5
  time: Record<string, Intl.DateTimeFormatOptions>;
6
6
  }
7
+ export interface Formatters {
8
+ getNumberFormat(...args: ConstructorParameters<typeof Intl.NumberFormat>): Intl.NumberFormat;
9
+ getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
10
+ getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
11
+ }
7
12
  export declare type Pattern = string | PluralOffsetString | PluralFormat | SelectFormat | StringFormat;
8
13
  export default class Compiler {
9
14
  private locales;
@@ -11,7 +16,8 @@ export default class Compiler {
11
16
  private pluralNumberFormat;
12
17
  private currentPlural;
13
18
  private pluralStack;
14
- constructor(locales: string | string[], formats: Formats);
19
+ private formatters;
20
+ constructor(locales: string | string[], formats: Formats, formatters: Formatters);
15
21
  compile(ast: MessageFormatPattern): Pattern[];
16
22
  compileMessage(ast: MessageFormatPattern): Pattern[];
17
23
  compileMessageText(element: MessageTextElement): string | PluralOffsetString;
@@ -23,15 +29,15 @@ declare abstract class Formatter {
23
29
  constructor(id: string);
24
30
  abstract format(value: string | number): string;
25
31
  }
26
- export declare class StringFormat extends Formatter {
32
+ declare class StringFormat extends Formatter {
27
33
  format(value: number | string): string;
28
34
  }
29
- export declare class PluralFormat {
35
+ declare class PluralFormat {
30
36
  id: string;
31
37
  private offset;
32
38
  private options;
33
39
  private pluralRules;
34
- constructor(id: string, useOrdinal: boolean, offset: number, options: Record<string, Pattern[]>, locales: string | string[]);
40
+ constructor(id: string, offset: number, options: Record<string, Pattern[]>, pluralRules: Intl.PluralRules);
35
41
  getOption(value: number): Pattern[];
36
42
  }
37
43
  export declare class PluralOffsetString extends Formatter {
package/dist/compiler.js CHANGED
@@ -19,7 +19,7 @@ var __extends = (this && this.__extends) || (function () {
19
19
  })();
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  var Compiler = /** @class */ (function () {
22
- function Compiler(locales, formats) {
22
+ function Compiler(locales, formats, formatters) {
23
23
  this.locales = [];
24
24
  this.formats = {
25
25
  number: {},
@@ -31,6 +31,7 @@ var Compiler = /** @class */ (function () {
31
31
  this.pluralStack = [];
32
32
  this.locales = locales;
33
33
  this.formats = formats;
34
+ this.formatters = formatters;
34
35
  }
35
36
  Compiler.prototype.compile = function (ast) {
36
37
  this.pluralStack = [];
@@ -75,6 +76,7 @@ var Compiler = /** @class */ (function () {
75
76
  };
76
77
  Compiler.prototype.compileArgument = function (element) {
77
78
  var format = element.format, id = element.id;
79
+ var formatters = this.formatters;
78
80
  if (!format) {
79
81
  return new StringFormat(id);
80
82
  }
@@ -83,23 +85,22 @@ var Compiler = /** @class */ (function () {
83
85
  case 'numberFormat':
84
86
  return {
85
87
  id: id,
86
- format: new Intl.NumberFormat(locales, formats.number[format.style])
87
- .format
88
+ format: formatters.getNumberFormat(locales, formats.number[format.style]).format
88
89
  };
89
90
  case 'dateFormat':
90
91
  return {
91
92
  id: id,
92
- format: new Intl.DateTimeFormat(locales, formats.date[format.style])
93
- .format
93
+ format: formatters.getDateTimeFormat(locales, formats.date[format.style]).format
94
94
  };
95
95
  case 'timeFormat':
96
96
  return {
97
97
  id: id,
98
- format: new Intl.DateTimeFormat(locales, formats.time[format.style])
99
- .format
98
+ format: formatters.getDateTimeFormat(locales, formats.time[format.style]).format
100
99
  };
101
100
  case 'pluralFormat':
102
- return new PluralFormat(id, format.ordinal, format.offset, this.compileOptions(element), locales);
101
+ return new PluralFormat(id, format.offset, this.compileOptions(element), formatters.getPluralRules(locales, {
102
+ type: format.ordinal ? 'ordinal' : 'cardinal'
103
+ }));
103
104
  case 'selectFormat':
104
105
  return new SelectFormat(id, this.compileOptions(element));
105
106
  default:
@@ -147,15 +148,12 @@ var StringFormat = /** @class */ (function (_super) {
147
148
  };
148
149
  return StringFormat;
149
150
  }(Formatter));
150
- exports.StringFormat = StringFormat;
151
151
  var PluralFormat = /** @class */ (function () {
152
- function PluralFormat(id, useOrdinal, offset, options, locales) {
152
+ function PluralFormat(id, offset, options, pluralRules) {
153
153
  this.id = id;
154
154
  this.offset = offset;
155
155
  this.options = options;
156
- this.pluralRules = new Intl.PluralRules(locales, {
157
- type: useOrdinal ? 'ordinal' : 'cardinal'
158
- });
156
+ this.pluralRules = pluralRules;
159
157
  }
160
158
  PluralFormat.prototype.getOption = function (value) {
161
159
  var options = this.options;
@@ -165,7 +163,6 @@ var PluralFormat = /** @class */ (function () {
165
163
  };
166
164
  return PluralFormat;
167
165
  }());
168
- exports.PluralFormat = PluralFormat;
169
166
  var PluralOffsetString = /** @class */ (function (_super) {
170
167
  __extends(PluralOffsetString, _super);
171
168
  function PluralOffsetString(id, offset, numberFormat, string) {
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":";AAAA;;;;EAIE;;;;;;;;;;;;;;;AAuBF;IAWE,kBAAY,OAA0B,EAAE,OAAgB;QAVhD,YAAO,GAAsB,EAAE,CAAC;QAChC,YAAO,GAAY;YACzB,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,EAAE;SACT,CAAC;QACM,uBAAkB,GAA6B,IAAI,CAAC;QACpD,kBAAa,GAAuC,IAAI,CAAC;QACzD,gBAAW,GAA8C,EAAE,CAAC;QAGlE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,0BAAO,GAAP,UAAQ,GAAyB;QAC/B,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAE/B,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,iCAAc,GAAd,UAAe,GAAyB;QAAxC,iBAoBC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OAAO,CAAC,aAAa,EAAE,IAAI,GAAG,MAAM,CAAC;aACrC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,CAAC;IACH,yBAAC;AAAD,CAAC,AAvBD,CAAwC,SAAS,GAuBhD;AAvBY,gDAAkB;AAyB/B;IAGE,sBAAY,EAAU,EAAE,OAAkC;QACxD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,gCAAS,GAAT,UAAU,KAAa;QACb,IAAA,sBAAO,CAAU;QACzB,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC;IACzC,CAAC;IACH,mBAAC;AAAD,CAAC,AAZD,IAYC;AAZY,oCAAY;AAczB,SAAgB,sBAAsB,CACpC,CAAM;IAEN,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACrB,CAAC;AAJD,wDAIC"}
package/dist/core.d.ts ADDED
@@ -0,0 +1,78 @@
1
+ import { Formats, Formatters } from './compiler';
2
+ import parser, { MessageFormatPattern } from 'intl-messageformat-parser';
3
+ export interface Options {
4
+ formatters?: Formatters;
5
+ }
6
+ export declare function createDefaultFormatters(): Formatters;
7
+ export declare class IntlMessageFormat {
8
+ private ast;
9
+ private locale;
10
+ private pattern;
11
+ private message;
12
+ constructor(message: string | MessageFormatPattern, locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
13
+ format: (values?: Record<string, string | number | boolean | null | undefined> | undefined) => string;
14
+ resolvedOptions(): {
15
+ locale: string;
16
+ };
17
+ getAst(): MessageFormatPattern;
18
+ static defaultLocale: string;
19
+ static __parse: typeof parser['parse'] | undefined;
20
+ static formats: {
21
+ number: {
22
+ currency: {
23
+ style: string;
24
+ };
25
+ percent: {
26
+ style: string;
27
+ };
28
+ };
29
+ date: {
30
+ short: {
31
+ month: string;
32
+ day: string;
33
+ year: string;
34
+ };
35
+ medium: {
36
+ month: string;
37
+ day: string;
38
+ year: string;
39
+ };
40
+ long: {
41
+ month: string;
42
+ day: string;
43
+ year: string;
44
+ };
45
+ full: {
46
+ weekday: string;
47
+ month: string;
48
+ day: string;
49
+ year: string;
50
+ };
51
+ };
52
+ time: {
53
+ short: {
54
+ hour: string;
55
+ minute: string;
56
+ };
57
+ medium: {
58
+ hour: string;
59
+ minute: string;
60
+ second: string;
61
+ };
62
+ long: {
63
+ hour: string;
64
+ minute: string;
65
+ second: string;
66
+ timeZoneName: string;
67
+ };
68
+ full: {
69
+ hour: string;
70
+ minute: string;
71
+ second: string;
72
+ timeZoneName: string;
73
+ };
74
+ };
75
+ };
76
+ }
77
+ export { Formats, Pattern } from './compiler';
78
+ export default IntlMessageFormat;