react-intl 6.0.5 → 6.0.6
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 +130 -0
- package/CHANGELOG.md +1384 -0
- package/LICENSE.md +0 -0
- package/README.md +0 -0
- package/example-sandboxes/rescripts/.rescriptsrc.js +28 -0
- package/example-sandboxes/rescripts/package-lock.json +18035 -0
- package/example-sandboxes/rescripts/package.json +35 -0
- package/example-sandboxes/rescripts/public/index.html +42 -0
- package/example-sandboxes/rescripts/src/App.tsx +16 -0
- package/example-sandboxes/rescripts/src/index.tsx +5 -0
- package/example-sandboxes/rescripts/src/react-app-env.d.ts +1 -0
- package/example-sandboxes/rescripts/src/styles.css +4 -0
- package/example-sandboxes/rescripts/tsconfig.json +20 -0
- package/example-sandboxes/strict-locale-type/.env +1 -0
- package/example-sandboxes/strict-locale-type/package-lock.json +14595 -0
- package/example-sandboxes/strict-locale-type/package.json +35 -0
- package/example-sandboxes/strict-locale-type/src/App.tsx +48 -0
- package/example-sandboxes/strict-locale-type/src/index.html +28 -0
- package/example-sandboxes/strict-locale-type/src/index.tsx +7 -0
- package/example-sandboxes/strict-locale-type/src/styles.css +4 -0
- package/example-sandboxes/strict-locale-type/tsconfig.json +7 -0
- package/example-sandboxes/strict-message-types/.env +1 -0
- package/example-sandboxes/strict-message-types/package-lock.json +14596 -0
- package/example-sandboxes/strict-message-types/package.json +35 -0
- package/example-sandboxes/strict-message-types/src/App.tsx +31 -0
- package/example-sandboxes/strict-message-types/src/index.html +28 -0
- package/example-sandboxes/strict-message-types/src/index.tsx +7 -0
- package/example-sandboxes/strict-message-types/src/styles.css +4 -0
- package/example-sandboxes/strict-message-types/tsconfig.json +7 -0
- package/examples/BUILD +70 -0
- package/examples/Bug2727.tsx +37 -0
- package/examples/HandleChange.tsx +48 -0
- package/examples/Hooks.tsx +126 -0
- package/examples/Injected.tsx +41 -0
- package/examples/Messages.tsx +82 -0
- package/examples/StaticTypeSafetyAndCodeSplitting/StaticTypeSafetyAndCodeSplitting.tsx +44 -0
- package/examples/StaticTypeSafetyAndCodeSplitting/en.json +3 -0
- package/examples/StaticTypeSafetyAndCodeSplitting/intlHelpers.tsx +39 -0
- package/examples/StaticTypeSafetyAndCodeSplitting/it.json +3 -0
- package/examples/TimeZone.tsx +44 -0
- package/examples/advanced/Advanced.tsx +68 -0
- package/examples/advanced/compiled-lang/en.json +77 -0
- package/examples/advanced/compiled-lang/fr.json +77 -0
- package/examples/index.html +20 -0
- package/examples/index.tsx +44 -0
- package/examples/package.json +20 -0
- package/index.ts +127 -0
- package/jest.config.js +27 -0
- package/package.json +12 -8
- package/src/components/createFormattedComponent.tsx +123 -0
- package/src/components/dateTimeRange.tsx +26 -0
- package/src/components/injectIntl.tsx +111 -0
- package/src/components/message.tsx +73 -0
- package/src/components/plural.tsx +45 -0
- package/src/components/provider.tsx +196 -0
- package/src/components/relative.tsx +192 -0
- package/src/components/useIntl.ts +10 -0
- package/src/types.ts +29 -0
- package/src/utils.ts +77 -0
- package/tests/functional/index.ts +18 -0
- package/tests/functional/support/build.ts +16 -0
- package/tests/functional/support/format.tsx +112 -0
- package/tests/perf/index.tsx +196 -0
- package/tests/setup.js +10 -0
- package/tests/unit/components/__snapshots__/displayName.tsx.snap +19 -0
- package/tests/unit/components/__snapshots__/message.tsx.snap +41 -0
- package/tests/unit/components/__snapshots__/relative.tsx.snap +11 -0
- package/tests/unit/components/__snapshots__/useIntl.tsx.snap +25 -0
- package/tests/unit/components/date.tsx +233 -0
- package/tests/unit/components/dateTimeRange.tsx +103 -0
- package/tests/unit/components/displayName.tsx +57 -0
- package/tests/unit/components/message.tsx +509 -0
- package/tests/unit/components/number.tsx +198 -0
- package/tests/unit/components/plural.tsx +116 -0
- package/tests/unit/components/provider.tsx +215 -0
- package/tests/unit/components/relative.tsx +263 -0
- package/tests/unit/components/time.tsx +242 -0
- package/tests/unit/components/useIntl.tsx +64 -0
- package/tests/unit/components/withIntl.tsx +66 -0
- package/tests/unit/react-intl.ts +88 -0
- package/tests/unit/testUtils.tsx +42 -0
- package/tsconfig.json +5 -0
- package/index.d.ts +0 -43
- package/index.d.ts.map +0 -1
- package/index.js +0 -51
- package/lib/index.d.ts +0 -43
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -26
- package/lib/src/components/createFormattedComponent.d.ts +0 -29
- package/lib/src/components/createFormattedComponent.d.ts.map +0 -1
- package/lib/src/components/createFormattedComponent.js +0 -62
- package/lib/src/components/dateTimeRange.d.ts +0 -11
- package/lib/src/components/dateTimeRange.d.ts.map +0 -1
- package/lib/src/components/dateTimeRange.js +0 -15
- package/lib/src/components/injectIntl.d.ts +0 -22
- package/lib/src/components/injectIntl.d.ts.map +0 -1
- package/lib/src/components/injectIntl.js +0 -29
- package/lib/src/components/message.d.ts +0 -12
- package/lib/src/components/message.d.ts.map +0 -1
- package/lib/src/components/message.js +0 -35
- package/lib/src/components/plural.d.ts +0 -15
- package/lib/src/components/plural.d.ts.map +0 -1
- package/lib/src/components/plural.js +0 -26
- package/lib/src/components/provider.d.ts +0 -35
- package/lib/src/components/provider.d.ts.map +0 -1
- package/lib/src/components/provider.js +0 -108
- package/lib/src/components/relative.d.ts +0 -12
- package/lib/src/components/relative.d.ts.map +0 -1
- package/lib/src/components/relative.js +0 -129
- package/lib/src/components/useIntl.d.ts +0 -3
- package/lib/src/components/useIntl.d.ts.map +0 -1
- package/lib/src/components/useIntl.js +0 -8
- package/lib/src/types.d.ts +0 -12
- package/lib/src/types.d.ts.map +0 -1
- package/lib/src/types.js +0 -1
- package/lib/src/utils.d.ts +0 -14
- package/lib/src/utils.d.ts.map +0 -1
- package/lib/src/utils.js +0 -43
- package/react-intl.iife.js +0 -7485
- package/src/components/createFormattedComponent.d.ts +0 -29
- package/src/components/createFormattedComponent.d.ts.map +0 -1
- package/src/components/createFormattedComponent.js +0 -69
- package/src/components/dateTimeRange.d.ts +0 -11
- package/src/components/dateTimeRange.d.ts.map +0 -1
- package/src/components/dateTimeRange.js +0 -17
- package/src/components/injectIntl.d.ts +0 -22
- package/src/components/injectIntl.d.ts.map +0 -1
- package/src/components/injectIntl.js +0 -33
- package/src/components/message.d.ts +0 -12
- package/src/components/message.d.ts.map +0 -1
- package/src/components/message.js +0 -37
- package/src/components/plural.d.ts +0 -15
- package/src/components/plural.d.ts.map +0 -1
- package/src/components/plural.js +0 -29
- package/src/components/provider.d.ts +0 -35
- package/src/components/provider.d.ts.map +0 -1
- package/src/components/provider.js +0 -112
- package/src/components/relative.d.ts +0 -12
- package/src/components/relative.d.ts.map +0 -1
- package/src/components/relative.js +0 -131
- package/src/components/useIntl.d.ts +0 -3
- package/src/components/useIntl.d.ts.map +0 -1
- package/src/components/useIntl.js +0 -12
- package/src/types.d.ts +0 -12
- package/src/types.d.ts.map +0 -1
- package/src/types.js +0 -2
- package/src/utils.d.ts +0 -14
- package/src/utils.d.ts.map +0 -1
- package/src/utils.js +0 -49
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {FormattedTime, FormattedTimeParts} from '../../../'
|
|
3
|
+
import {mountFormattedComponentWithProvider} from '../testUtils'
|
|
4
|
+
import {createIntl} from '../../../src/components/provider'
|
|
5
|
+
import {IntlShape} from '@formatjs/intl'
|
|
6
|
+
import {render} from '@testing-library/react'
|
|
7
|
+
|
|
8
|
+
const mountWithProvider = mountFormattedComponentWithProvider(FormattedTime)
|
|
9
|
+
const mountPartsWithProvider =
|
|
10
|
+
mountFormattedComponentWithProvider(FormattedTimeParts)
|
|
11
|
+
|
|
12
|
+
describe('<FormattedTime>', () => {
|
|
13
|
+
let intl: IntlShape<React.ReactNode>
|
|
14
|
+
const onError = jest.fn()
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
onError.mockClear()
|
|
17
|
+
intl = createIntl({
|
|
18
|
+
locale: 'en',
|
|
19
|
+
onError,
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('has a `displayName`', () => {
|
|
24
|
+
expect(typeof FormattedTime.displayName).toBe('string')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('throws when <IntlProvider> is missing from ancestry', () => {
|
|
28
|
+
// So it doesn't spam the console
|
|
29
|
+
jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
30
|
+
expect(() => render(<FormattedTime value={0} />)).toThrow(
|
|
31
|
+
'[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.'
|
|
32
|
+
)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('requires a finite `value` prop', () => {
|
|
36
|
+
const {rerenderProps} = mountWithProvider({value: 0}, intl)
|
|
37
|
+
expect(onError).not.toHaveBeenCalled()
|
|
38
|
+
|
|
39
|
+
rerenderProps(
|
|
40
|
+
{
|
|
41
|
+
value: NaN,
|
|
42
|
+
},
|
|
43
|
+
intl
|
|
44
|
+
)
|
|
45
|
+
expect(onError).toHaveBeenCalledTimes(1)
|
|
46
|
+
expect(onError.mock.calls[0][0].code).toBe('FORMAT_ERROR')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('renders a formatted time in a <>', () => {
|
|
50
|
+
const date = new Date()
|
|
51
|
+
|
|
52
|
+
const {getByTestId} = mountWithProvider({value: date}, intl)
|
|
53
|
+
|
|
54
|
+
expect(getByTestId('comp')).toHaveTextContent(intl.formatTime(date))
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('renders a formatted time w/o textComponent', () => {
|
|
58
|
+
const date = new Date()
|
|
59
|
+
|
|
60
|
+
const {getByTestId} = mountWithProvider(
|
|
61
|
+
{value: date},
|
|
62
|
+
{
|
|
63
|
+
...intl,
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
textComponent: null,
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
expect(getByTestId('comp')).toHaveTextContent(intl.formatTime(date))
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('accepts valid Intl.DateTimeFormat options as props', () => {
|
|
73
|
+
const date = Date.now()
|
|
74
|
+
const options: Intl.DateTimeFormatOptions = {hour: '2-digit'}
|
|
75
|
+
|
|
76
|
+
const {getByTestId} = mountWithProvider({value: date, ...options}, intl)
|
|
77
|
+
|
|
78
|
+
expect(getByTestId('comp')).toHaveTextContent(
|
|
79
|
+
intl.formatTime(date, options)
|
|
80
|
+
)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('falls back and warns on invalid Intl.DateTimeFormat options', () => {
|
|
84
|
+
const date = new Date()
|
|
85
|
+
|
|
86
|
+
const {getByTestId} = mountWithProvider(
|
|
87
|
+
// @ts-expect-error invalid for testing
|
|
88
|
+
{value: date, hour: 'invalid'},
|
|
89
|
+
intl
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
expect(getByTestId('comp')).toHaveTextContent(String(date))
|
|
93
|
+
expect(onError.mock.calls[0][0].code).toBe('FORMAT_ERROR')
|
|
94
|
+
expect(onError).toHaveBeenCalledTimes(1)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('accepts `format` prop', () => {
|
|
98
|
+
intl = createIntl({
|
|
99
|
+
onError: () => {},
|
|
100
|
+
locale: 'en',
|
|
101
|
+
formats: {
|
|
102
|
+
time: {
|
|
103
|
+
'hour-only': {
|
|
104
|
+
hour: '2-digit',
|
|
105
|
+
hour12: false,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
const date = Date.now()
|
|
112
|
+
const format = 'hour-only'
|
|
113
|
+
|
|
114
|
+
const {getByTestId} = mountWithProvider({value: date, format}, intl)
|
|
115
|
+
|
|
116
|
+
expect(getByTestId('comp')).toHaveTextContent(
|
|
117
|
+
intl.formatTime(date, {format})
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('supports function-as-child pattern', () => {
|
|
122
|
+
const date = Date.now()
|
|
123
|
+
|
|
124
|
+
const spy = jest.fn().mockImplementation(() => <b data-testid="b">Jest</b>)
|
|
125
|
+
const {getByTestId} = mountWithProvider({value: date, children: spy}, intl)
|
|
126
|
+
|
|
127
|
+
expect(getByTestId('b').tagName).toBe('B')
|
|
128
|
+
expect(getByTestId('comp')).toHaveTextContent('Jest')
|
|
129
|
+
|
|
130
|
+
expect(spy).toHaveBeenCalledTimes(1)
|
|
131
|
+
expect(spy.mock.calls[0]).toEqual([intl.formatTime(date)])
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
describe('<FormattedTimeParts>', () => {
|
|
136
|
+
let intl: IntlShape<React.ReactNode>
|
|
137
|
+
const children = jest.fn(
|
|
138
|
+
parts => (Array.isArray(parts) && parts[0] && parts[0].value) || null
|
|
139
|
+
)
|
|
140
|
+
const onError = jest.fn()
|
|
141
|
+
beforeEach(() => {
|
|
142
|
+
onError.mockClear()
|
|
143
|
+
intl = createIntl({
|
|
144
|
+
locale: 'en',
|
|
145
|
+
onError,
|
|
146
|
+
})
|
|
147
|
+
children.mockClear()
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('has a `displayName`', () => {
|
|
151
|
+
expect(FormattedTimeParts.displayName).toBe('FormattedTimeParts')
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('throws when <IntlProvider> is missing from ancestry', () => {
|
|
155
|
+
// So it doesn't spam the console
|
|
156
|
+
jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
157
|
+
expect(() =>
|
|
158
|
+
render(<FormattedTimeParts value={0} children={children} />)
|
|
159
|
+
).toThrow(
|
|
160
|
+
'[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.'
|
|
161
|
+
)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('requires a finite `value` prop', () => {
|
|
165
|
+
const {rerenderProps} = mountPartsWithProvider({value: 0, children}, intl)
|
|
166
|
+
expect(onError).not.toHaveBeenCalled()
|
|
167
|
+
|
|
168
|
+
rerenderProps(
|
|
169
|
+
{
|
|
170
|
+
children,
|
|
171
|
+
value: NaN,
|
|
172
|
+
},
|
|
173
|
+
intl
|
|
174
|
+
)
|
|
175
|
+
expect(onError.mock.calls[0][0].code).toBe('FORMAT_ERROR')
|
|
176
|
+
expect(onError).toHaveBeenCalledTimes(1)
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('accepts valid Intl.DateTimeFormat options as props', () => {
|
|
180
|
+
const date = new Date(1567130870626)
|
|
181
|
+
const options: Intl.DateTimeFormatOptions = {hour: '2-digit'}
|
|
182
|
+
|
|
183
|
+
mountPartsWithProvider({value: date, children, ...options}, intl)
|
|
184
|
+
|
|
185
|
+
expect(children.mock.calls[0][0]).toEqual(
|
|
186
|
+
intl.formatTimeToParts(date, options)
|
|
187
|
+
)
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('renders a string date', () => {
|
|
191
|
+
const date = new Date()
|
|
192
|
+
|
|
193
|
+
mountPartsWithProvider({value: date.toISOString(), children}, intl)
|
|
194
|
+
|
|
195
|
+
expect(children.mock.calls[0][0]).toEqual(intl.formatTimeToParts(date))
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it('renders date 0 if value is ""', () => {
|
|
199
|
+
const date = new Date(0)
|
|
200
|
+
|
|
201
|
+
mountPartsWithProvider({value: '', children}, intl)
|
|
202
|
+
|
|
203
|
+
expect(children.mock.calls[0][0]).toEqual(intl.formatTimeToParts(date))
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('falls back and warns on invalid Intl.DateTimeFormat options', () => {
|
|
207
|
+
const date = new Date(1567130870626)
|
|
208
|
+
|
|
209
|
+
// @ts-expect-error invalid for testing
|
|
210
|
+
mountPartsWithProvider({value: date, hour: 'invalid', children}, intl)
|
|
211
|
+
expect(children.mock.calls[0][0]).toEqual(
|
|
212
|
+
// @ts-expect-error invalid for testing
|
|
213
|
+
intl.formatTimeToParts(date, {hour: 'invalid'})
|
|
214
|
+
)
|
|
215
|
+
expect(onError.mock.calls[0][0].code).toBe('FORMAT_ERROR')
|
|
216
|
+
expect(onError).toHaveBeenCalledTimes(2)
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('accepts `format` prop', () => {
|
|
220
|
+
intl = createIntl({
|
|
221
|
+
onError: () => {},
|
|
222
|
+
locale: 'en',
|
|
223
|
+
formats: {
|
|
224
|
+
time: {
|
|
225
|
+
'hour-only': {
|
|
226
|
+
hour: '2-digit',
|
|
227
|
+
hour12: false,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
const date = new Date(1567130870626)
|
|
234
|
+
const format = 'hour-only'
|
|
235
|
+
|
|
236
|
+
mountPartsWithProvider({value: date, format, children}, intl)
|
|
237
|
+
|
|
238
|
+
expect(children.mock.calls[0][0]).toEqual(
|
|
239
|
+
intl.formatTimeToParts(date, {format})
|
|
240
|
+
)
|
|
241
|
+
})
|
|
242
|
+
})
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {render} from '@testing-library/react'
|
|
3
|
+
import {IntlProvider} from '../../../'
|
|
4
|
+
import useIntl from '../../../src/components/useIntl'
|
|
5
|
+
|
|
6
|
+
const FunctionComponent = ({spy}: {spy?: Function}) => {
|
|
7
|
+
const hookReturns = useIntl()
|
|
8
|
+
spy!(hookReturns.locale)
|
|
9
|
+
return null
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const FC = () => {
|
|
13
|
+
const {formatNumber} = useIntl()
|
|
14
|
+
return formatNumber(10000, {style: 'currency', currency: 'USD'}) as any
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('useIntl() hook', () => {
|
|
18
|
+
it('throws when <IntlProvider> is missing from ancestry', () => {
|
|
19
|
+
// So it doesn't spam the console
|
|
20
|
+
jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
21
|
+
expect(() => render(<FunctionComponent />)).toThrow(
|
|
22
|
+
'[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.'
|
|
23
|
+
)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('hooks onto the intl context', () => {
|
|
27
|
+
const spy = jest.fn()
|
|
28
|
+
render(
|
|
29
|
+
<IntlProvider locale="en">
|
|
30
|
+
<FunctionComponent spy={spy} />
|
|
31
|
+
</IntlProvider>
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
expect(spy).toHaveBeenCalledWith('en')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should work when switching locale on provider', () => {
|
|
38
|
+
const {rerender, getByTestId} = render(
|
|
39
|
+
<IntlProvider locale="en">
|
|
40
|
+
<span data-testid="comp">
|
|
41
|
+
<FC />
|
|
42
|
+
</span>
|
|
43
|
+
</IntlProvider>
|
|
44
|
+
)
|
|
45
|
+
expect(getByTestId('comp')).toMatchSnapshot()
|
|
46
|
+
rerender(
|
|
47
|
+
<IntlProvider locale="es">
|
|
48
|
+
<span data-testid="comp">
|
|
49
|
+
<FC />
|
|
50
|
+
</span>
|
|
51
|
+
</IntlProvider>
|
|
52
|
+
)
|
|
53
|
+
expect(getByTestId('comp')).toMatchSnapshot()
|
|
54
|
+
rerender(
|
|
55
|
+
<IntlProvider locale="en">
|
|
56
|
+
<span data-testid="comp">
|
|
57
|
+
<FC />
|
|
58
|
+
</span>
|
|
59
|
+
</IntlProvider>
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
expect(getByTestId('comp')).toMatchSnapshot()
|
|
63
|
+
})
|
|
64
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import IntlProvider from '../../../src/components/provider'
|
|
3
|
+
import injectIntl, {
|
|
4
|
+
WrappedComponentProps,
|
|
5
|
+
} from '../../../src/components/injectIntl'
|
|
6
|
+
import {render} from '@testing-library/react'
|
|
7
|
+
import {IntlShape} from '@formatjs/intl'
|
|
8
|
+
|
|
9
|
+
const mountWithProvider = (el: JSX.Element) =>
|
|
10
|
+
render(<IntlProvider locale="en">{el}</IntlProvider>)
|
|
11
|
+
|
|
12
|
+
describe('injectIntl()', () => {
|
|
13
|
+
let Wrapped: React.FC<WrappedComponentProps>
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
Wrapped = ({intl}: {intl: IntlShape<React.ReactNode>}) => (
|
|
17
|
+
<div data-testid="comp">{JSON.stringify(intl)}</div>
|
|
18
|
+
)
|
|
19
|
+
Wrapped.displayName = 'Wrapped'
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
Wrapped.someNonReactStatic = {
|
|
22
|
+
foo: true,
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('allows introspection access to the wrapped component', () => {
|
|
27
|
+
expect(injectIntl(Wrapped).WrappedComponent).toBe(Wrapped)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('hoists non-react statics', () => {
|
|
31
|
+
expect((injectIntl(Wrapped) as any).someNonReactStatic.foo).toBe(true)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('displayName', () => {
|
|
35
|
+
it('is descriptive by default', () => {
|
|
36
|
+
expect(injectIntl(() => null).displayName).toBe('injectIntl(Component)')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it("includes `WrappedComponent`'s `displayName`", () => {
|
|
40
|
+
Wrapped.displayName = 'Foo'
|
|
41
|
+
expect(injectIntl(Wrapped).displayName).toBe('injectIntl(Foo)')
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('throws when <IntlProvider> is missing from ancestry', () => {
|
|
46
|
+
// So it doesn't spam the console
|
|
47
|
+
jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
48
|
+
const Injected = injectIntl(Wrapped)
|
|
49
|
+
|
|
50
|
+
expect(() => render(<Injected />)).toThrow(
|
|
51
|
+
'[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.'
|
|
52
|
+
)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('propagates all props to <WrappedComponent>', () => {
|
|
56
|
+
const Injected = injectIntl(Wrapped) as any
|
|
57
|
+
const props = {
|
|
58
|
+
foo: 'bar',
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const {getByTestId} = mountWithProvider(<Injected {...props} />)
|
|
62
|
+
expect(getByTestId('comp')).toHaveTextContent(
|
|
63
|
+
'{"formats":{},"messages":{},"defaultLocale":"en","defaultFormats":{},"fallbackOnEmptyString":true,"locale":"en","formatters":{}}'
|
|
64
|
+
)
|
|
65
|
+
})
|
|
66
|
+
})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as ReactIntl from '../../'
|
|
2
|
+
import * as ts from 'typescript'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import lexer from 'cjs-module-lexer'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
|
|
7
|
+
describe('react-intl', () => {
|
|
8
|
+
describe('exports', () => {
|
|
9
|
+
it('exports `defineMessages`', () => {
|
|
10
|
+
expect(typeof ReactIntl.defineMessages).toBe('function')
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('exports `defineMessage`', () => {
|
|
14
|
+
expect(typeof ReactIntl.defineMessage).toBe('function')
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('exports `injectIntl`', () => {
|
|
18
|
+
expect(typeof ReactIntl.injectIntl).toBe('function')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('exports `useIntl`', () => {
|
|
22
|
+
expect(typeof ReactIntl.useIntl).toBe('function')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('React Components', () => {
|
|
26
|
+
it('exports `IntlProvider`', () => {
|
|
27
|
+
expect(typeof ReactIntl.IntlProvider).toBe('function')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('exports `FormattedDate`', () => {
|
|
31
|
+
expect(typeof ReactIntl.FormattedDate).toBe('function')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('exports `FormattedTime`', () => {
|
|
35
|
+
expect(typeof ReactIntl.FormattedTime).toBe('function')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('exports `FormattedNumber`', () => {
|
|
39
|
+
expect(typeof ReactIntl.FormattedNumber).toBe('function')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('exports `FormattedDateParts`', () => {
|
|
43
|
+
expect(typeof ReactIntl.FormattedDateParts).toBe('function')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('exports `FormattedTimeParts`', () => {
|
|
47
|
+
expect(typeof ReactIntl.FormattedTimeParts).toBe('function')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('exports `FormattedNumberParts`', () => {
|
|
51
|
+
expect(typeof ReactIntl.FormattedNumberParts).toBe('function')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('exports `FormattedRelativeTime`', () => {
|
|
55
|
+
expect(typeof ReactIntl.FormattedRelativeTime).toBe('function')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('exports `FormattedPlural`', () => {
|
|
59
|
+
expect(typeof ReactIntl.FormattedPlural).toBe('function')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('exports `FormattedMessage`', () => {
|
|
63
|
+
expect(typeof ReactIntl.FormattedMessage).toBe('object')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('exports `FormattedDisplayNames`', () => {
|
|
67
|
+
expect(typeof ReactIntl.FormattedDisplayName).toBe('function')
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
describe('static analysis of named exports ', () => {
|
|
72
|
+
// Parse dist file for statically analyzable named exports
|
|
73
|
+
const filePath = path.resolve(__dirname, '..', '..', 'index.ts')
|
|
74
|
+
const source = fs.readFileSync(filePath, 'utf8')
|
|
75
|
+
const {outputText} = ts.transpileModule(source, {
|
|
76
|
+
compilerOptions: {
|
|
77
|
+
esModuleInterop: true,
|
|
78
|
+
module: ts.ModuleKind.CommonJS,
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
const parsed = lexer.parse(outputText)
|
|
82
|
+
const keys = Object.keys(ReactIntl)
|
|
83
|
+
|
|
84
|
+
it.each(keys)('has named export "%s"', key => {
|
|
85
|
+
expect(parsed.exports).toContain(key)
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import Provider from '../../src/components/provider'
|
|
3
|
+
import {render} from '@testing-library/react'
|
|
4
|
+
import type {IntlConfig} from '../../src/types'
|
|
5
|
+
|
|
6
|
+
export function mountFormattedComponentWithProvider<P>(
|
|
7
|
+
Comp: React.ComponentType<P>
|
|
8
|
+
) {
|
|
9
|
+
return (
|
|
10
|
+
props: P & {children?(nodes: React.ReactNode[]): React.ReactNode},
|
|
11
|
+
providerProps: IntlConfig = {locale: 'en'}
|
|
12
|
+
) => {
|
|
13
|
+
const result = render(
|
|
14
|
+
<React.StrictMode>
|
|
15
|
+
<Provider {...providerProps}>
|
|
16
|
+
<span data-testid="comp">
|
|
17
|
+
<Comp {...props} />
|
|
18
|
+
</span>
|
|
19
|
+
</Provider>
|
|
20
|
+
</React.StrictMode>
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const {rerender} = result
|
|
24
|
+
const rerenderProps = (
|
|
25
|
+
newProps: P & {
|
|
26
|
+
children?(nodes: React.ReactNode[]): React.ReactNode
|
|
27
|
+
} = props,
|
|
28
|
+
newProviderProps: IntlConfig = providerProps
|
|
29
|
+
) =>
|
|
30
|
+
rerender(
|
|
31
|
+
<React.StrictMode>
|
|
32
|
+
<Provider {...newProviderProps}>
|
|
33
|
+
<span data-testid="comp">
|
|
34
|
+
<Comp {...newProps} />
|
|
35
|
+
</span>
|
|
36
|
+
</Provider>
|
|
37
|
+
</React.StrictMode>
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return {...result, rerenderProps}
|
|
41
|
+
}
|
|
42
|
+
}
|
package/tsconfig.json
ADDED
package/index.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { MessageDescriptor, CustomFormatConfig, FormatDateOptions } from '@formatjs/intl';
|
|
3
|
-
import { IntlListFormatOptions } from '@formatjs/intl-listformat';
|
|
4
|
-
import { DisplayNamesOptions } from '@formatjs/intl-displaynames';
|
|
5
|
-
import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
|
|
6
|
-
import injectIntl, { Provider as RawIntlProvider, Context as IntlContext, WithIntlProps, WrappedComponentProps } from './src/components/injectIntl';
|
|
7
|
-
import useIntl from './src/components/useIntl';
|
|
8
|
-
import IntlProvider, { createIntl } from './src/components/provider';
|
|
9
|
-
import FormattedRelativeTime from './src/components/relative';
|
|
10
|
-
import FormattedPlural from './src/components/plural';
|
|
11
|
-
import FormattedMessage from './src/components/message';
|
|
12
|
-
import FormattedDateTimeRange from './src/components/dateTimeRange';
|
|
13
|
-
export { FormattedDateTimeRange, FormattedMessage, FormattedPlural, FormattedRelativeTime, IntlContext, IntlProvider, RawIntlProvider, WithIntlProps, WrappedComponentProps, createIntl, injectIntl, useIntl, };
|
|
14
|
-
export { IntlConfig, ResolvedIntlConfig, IntlShape } from './src/types';
|
|
15
|
-
export { createIntlCache, MessageDescriptor, IntlCache, Formatters, IntlFormatters, FormatDisplayNameOptions, FormatListOptions, FormatPluralOptions, FormatRelativeTimeOptions, FormatNumberOptions, FormatDateOptions, CustomFormatConfig, CustomFormats, UnsupportedFormatterError, InvalidConfigError, MissingDataError, MessageFormatError, MissingTranslationError, IntlErrorCode as ReactIntlErrorCode, IntlError as ReactIntlError, } from '@formatjs/intl';
|
|
16
|
-
export declare function defineMessages<K extends keyof any, T = MessageDescriptor, U extends Record<K, T> = Record<K, T>>(msgs: U): U;
|
|
17
|
-
export declare function defineMessage<T extends MessageDescriptor>(msg: T): T;
|
|
18
|
-
export declare const FormattedDate: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
19
|
-
value: string | number | Date | undefined;
|
|
20
|
-
}>;
|
|
21
|
-
export declare const FormattedTime: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
22
|
-
value: string | number | Date | undefined;
|
|
23
|
-
}>;
|
|
24
|
-
export declare const FormattedNumber: React.FC<NumberFormatOptions & CustomFormatConfig & {
|
|
25
|
-
value: number | bigint;
|
|
26
|
-
}>;
|
|
27
|
-
export declare const FormattedList: React.FC<IntlListFormatOptions & {
|
|
28
|
-
value: readonly React.ReactNode[];
|
|
29
|
-
}>;
|
|
30
|
-
export declare const FormattedDisplayName: React.FC<DisplayNamesOptions & {
|
|
31
|
-
value: string | number | Record<string, unknown>;
|
|
32
|
-
}>;
|
|
33
|
-
export declare const FormattedDateParts: React.FC<FormatDateOptions & {
|
|
34
|
-
value: Parameters<Intl.DateTimeFormat['format']>[0] | string;
|
|
35
|
-
children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
|
|
36
|
-
}>;
|
|
37
|
-
export declare const FormattedTimeParts: React.FC<FormatDateOptions & {
|
|
38
|
-
value: Parameters<Intl.DateTimeFormat['format']>[0] | string;
|
|
39
|
-
children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
|
|
40
|
-
}>;
|
|
41
|
-
export { FormattedNumberParts, FormattedListParts, } from './src/components/createFormattedComponent';
|
|
42
|
-
export type { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
|
|
43
|
-
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/react-intl/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,gBA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AAC,GAAG,EAAE,IAAI,CAAC,kBAAkB,EAAE,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CACpE,CACoD,CAAA;AACvD,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CACvC,iBAAiB,GAAG;IAClB,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAA;IAC5D,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,kBAAkB,EAAE,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CACpE,CACoD,CAAA;AAEvD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,2CAA2C,CAAA;AAClD,YAAY,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAA"}
|
package/index.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FormattedListParts = exports.FormattedNumberParts = exports.FormattedTimeParts = exports.FormattedDateParts = exports.FormattedDisplayName = exports.FormattedList = exports.FormattedNumber = exports.FormattedTime = exports.FormattedDate = exports.defineMessage = exports.defineMessages = exports.ReactIntlError = exports.ReactIntlErrorCode = exports.MissingTranslationError = exports.MessageFormatError = exports.MissingDataError = exports.InvalidConfigError = exports.UnsupportedFormatterError = exports.createIntlCache = exports.useIntl = exports.injectIntl = exports.createIntl = exports.RawIntlProvider = exports.IntlProvider = exports.IntlContext = exports.FormattedRelativeTime = exports.FormattedPlural = exports.FormattedMessage = exports.FormattedDateTimeRange = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var createFormattedComponent_1 = require("./src/components/createFormattedComponent");
|
|
6
|
-
var injectIntl_1 = (0, tslib_1.__importStar)(require("./src/components/injectIntl"));
|
|
7
|
-
exports.injectIntl = injectIntl_1.default;
|
|
8
|
-
Object.defineProperty(exports, "RawIntlProvider", { enumerable: true, get: function () { return injectIntl_1.Provider; } });
|
|
9
|
-
Object.defineProperty(exports, "IntlContext", { enumerable: true, get: function () { return injectIntl_1.Context; } });
|
|
10
|
-
var useIntl_1 = (0, tslib_1.__importDefault)(require("./src/components/useIntl"));
|
|
11
|
-
exports.useIntl = useIntl_1.default;
|
|
12
|
-
var provider_1 = (0, tslib_1.__importStar)(require("./src/components/provider"));
|
|
13
|
-
exports.IntlProvider = provider_1.default;
|
|
14
|
-
Object.defineProperty(exports, "createIntl", { enumerable: true, get: function () { return provider_1.createIntl; } });
|
|
15
|
-
var relative_1 = (0, tslib_1.__importDefault)(require("./src/components/relative"));
|
|
16
|
-
exports.FormattedRelativeTime = relative_1.default;
|
|
17
|
-
var plural_1 = (0, tslib_1.__importDefault)(require("./src/components/plural"));
|
|
18
|
-
exports.FormattedPlural = plural_1.default;
|
|
19
|
-
var message_1 = (0, tslib_1.__importDefault)(require("./src/components/message"));
|
|
20
|
-
exports.FormattedMessage = message_1.default;
|
|
21
|
-
var dateTimeRange_1 = (0, tslib_1.__importDefault)(require("./src/components/dateTimeRange"));
|
|
22
|
-
exports.FormattedDateTimeRange = dateTimeRange_1.default;
|
|
23
|
-
var intl_1 = require("@formatjs/intl");
|
|
24
|
-
Object.defineProperty(exports, "createIntlCache", { enumerable: true, get: function () { return intl_1.createIntlCache; } });
|
|
25
|
-
Object.defineProperty(exports, "UnsupportedFormatterError", { enumerable: true, get: function () { return intl_1.UnsupportedFormatterError; } });
|
|
26
|
-
Object.defineProperty(exports, "InvalidConfigError", { enumerable: true, get: function () { return intl_1.InvalidConfigError; } });
|
|
27
|
-
Object.defineProperty(exports, "MissingDataError", { enumerable: true, get: function () { return intl_1.MissingDataError; } });
|
|
28
|
-
Object.defineProperty(exports, "MessageFormatError", { enumerable: true, get: function () { return intl_1.MessageFormatError; } });
|
|
29
|
-
Object.defineProperty(exports, "MissingTranslationError", { enumerable: true, get: function () { return intl_1.MissingTranslationError; } });
|
|
30
|
-
Object.defineProperty(exports, "ReactIntlErrorCode", { enumerable: true, get: function () { return intl_1.IntlErrorCode; } });
|
|
31
|
-
Object.defineProperty(exports, "ReactIntlError", { enumerable: true, get: function () { return intl_1.IntlError; } });
|
|
32
|
-
function defineMessages(msgs) {
|
|
33
|
-
return msgs;
|
|
34
|
-
}
|
|
35
|
-
exports.defineMessages = defineMessages;
|
|
36
|
-
function defineMessage(msg) {
|
|
37
|
-
return msg;
|
|
38
|
-
}
|
|
39
|
-
exports.defineMessage = defineMessage;
|
|
40
|
-
// IMPORTANT: Explicit here to prevent api-extractor from outputing `import('./src/types').CustomFormatConfig`
|
|
41
|
-
exports.FormattedDate = (0, createFormattedComponent_1.createFormattedComponent)('formatDate');
|
|
42
|
-
exports.FormattedTime = (0, createFormattedComponent_1.createFormattedComponent)('formatTime');
|
|
43
|
-
// @ts-ignore issue w/ TS Intl types
|
|
44
|
-
exports.FormattedNumber = (0, createFormattedComponent_1.createFormattedComponent)('formatNumber');
|
|
45
|
-
exports.FormattedList = (0, createFormattedComponent_1.createFormattedComponent)('formatList');
|
|
46
|
-
exports.FormattedDisplayName = (0, createFormattedComponent_1.createFormattedComponent)('formatDisplayName');
|
|
47
|
-
exports.FormattedDateParts = (0, createFormattedComponent_1.createFormattedDateTimePartsComponent)('formatDate');
|
|
48
|
-
exports.FormattedTimeParts = (0, createFormattedComponent_1.createFormattedDateTimePartsComponent)('formatTime');
|
|
49
|
-
var createFormattedComponent_2 = require("./src/components/createFormattedComponent");
|
|
50
|
-
Object.defineProperty(exports, "FormattedNumberParts", { enumerable: true, get: function () { return createFormattedComponent_2.FormattedNumberParts; } });
|
|
51
|
-
Object.defineProperty(exports, "FormattedListParts", { enumerable: true, get: function () { return createFormattedComponent_2.FormattedListParts; } });
|
package/lib/index.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { MessageDescriptor, CustomFormatConfig, FormatDateOptions } from '@formatjs/intl';
|
|
3
|
-
import { IntlListFormatOptions } from '@formatjs/intl-listformat';
|
|
4
|
-
import { DisplayNamesOptions } from '@formatjs/intl-displaynames';
|
|
5
|
-
import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
|
|
6
|
-
import injectIntl, { Provider as RawIntlProvider, Context as IntlContext, WithIntlProps, WrappedComponentProps } from './src/components/injectIntl';
|
|
7
|
-
import useIntl from './src/components/useIntl';
|
|
8
|
-
import IntlProvider, { createIntl } from './src/components/provider';
|
|
9
|
-
import FormattedRelativeTime from './src/components/relative';
|
|
10
|
-
import FormattedPlural from './src/components/plural';
|
|
11
|
-
import FormattedMessage from './src/components/message';
|
|
12
|
-
import FormattedDateTimeRange from './src/components/dateTimeRange';
|
|
13
|
-
export { FormattedDateTimeRange, FormattedMessage, FormattedPlural, FormattedRelativeTime, IntlContext, IntlProvider, RawIntlProvider, WithIntlProps, WrappedComponentProps, createIntl, injectIntl, useIntl, };
|
|
14
|
-
export { IntlConfig, ResolvedIntlConfig, IntlShape } from './src/types';
|
|
15
|
-
export { createIntlCache, MessageDescriptor, IntlCache, Formatters, IntlFormatters, FormatDisplayNameOptions, FormatListOptions, FormatPluralOptions, FormatRelativeTimeOptions, FormatNumberOptions, FormatDateOptions, CustomFormatConfig, CustomFormats, UnsupportedFormatterError, InvalidConfigError, MissingDataError, MessageFormatError, MissingTranslationError, IntlErrorCode as ReactIntlErrorCode, IntlError as ReactIntlError, } from '@formatjs/intl';
|
|
16
|
-
export declare function defineMessages<K extends keyof any, T = MessageDescriptor, U extends Record<K, T> = Record<K, T>>(msgs: U): U;
|
|
17
|
-
export declare function defineMessage<T extends MessageDescriptor>(msg: T): T;
|
|
18
|
-
export declare const FormattedDate: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
19
|
-
value: string | number | Date | undefined;
|
|
20
|
-
}>;
|
|
21
|
-
export declare const FormattedTime: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
22
|
-
value: string | number | Date | undefined;
|
|
23
|
-
}>;
|
|
24
|
-
export declare const FormattedNumber: React.FC<NumberFormatOptions & CustomFormatConfig & {
|
|
25
|
-
value: number | bigint;
|
|
26
|
-
}>;
|
|
27
|
-
export declare const FormattedList: React.FC<IntlListFormatOptions & {
|
|
28
|
-
value: readonly React.ReactNode[];
|
|
29
|
-
}>;
|
|
30
|
-
export declare const FormattedDisplayName: React.FC<DisplayNamesOptions & {
|
|
31
|
-
value: string | number | Record<string, unknown>;
|
|
32
|
-
}>;
|
|
33
|
-
export declare const FormattedDateParts: React.FC<FormatDateOptions & {
|
|
34
|
-
value: Parameters<Intl.DateTimeFormat['format']>[0] | string;
|
|
35
|
-
children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
|
|
36
|
-
}>;
|
|
37
|
-
export declare const FormattedTimeParts: React.FC<FormatDateOptions & {
|
|
38
|
-
value: Parameters<Intl.DateTimeFormat['format']>[0] | string;
|
|
39
|
-
children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
|
|
40
|
-
}>;
|
|
41
|
-
export { FormattedNumberParts, FormattedListParts, } from './src/components/createFormattedComponent';
|
|
42
|
-
export type { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
|
|
43
|
-
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/react-intl/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,qBAAqB,EAAC,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAC,mBAAmB,EAAC,MAAM,6BAA6B,CAAA;AAC/D,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAA;AAC9D,OAAO,UAAU,EAAE,EACjB,QAAQ,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