intl-messageformat 10.1.1 → 10.1.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/BUILD +126 -0
- package/CHANGELOG.md +1141 -0
- package/LICENSE.md +0 -0
- package/README.md +0 -0
- package/index.ts +11 -0
- package/package.json +5 -5
- package/src/core.ts +294 -0
- package/src/error.ts +65 -0
- package/src/formatters.ts +311 -0
- package/tests/benchmark.ts +103 -0
- package/tests/index.test.ts +968 -0
- package/tsconfig.json +5 -0
- package/index.d.ts +0 -6
- package/index.d.ts.map +0 -1
- package/index.js +0 -13
- package/intl-messageformat.esm.js +0 -3717
- package/intl-messageformat.iife.js +0 -3788
- package/lib/index.d.ts +0 -6
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -10
- package/lib/src/core.d.ts +0 -34
- package/lib/src/core.d.ts.map +0 -1
- package/lib/src/core.js +0 -240
- package/lib/src/error.d.ts +0 -28
- package/lib/src/error.d.ts.map +0 -1
- package/lib/src/error.js +0 -48
- package/lib/src/formatters.d.ts +0 -47
- package/lib/src/formatters.d.ts.map +0 -1
- package/lib/src/formatters.js +0 -177
- package/src/core.d.ts +0 -34
- package/src/core.d.ts.map +0 -1
- package/src/core.js +0 -243
- package/src/error.d.ts +0 -28
- package/src/error.d.ts.map +0 -1
- package/src/error.js +0 -51
- package/src/formatters.d.ts +0 -47
- package/src/formatters.d.ts.map +0 -1
- package/src/formatters.js +0 -182
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {Suite, Event} from 'benchmark'
|
|
2
|
+
import IntlMessageFormat, {Formatters} from '..'
|
|
3
|
+
import '@formatjs/intl-pluralrules/polyfill'
|
|
4
|
+
import '@formatjs/intl-pluralrules/locale-data/en'
|
|
5
|
+
import memoize from '@formatjs/fast-memoize'
|
|
6
|
+
|
|
7
|
+
const msg =
|
|
8
|
+
'' +
|
|
9
|
+
'{gender_of_host, select, ' +
|
|
10
|
+
'female {' +
|
|
11
|
+
'{num_guests, plural, offset:1 ' +
|
|
12
|
+
'=0 {{host} does not give a party.}' +
|
|
13
|
+
'=1 {{host} invites {guest} to her party.}' +
|
|
14
|
+
'=2 {{host} invites {guest} and one other person to her party.}' +
|
|
15
|
+
'other {{host} invites {guest} and {num_guests,number} other people to her party.}}}' +
|
|
16
|
+
'male {' +
|
|
17
|
+
'{num_guests, plural, offset:1 ' +
|
|
18
|
+
'=0 {{host} does not give a party.}' +
|
|
19
|
+
'=1 {{host} invites {guest} to his party.}' +
|
|
20
|
+
'=2 {{host} invites {guest} and one other person to his party.}' +
|
|
21
|
+
'other {{host} invites {guest} and {num_guests,number} other people to his party.}}}' +
|
|
22
|
+
'other {' +
|
|
23
|
+
'{num_guests, plural, offset:1 ' +
|
|
24
|
+
'=0 {{host} does not give a party.}' +
|
|
25
|
+
'=1 {{host} invites {guest} to their party.}' +
|
|
26
|
+
'=2 {{host} invites {guest} and one other person to their party.}' +
|
|
27
|
+
'other {{host} invites {guest} and {num_guests,number} other people to their party.}}}}'
|
|
28
|
+
|
|
29
|
+
const mf = new IntlMessageFormat(msg, 'en-US')
|
|
30
|
+
const stringMsg = 'Hello, world!'
|
|
31
|
+
const stringMf = new IntlMessageFormat(stringMsg, 'en-US')
|
|
32
|
+
|
|
33
|
+
const preparsedMsg = IntlMessageFormat.__parse!(msg)
|
|
34
|
+
|
|
35
|
+
const formatters: Formatters = {
|
|
36
|
+
getNumberFormat: memoize(Intl.NumberFormat),
|
|
37
|
+
getDateTimeFormat: memoize(Intl.DateTimeFormat),
|
|
38
|
+
getPluralRules: memoize(Intl.PluralRules),
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
new Suite()
|
|
42
|
+
.add('format_cached_complex_msg', () =>
|
|
43
|
+
mf.format({
|
|
44
|
+
gender_of_host: 'male',
|
|
45
|
+
num_guests: 10,
|
|
46
|
+
host: 'Eric',
|
|
47
|
+
guest: 'Caridy',
|
|
48
|
+
})
|
|
49
|
+
)
|
|
50
|
+
.add('format_cached_string_msg', () => stringMf.format())
|
|
51
|
+
.add(
|
|
52
|
+
'new_complex_msg_preparsed',
|
|
53
|
+
() => new IntlMessageFormat(preparsedMsg, 'en-US')
|
|
54
|
+
)
|
|
55
|
+
.add('new_complex_msg', () => new IntlMessageFormat(msg, 'en-US'))
|
|
56
|
+
.add('new_string_msg', () => new IntlMessageFormat(stringMsg, 'en-US'))
|
|
57
|
+
.add('complex msg format', () =>
|
|
58
|
+
new IntlMessageFormat(msg, 'en-US').format({
|
|
59
|
+
gender_of_host: 'male',
|
|
60
|
+
num_guests: 2,
|
|
61
|
+
host: 'foo',
|
|
62
|
+
guest: 'bar',
|
|
63
|
+
})
|
|
64
|
+
)
|
|
65
|
+
.add('complex msg w/ formatters format', () =>
|
|
66
|
+
new IntlMessageFormat(msg, 'en-US', undefined, {formatters}).format({
|
|
67
|
+
gender_of_host: 'male',
|
|
68
|
+
num_guests: 2,
|
|
69
|
+
host: 'foo',
|
|
70
|
+
guest: 'bar',
|
|
71
|
+
})
|
|
72
|
+
)
|
|
73
|
+
.add('complex preparsed msg w/ formatters format', () =>
|
|
74
|
+
new IntlMessageFormat(preparsedMsg, 'en-US', undefined, {
|
|
75
|
+
formatters,
|
|
76
|
+
}).format({
|
|
77
|
+
gender_of_host: 'male',
|
|
78
|
+
num_guests: 2,
|
|
79
|
+
host: 'foo',
|
|
80
|
+
guest: 'bar',
|
|
81
|
+
})
|
|
82
|
+
)
|
|
83
|
+
.add('complex preparsed msg w/ new formatters format', () =>
|
|
84
|
+
new IntlMessageFormat(preparsedMsg, 'en-US', undefined, {
|
|
85
|
+
formatters: {
|
|
86
|
+
getNumberFormat: formatters.getNumberFormat,
|
|
87
|
+
getDateTimeFormat: formatters.getDateTimeFormat,
|
|
88
|
+
getPluralRules: formatters.getPluralRules,
|
|
89
|
+
},
|
|
90
|
+
}).format({
|
|
91
|
+
gender_of_host: 'male',
|
|
92
|
+
num_guests: 2,
|
|
93
|
+
host: 'foo',
|
|
94
|
+
guest: 'bar',
|
|
95
|
+
})
|
|
96
|
+
)
|
|
97
|
+
.on('error', function (event: Event) {
|
|
98
|
+
console.log(String(event.target))
|
|
99
|
+
})
|
|
100
|
+
.on('cycle', function (event: Event) {
|
|
101
|
+
console.log(String(event.target))
|
|
102
|
+
})
|
|
103
|
+
.run()
|