You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 4, 2020. It is now read-only.
***intl-messageformat-parser:** Escape double-' to a single ' ([#103](https://github.com/formatjs/formatjs/issues/103)) ([4d0cd1f](https://github.com/formatjs/formatjs/commit/4d0cd1f))
12
-
13
-
14
-
15
-
10
+
-**intl-messageformat-parser:** Escape double-' to a single ' ([#103](https://github.com/formatjs/formatjs/issues/103)) ([4d0cd1f](https://github.com/formatjs/formatjs/commit/4d0cd1f))
Copy file name to clipboardExpand all lines: packages/intl-messageformat/README.md
+38-1Lines changed: 38 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ _Note: This `IntlMessageFormat` API may change to stay in sync with ECMA-402, bu
23
23
Messages are provided into the constructor as a `String` message, or a [pre-parsed AST][parser] object.
24
24
25
25
```js
26
-
var msg =newIntlMessageFormat(message, locales, [formats]);
26
+
var msg =newIntlMessageFormat(message, locales, [formats], [opts]);
27
27
```
28
28
29
29
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.
@@ -122,6 +122,9 @@ To create a message to format, use the `IntlMessageFormat` constructor. The cons
122
122
123
123
-**[formats]** - _{Object}_ - Optional object with user defined options for format styles.
-`formatters`: Map containing memoized formatters for performance.
127
+
125
128
```js
126
129
var msg =newIntlMessageFormat('My name is {name}.', 'en-US');
127
130
```
@@ -178,6 +181,8 @@ In this example, we're defining a `USD` number format style which is passed to t
178
181
179
182
## Advanced Usage
180
183
184
+
### Core entry point
185
+
181
186
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:
182
187
183
188
```ts
@@ -193,6 +198,25 @@ new IntlMessageFormat(parser.parse('hello')).format(); // prints out hello
193
198
194
199
This helps performance for cases like SSR or preload/precompilation-supported platforms since `AST` can be cached.
195
200
201
+
### Formatters
202
+
203
+
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.
0 commit comments