use-intl 2.11.0-alpha.2 → 2.11.0-useFormatter-alpha.1
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 +19 -0
- package/README.md +32 -20
- package/dist/core/createFormatter.d.ts +17 -0
- package/dist/core/createIntl.d.ts +5 -15
- package/dist/core/index.d.ts +1 -0
- package/dist/core/use-intl.esm.js +38 -41
- package/dist/core/use-intl.esm.js.map +1 -1
- package/dist/core/use-intl.esm10.js +34 -0
- package/dist/core/use-intl.esm10.js.map +1 -0
- package/dist/core/use-intl.esm2.js +151 -35
- package/dist/core/use-intl.esm2.js.map +1 -1
- package/dist/core/use-intl.esm3.js +27 -140
- package/dist/core/use-intl.esm3.js.map +1 -1
- package/dist/core/use-intl.esm4.js +9 -53
- package/dist/core/use-intl.esm4.js.map +1 -1
- package/dist/core/use-intl.esm5.js +28 -11
- package/dist/core/use-intl.esm5.js.map +1 -1
- package/dist/core/use-intl.esm6.js +11 -209
- package/dist/core/use-intl.esm6.js.map +1 -1
- package/dist/core/use-intl.esm7.js +56 -7
- package/dist/core/use-intl.esm7.js.map +1 -1
- package/dist/core/use-intl.esm8.js +200 -19
- package/dist/core/use-intl.esm8.js.map +1 -1
- package/dist/core/use-intl.esm9.js +5 -29
- package/dist/core/use-intl.esm9.js.map +1 -1
- package/dist/react/IntlContext.d.ts +19 -2
- package/dist/react/IntlProvider.d.ts +16 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react/use-intl.esm.js +26 -7
- package/dist/react/use-intl.esm.js.map +1 -1
- package/dist/react/use-intl.esm10.js +2 -2
- package/dist/react/use-intl.esm2.js +3 -20
- package/dist/react/use-intl.esm2.js.map +1 -1
- package/dist/react/use-intl.esm3.js +40 -16
- package/dist/react/use-intl.esm3.js.map +1 -1
- package/dist/react/use-intl.esm4.js +21 -3
- package/dist/react/use-intl.esm4.js.map +1 -1
- package/dist/react/use-intl.esm5.js +20 -3
- package/dist/react/use-intl.esm5.js.map +1 -1
- package/dist/react/use-intl.esm6.js +24 -41
- package/dist/react/use-intl.esm6.js.map +1 -1
- package/dist/react/use-intl.esm7.js +5 -3
- package/dist/react/use-intl.esm7.js.map +1 -1
- package/dist/react/use-intl.esm8.js +3 -30
- package/dist/react/use-intl.esm8.js.map +1 -1
- package/dist/react/use-intl.esm9.js +1 -1
- package/dist/react/useFormatter.d.ts +5 -0
- package/dist/react/useIntl.d.ts +1 -0
- package/dist/react/useIntlContext.d.ts +1 -1
- package/dist/src/core/createBaseTranslator.js +10 -8
- package/dist/src/core/createBaseTranslator.js.map +1 -1
- package/dist/src/core/createFormatter.d.ts +17 -0
- package/dist/src/core/createFormatter.js +126 -0
- package/dist/src/core/createFormatter.js.map +1 -0
- package/dist/src/core/createIntl.d.ts +5 -15
- package/dist/src/core/createIntl.js +9 -124
- package/dist/src/core/createIntl.js.map +1 -1
- package/dist/src/core/index.d.ts +1 -0
- package/dist/src/core/index.js +2 -0
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/react/IntlContext.d.ts +19 -2
- package/dist/src/react/IntlContext.js.map +1 -1
- package/dist/src/react/IntlProvider.d.ts +16 -2
- package/dist/src/react/IntlProvider.js +13 -4
- package/dist/src/react/IntlProvider.js.map +1 -1
- package/dist/src/react/index.d.ts +2 -1
- package/dist/src/react/index.js +3 -1
- package/dist/src/react/index.js.map +1 -1
- package/dist/src/react/useFormatter.d.ts +5 -0
- package/dist/src/react/useFormatter.js +14 -0
- package/dist/src/react/useFormatter.js.map +1 -0
- package/dist/src/react/useIntl.d.ts +1 -0
- package/dist/src/react/useIntl.js +6 -0
- package/dist/src/react/useIntl.js.map +1 -1
- package/dist/src/react/useIntlContext.d.ts +1 -1
- package/dist/use-intl.cjs.development.js +99 -68
- package/dist/use-intl.cjs.development.js.map +1 -1
- package/dist/use-intl.cjs.production.min.js +1 -1
- package/dist/use-intl.cjs.production.min.js.map +1 -1
- package/dist/use-intl.esm.js +10 -8
- package/dist/use-intl.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/core/createBaseTranslator.tsx +14 -12
- package/src/core/createFormatter.tsx +181 -0
- package/src/core/createIntl.tsx +12 -180
- package/src/core/index.tsx +3 -0
- package/src/react/IntlContext.tsx +20 -2
- package/src/react/IntlProvider.tsx +36 -5
- package/src/react/index.tsx +4 -1
- package/src/react/useFormatter.tsx +19 -0
- package/src/react/useIntl.tsx +10 -0
- package/dist/react/IntlContextValue.d.ts +0 -19
- package/dist/react/IntlProviderProps.d.ts +0 -15
- package/dist/react/getIntlContextValue.d.ts +0 -18
- package/dist/src/react/IntlContextValue.d.ts +0 -19
- package/dist/src/react/IntlContextValue.js +0 -2
- package/dist/src/react/IntlContextValue.js.map +0 -1
- package/dist/src/react/IntlProviderProps.d.ts +0 -15
- package/dist/src/react/IntlProviderProps.js +0 -2
- package/dist/src/react/IntlProviderProps.js.map +0 -1
- package/dist/src/react/getIntlContextValue.d.ts +0 -18
- package/dist/src/react/getIntlContextValue.js +0 -21
- package/dist/src/react/getIntlContextValue.js.map +0 -1
- package/src/react/IntlContextValue.tsx +0 -21
- package/src/react/IntlProviderProps.tsx +0 -17
- package/src/react/getIntlContextValue.tsx +0 -30
|
@@ -1,26 +1,50 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
1
2
|
import useIntlContext from './use-intl.esm9.js';
|
|
2
|
-
import useTranslationsImpl from './use-intl.esm10.js';
|
|
3
3
|
|
|
4
|
+
function getNow() {
|
|
5
|
+
return new Date();
|
|
6
|
+
}
|
|
4
7
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
8
|
+
* Reading the current date via `new Date()` in components should be avoided, as
|
|
9
|
+
* it causes components to be impure and can lead to flaky tests. Instead, this
|
|
10
|
+
* hook can be used.
|
|
11
|
+
*
|
|
12
|
+
* By default, it returns the time when the component mounts. If `updateInterval`
|
|
13
|
+
* is specified, the value will be updated based on the interval.
|
|
14
|
+
*
|
|
15
|
+
* You can however also return a static value from this hook, if you
|
|
16
|
+
* configure the `now` parameter on the context provider. Note however,
|
|
17
|
+
* that if `updateInterval` is configured in this case, the component
|
|
18
|
+
* will initialize with the global value, but will afterwards update
|
|
19
|
+
* continuously based on the interval.
|
|
7
20
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
21
|
+
* For unit tests, this can be mocked to a constant value. For end-to-end
|
|
22
|
+
* testing, an environment parameter can be passed to the `now` parameter
|
|
23
|
+
* of the provider to mock this to a static value.
|
|
11
24
|
*/
|
|
12
25
|
|
|
13
|
-
function useTranslations(namespace) {
|
|
14
|
-
var context = useIntlContext();
|
|
15
|
-
var messages = context.messages; // We have to wrap the actual hook so the type inference for the optional
|
|
16
|
-
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
17
|
-
// The prefix ("!") is arbitrary.
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
function useNow(options) {
|
|
28
|
+
var updateInterval = options == null ? void 0 : options.updateInterval;
|
|
29
|
+
|
|
30
|
+
var _useIntlContext = useIntlContext(),
|
|
31
|
+
globalNow = _useIntlContext.now;
|
|
32
|
+
|
|
33
|
+
var _useState = useState(globalNow || getNow()),
|
|
34
|
+
now = _useState[0],
|
|
35
|
+
setNow = _useState[1];
|
|
36
|
+
|
|
37
|
+
useEffect(function () {
|
|
38
|
+
if (!updateInterval) return;
|
|
39
|
+
var intervalId = setInterval(function () {
|
|
40
|
+
setNow(getNow());
|
|
41
|
+
}, updateInterval);
|
|
42
|
+
return function () {
|
|
43
|
+
clearInterval(intervalId);
|
|
44
|
+
};
|
|
45
|
+
}, [globalNow, updateInterval]);
|
|
46
|
+
return now;
|
|
23
47
|
}
|
|
24
48
|
|
|
25
|
-
export {
|
|
49
|
+
export { useNow as default };
|
|
26
50
|
//# sourceMappingURL=use-intl.esm3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/react/useNow.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n"],"names":["getNow","Date","useNow","options","updateInterval","useIntlContext","globalNow","now","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAT,GAAe;AACb,EAAO,OAAA,IAAIC,IAAJ,EAAP,CAAA;AACD,CAAA;AAED;;;;;;;;;;;;;;;;;AAiBG;;;AACqB,SAAAC,MAAA,CAAOC,OAAP,EAAwB;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAH,IAAGA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBC,cAAc,EAAvC;AAAA,MAAYC,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsBC,QAAQ,CAACF,SAAS,IAAIN,MAAM,EAApB,CAA9B;AAAA,MAAOO,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAYE,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACN,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMO,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACT,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BI,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVS,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAACL,SAAD,EAAYF,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOG,GAAP,CAAA;AACD;;;;"}
|
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
import useIntlContext from './use-intl.esm9.js';
|
|
2
|
+
import useTranslationsImpl from './use-intl.esm10.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Translates messages from the given namespace by using the ICU syntax.
|
|
6
|
+
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
7
|
+
*
|
|
8
|
+
* If no namespace is provided, all available messages are returned.
|
|
9
|
+
* The namespace can also indicate nesting by using a dot
|
|
10
|
+
* (e.g. `namespace.Component`).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function useTranslations(namespace) {
|
|
14
|
+
var context = useIntlContext();
|
|
15
|
+
var messages = context.messages; // We have to wrap the actual hook so the type inference for the optional
|
|
16
|
+
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
17
|
+
// The prefix ("!") is arbitrary.
|
|
18
|
+
|
|
19
|
+
return useTranslationsImpl({
|
|
20
|
+
'!': messages
|
|
21
|
+
}, // @ts-ignore
|
|
22
|
+
namespace ? "!." + namespace : '!', '!');
|
|
5
23
|
}
|
|
6
24
|
|
|
7
|
-
export {
|
|
25
|
+
export { useTranslations as default };
|
|
8
26
|
//# sourceMappingURL=use-intl.esm4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm4.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm4.js","sources":["../../src/react/useTranslations.tsx"],"sourcesContent":["import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from '../core/Formats';\nimport TranslationValues, {\n RichTranslationValues\n} from '../core/TranslationValues';\nimport MessageKeys from '../core/utils/MessageKeys';\nimport NamespaceKeys from '../core/utils/NamespaceKeys';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport NestedValueOf from '../core/utils/NestedValueOf';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function useTranslations<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>(\n namespace?: NestedKey\n): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n const messages = context.messages as IntlMessages;\n\n // We have to wrap the actual hook so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return useTranslationsImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n"],"names":["useTranslations","namespace","context","useIntlContext","messages","useTranslationsImpl"],"mappings":";;;AAYA;;;;;;;AAOG;;AACqB,SAAAA,eAAA,CAMtBC,SANsB,EAMD;AA6DrB,EAAMC,IAAAA,OAAO,GAAGC,cAAc,EAA9B,CAAA;AACA,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAzB,CA9DqB;AAiErB;AACA;;AACA,EAAA,OAAOC,mBAAmB,CAIxB;AAAC,IAAKD,GAAAA,EAAAA,QAAAA;AAAN,GAJwB;AAMxBH,EAAAA,SAAS,GAAQA,IAAAA,GAAAA,SAAR,GAAsB,GANP,EAOxB,GAPwB,CAA1B,CAAA;AASD;;;;"}
|
|
@@ -1,8 +1,25 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import createFormatter from '../core/use-intl.esm2.js';
|
|
1
3
|
import useIntlContext from './use-intl.esm9.js';
|
|
2
4
|
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
+
function useFormatter() {
|
|
6
|
+
var _useIntlContext = useIntlContext(),
|
|
7
|
+
formats = _useIntlContext.formats,
|
|
8
|
+
locale = _useIntlContext.locale,
|
|
9
|
+
globalNow = _useIntlContext.now,
|
|
10
|
+
onError = _useIntlContext.onError,
|
|
11
|
+
timeZone = _useIntlContext.timeZone;
|
|
12
|
+
|
|
13
|
+
return useMemo(function () {
|
|
14
|
+
return createFormatter({
|
|
15
|
+
formats: formats,
|
|
16
|
+
locale: locale,
|
|
17
|
+
now: globalNow,
|
|
18
|
+
onError: onError,
|
|
19
|
+
timeZone: timeZone
|
|
20
|
+
});
|
|
21
|
+
}, [formats, globalNow, locale, onError, timeZone]);
|
|
5
22
|
}
|
|
6
23
|
|
|
7
|
-
export {
|
|
24
|
+
export { useFormatter as default };
|
|
8
25
|
//# sourceMappingURL=use-intl.esm5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/useFormatter.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createFormatter from '../core/createFormatter';\nimport useIntlContext from './useIntlContext';\n\nexport default function useFormatter() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n return useMemo(\n () =>\n createFormatter({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["useFormatter","useIntlContext","formats","locale","globalNow","now","onError","timeZone","useMemo","createFormatter"],"mappings":";;;;AAIc,SAAUA,YAAV,GAAsB;AAClC,EAAA,IAAA,eAAA,GAA6DC,cAAc,EAA3E;AAAA,MAAOC,OAAP,mBAAOA,OAAP;AAAA,MAAgBC,MAAhB,mBAAgBA,MAAhB;AAAA,MAA6BC,SAA7B,mBAAwBC,GAAxB;AAAA,MAAwCC,OAAxC,mBAAwCA,OAAxC;AAAA,MAAiDC,QAAjD,mBAAiDA,QAAjD,CAAA;;AAEA,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,eAAe,CAAC;AACdP,MAAAA,OAAO,EAAPA,OADc;AAEdC,MAAAA,MAAM,EAANA,MAFc;AAGdE,MAAAA,GAAG,EAAED,SAHS;AAIdE,MAAAA,OAAO,EAAPA,OAJc;AAKdC,MAAAA,QAAQ,EAARA,QAAAA;AALc,KAAD,CADjB,CAAA;AAAA,GADY,EASZ,CAACL,OAAD,EAAUE,SAAV,EAAqBD,MAArB,EAA6BG,OAA7B,EAAsCC,QAAtC,CATY,CAAd,CAAA;AAWD;;;;"}
|
|
@@ -1,50 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import createIntl from '../core/use-intl.esm4.js';
|
|
2
3
|
import useIntlContext from './use-intl.esm9.js';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Reading the current date via `new Date()` in components should be avoided, as
|
|
9
|
-
* it causes components to be impure and can lead to flaky tests. Instead, this
|
|
10
|
-
* hook can be used.
|
|
11
|
-
*
|
|
12
|
-
* By default, it returns the time when the component mounts. If `updateInterval`
|
|
13
|
-
* is specified, the value will be updated based on the interval.
|
|
14
|
-
*
|
|
15
|
-
* You can however also return a static value from this hook, if you
|
|
16
|
-
* configure the `now` parameter on the context provider. Note however,
|
|
17
|
-
* that if `updateInterval` is configured in this case, the component
|
|
18
|
-
* will initialize with the global value, but will afterwards update
|
|
19
|
-
* continuously based on the interval.
|
|
20
|
-
*
|
|
21
|
-
* For unit tests, this can be mocked to a constant value. For end-to-end
|
|
22
|
-
* testing, an environment parameter can be passed to the `now` parameter
|
|
23
|
-
* of the provider to mock this to a static value.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
function useNow(options) {
|
|
28
|
-
var updateInterval = options == null ? void 0 : options.updateInterval;
|
|
5
|
+
var hasWarned = false;
|
|
6
|
+
/** @deprecated Switch to `useFormatter` */
|
|
29
7
|
|
|
8
|
+
function useIntl() {
|
|
30
9
|
var _useIntlContext = useIntlContext(),
|
|
31
|
-
|
|
10
|
+
formats = _useIntlContext.formats,
|
|
11
|
+
locale = _useIntlContext.locale,
|
|
12
|
+
globalNow = _useIntlContext.now,
|
|
13
|
+
onError = _useIntlContext.onError,
|
|
14
|
+
timeZone = _useIntlContext.timeZone;
|
|
32
15
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
if (!hasWarned) {
|
|
17
|
+
hasWarned = true;
|
|
18
|
+
console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
|
|
19
|
+
}
|
|
36
20
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
}, [globalNow,
|
|
46
|
-
return now;
|
|
21
|
+
return useMemo(function () {
|
|
22
|
+
return createIntl({
|
|
23
|
+
formats: formats,
|
|
24
|
+
locale: locale,
|
|
25
|
+
now: globalNow,
|
|
26
|
+
onError: onError,
|
|
27
|
+
timeZone: timeZone
|
|
28
|
+
});
|
|
29
|
+
}, [formats, globalNow, locale, onError, timeZone]);
|
|
47
30
|
}
|
|
48
31
|
|
|
49
|
-
export {
|
|
32
|
+
export { useIntl as default };
|
|
50
33
|
//# sourceMappingURL=use-intl.esm6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm6.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm6.js","sources":["../../src/react/useIntl.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nlet hasWarned = false;\n\n/** @deprecated Switch to `useFormatter` */\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n if (!hasWarned) {\n hasWarned = true;\n console.warn(\n '`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.'\n );\n }\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["hasWarned","useIntl","useIntlContext","formats","locale","globalNow","now","onError","timeZone","console","warn","useMemo","createIntl"],"mappings":";;;;AAIA,IAAIA,SAAS,GAAG,KAAhB,CAAA;AAEA;;AACc,SAAUC,OAAV,GAAiB;AAC7B,EAAA,IAAA,eAAA,GAA6DC,cAAc,EAA3E;AAAA,MAAOC,OAAP,mBAAOA,OAAP;AAAA,MAAgBC,MAAhB,mBAAgBA,MAAhB;AAAA,MAA6BC,SAA7B,mBAAwBC,GAAxB;AAAA,MAAwCC,OAAxC,mBAAwCA,OAAxC;AAAA,MAAiDC,QAAjD,mBAAiDA,QAAjD,CAAA;;AAEA,EAAI,IAAA,CAACR,SAAL,EAAgB;AACdA,IAAAA,SAAS,GAAG,IAAZ,CAAA;AACAS,IAAAA,OAAO,CAACC,IAAR,CACE,6GADF,CAAA,CAAA;AAGD,GAAA;;AAED,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,UAAU,CAAC;AACTT,MAAAA,OAAO,EAAPA,OADS;AAETC,MAAAA,MAAM,EAANA,MAFS;AAGTE,MAAAA,GAAG,EAAED,SAHI;AAITE,MAAAA,OAAO,EAAPA,OAJS;AAKTC,MAAAA,QAAQ,EAARA,QAAAA;AALS,KAAD,CADZ,CAAA;AAAA,GADY,EASZ,CAACL,OAAD,EAAUE,SAAV,EAAqBD,MAArB,EAA6BG,OAA7B,EAAsCC,QAAtC,CATY,CAAd,CAAA;AAWD;;;;"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import useIntlContext from './use-intl.esm9.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
function useLocale() {
|
|
4
|
+
return useIntlContext().locale;
|
|
5
|
+
}
|
|
4
6
|
|
|
5
|
-
export {
|
|
7
|
+
export { useLocale as default };
|
|
6
8
|
//# sourceMappingURL=use-intl.esm7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/useLocale.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n"],"names":["useLocale","useIntlContext","locale"],"mappings":";;AAEc,SAAUA,SAAV,GAAmB;AAC/B,EAAOC,OAAAA,cAAc,GAAGC,MAAxB,CAAA;AACD;;;;"}
|
|
@@ -1,33 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm5.js';
|
|
3
|
-
import validateMessages from '../core/use-intl.esm8.js';
|
|
1
|
+
import { createContext } from 'react';
|
|
4
2
|
|
|
5
|
-
var
|
|
6
|
-
/**
|
|
7
|
-
* Enhances the incoming props with defaults.
|
|
8
|
-
*/
|
|
3
|
+
var IntlContext = /*#__PURE__*/createContext(undefined);
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
var getMessageFallback = _ref.getMessageFallback,
|
|
12
|
-
messages = _ref.messages,
|
|
13
|
-
onError = _ref.onError,
|
|
14
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
15
|
-
|
|
16
|
-
var finalOnError = onError || defaultOnError;
|
|
17
|
-
var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
|
|
18
|
-
|
|
19
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
20
|
-
if (messages) {
|
|
21
|
-
validateMessages(messages, finalOnError);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return _extends({}, rest, {
|
|
26
|
-
messages: messages,
|
|
27
|
-
onError: finalOnError,
|
|
28
|
-
getMessageFallback: finalGetMessageFallback
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { getIntlContextValue as default };
|
|
5
|
+
export { IntlContext as default };
|
|
33
6
|
//# sourceMappingURL=use-intl.esm8.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport Formats from '../core/Formats';\nimport IntlError from '../core/IntlError';\nimport {RichTranslationValues} from '../core/TranslationValues';\n\nexport type IntlContextShape = {\n messages?: AbstractIntlMessages;\n locale: string;\n formats?: Partial<Formats>;\n timeZone?: string;\n onError(error: IntlError): void;\n getMessageFallback(info: {\n error: IntlError;\n key: string;\n namespace?: string;\n }): string;\n now?: Date;\n defaultTranslationValues?: RichTranslationValues;\n};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAqBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B;;;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export default function useFormatter(): {
|
|
2
|
+
dateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
|
|
3
|
+
number: (value: number, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
|
|
4
|
+
relativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
5
|
+
};
|
package/dist/react/useIntl.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @deprecated Switch to `useFormatter` */
|
|
1
2
|
export default function useIntl(): {
|
|
2
3
|
formatDateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
|
|
3
4
|
formatNumber: (value: number, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function useIntlContext(): import("./
|
|
1
|
+
export default function useIntlContext(): import("./IntlContext").IntlContextShape;
|
|
@@ -90,19 +90,21 @@ export default function createBaseTranslator({ cachedFormatsByLocale, defaultTra
|
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
const messages = messagesOrError;
|
|
93
|
-
|
|
93
|
+
let message;
|
|
94
|
+
try {
|
|
95
|
+
message = resolvePath(messages, key, namespace);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
99
|
+
}
|
|
100
|
+
const cacheKey = [namespace, key, message]
|
|
101
|
+
.filter((part) => part != null)
|
|
102
|
+
.join('.');
|
|
94
103
|
let messageFormat;
|
|
95
104
|
if (cachedFormatsByLocale?.[locale]?.[cacheKey]) {
|
|
96
105
|
messageFormat = cachedFormatsByLocale?.[locale][cacheKey];
|
|
97
106
|
}
|
|
98
107
|
else {
|
|
99
|
-
let message;
|
|
100
|
-
try {
|
|
101
|
-
message = resolvePath(messages, key, namespace);
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
105
|
-
}
|
|
106
108
|
if (typeof message === 'object') {
|
|
107
109
|
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INSUFFICIENT_PATH, process.env.NODE_ENV !== 'production'
|
|
108
110
|
? `Insufficient path specified for \`${key}\` in \`${namespace ? `\`${namespace}\`` : 'messages'}\`.`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseTranslator.js","sourceRoot":"","sources":["../../../src/core/createBaseTranslator.tsx"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,YAAY,EACZ,cAAc,EAIf,MAAM,OAAO,CAAC;AAIf,OAAO,S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AI,SAAS,CAC7B,aAAa,CAAC,eAAe,EAC5B,KAAe,CAAC,OAAO,CACzB,CAAC;QACF,OAAO,CAAC,SAAS,CAAC,CAAC;QACnB,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAUD,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAG1C,EACA,qBAAqB,EACrB,wBAAwB,EACxB,OAAO,EAAE,aAAa,EACtB,kBAAkB,GAAG,yBAAyB,EAC9C,MAAM,EACN,eAAe,EACf,SAAS,EACT,OAAO,EACP,QAAQ,EAC4B;IACpC,SAAS,6BAA6B,CACpC,GAAW,EACX,IAAmB,EACnB,OAAgB;QAEhB,MAAM,KAAK,GAAG,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3C,OAAO,CAAC,KAAK,CAAC,CAAC;QACf,OAAO,kBAAkB,CAAC,EAAC,KAAK,EAAE,GAAG,EAAE,SAAS,EAAC,CAAC,CAAC;IACrD,CAAC;IAED,SAAS,eAAe;IACtB,+EAA+E;IAC/E,GAAW;IACX,kEAAkE;IAClE,MAA8B;IAC9B,2DAA2D;IAC3D,OAA0B;QAE1B,IAAI,eAAe,YAAY,SAAS,EAAE;YACxC,kDAAkD;YAClD,OAAO,kBAAkB,CAAC;gBACxB,KAAK,EAAE,eAAe;gBACtB,GAAG;gBACH,SAAS;aACV,CAAC,CAAC;SACJ;QACD,MAAM,QAAQ,GAAG,eAAe,CAAC;QAEjC,MAAM,QAAQ,GAAG,CAAC,SAAS,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"createBaseTranslator.js","sourceRoot":"","sources":["../../../src/core/createBaseTranslator.tsx"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,YAAY,EACZ,cAAc,EAIf,MAAM,OAAO,CAAC;AAIf,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,OAAO,iCAAiC,MAAM,qCAAqC,CAAC;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YAAY,SAAS,EAAE;YACxC,kDAAkD;YAClD,OAAO,kBAAkB,CAAC;gBACxB,KAAK,EAAE,eAAe;gBACtB,GAAG;gBACH,SAAS;aACV,CAAC,CAAC;SACJ;QACD,MAAM,QAAQ,GAAG,eAAe,CAAC;QAEjC,IAAI;YACF,OAAO,WAAW,CAAC,QAAQ,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;SAC9C;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,6BAA6B,CAClC,GAAG,EACH,aAAa,CAAC,eAAe,EAC5B,KAAe,CAAC,OAAO,CACzB,CAAC;SACH;IACH,CAAC,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import DateTimeFormatOptions from './DateTimeFormatOptions';
|
|
2
|
+
import Formats from './Formats';
|
|
3
|
+
import IntlError from './IntlError';
|
|
4
|
+
import NumberFormatOptions from './NumberFormatOptions';
|
|
5
|
+
declare type Props = {
|
|
6
|
+
locale: string;
|
|
7
|
+
timeZone?: string;
|
|
8
|
+
onError?(error: IntlError): void;
|
|
9
|
+
formats?: Partial<Formats>;
|
|
10
|
+
now?: Date;
|
|
11
|
+
};
|
|
12
|
+
export default function createFormatter({ formats, locale, now: globalNow, onError, timeZone }: Props): {
|
|
13
|
+
dateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions | undefined) => string;
|
|
14
|
+
number: (value: number, formatOrOptions?: string | NumberFormatOptions | undefined) => string;
|
|
15
|
+
relativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import IntlError, { IntlErrorCode } from './IntlError';
|
|
2
|
+
import { defaultOnError } from './defaults';
|
|
3
|
+
const MINUTE = 60;
|
|
4
|
+
const HOUR = MINUTE * 60;
|
|
5
|
+
const DAY = HOUR * 24;
|
|
6
|
+
const WEEK = DAY * 7;
|
|
7
|
+
const MONTH = DAY * (365 / 12); // Approximation
|
|
8
|
+
const YEAR = DAY * 365;
|
|
9
|
+
function getRelativeTimeFormatConfig(seconds) {
|
|
10
|
+
const absValue = Math.abs(seconds);
|
|
11
|
+
let value, unit;
|
|
12
|
+
// We have to round the resulting values, as `Intl.RelativeTimeFormat`
|
|
13
|
+
// will include fractions like '2.1 hours ago'.
|
|
14
|
+
if (absValue < MINUTE) {
|
|
15
|
+
unit = 'second';
|
|
16
|
+
value = Math.round(seconds);
|
|
17
|
+
}
|
|
18
|
+
else if (absValue < HOUR) {
|
|
19
|
+
unit = 'minute';
|
|
20
|
+
value = Math.round(seconds / MINUTE);
|
|
21
|
+
}
|
|
22
|
+
else if (absValue < DAY) {
|
|
23
|
+
unit = 'hour';
|
|
24
|
+
value = Math.round(seconds / HOUR);
|
|
25
|
+
}
|
|
26
|
+
else if (absValue < WEEK) {
|
|
27
|
+
unit = 'day';
|
|
28
|
+
value = Math.round(seconds / DAY);
|
|
29
|
+
}
|
|
30
|
+
else if (absValue < MONTH) {
|
|
31
|
+
unit = 'week';
|
|
32
|
+
value = Math.round(seconds / WEEK);
|
|
33
|
+
}
|
|
34
|
+
else if (absValue < YEAR) {
|
|
35
|
+
unit = 'month';
|
|
36
|
+
value = Math.round(seconds / MONTH);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
unit = 'year';
|
|
40
|
+
value = Math.round(seconds / YEAR);
|
|
41
|
+
}
|
|
42
|
+
return { value, unit };
|
|
43
|
+
}
|
|
44
|
+
export default function createFormatter({ formats, locale, now: globalNow, onError = defaultOnError, timeZone }) {
|
|
45
|
+
function resolveFormatOrOptions(typeFormats, formatOrOptions) {
|
|
46
|
+
let options;
|
|
47
|
+
if (typeof formatOrOptions === 'string') {
|
|
48
|
+
const formatName = formatOrOptions;
|
|
49
|
+
options = typeFormats?.[formatName];
|
|
50
|
+
if (!options) {
|
|
51
|
+
const error = new IntlError(IntlErrorCode.MISSING_FORMAT, process.env.NODE_ENV !== 'production'
|
|
52
|
+
? `Format \`${formatName}\` is not available. You can configure it on the provider or provide custom options.`
|
|
53
|
+
: undefined);
|
|
54
|
+
onError(error);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
options = formatOrOptions;
|
|
60
|
+
}
|
|
61
|
+
return options;
|
|
62
|
+
}
|
|
63
|
+
function getFormattedValue(value, formatOrOptions, typeFormats, formatter) {
|
|
64
|
+
let options;
|
|
65
|
+
try {
|
|
66
|
+
options = resolveFormatOrOptions(typeFormats, formatOrOptions);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return String(value);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return formatter(options);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
|
|
76
|
+
return String(value);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function dateTime(
|
|
80
|
+
/** If a number is supplied, this is interpreted as a UTC timestamp. */
|
|
81
|
+
value,
|
|
82
|
+
/** If a time zone is supplied, the `value` is converted to that time zone.
|
|
83
|
+
* Otherwise the user time zone will be used. */
|
|
84
|
+
formatOrOptions) {
|
|
85
|
+
return getFormattedValue(value, formatOrOptions, formats?.dateTime, (options) => {
|
|
86
|
+
if (timeZone && !options?.timeZone) {
|
|
87
|
+
options = { ...options, timeZone };
|
|
88
|
+
}
|
|
89
|
+
return new Intl.DateTimeFormat(locale, options).format(value);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function number(value, formatOrOptions) {
|
|
93
|
+
return getFormattedValue(value, formatOrOptions, formats?.number, (options) => new Intl.NumberFormat(locale, options).format(value));
|
|
94
|
+
}
|
|
95
|
+
function relativeTime(
|
|
96
|
+
/** The date time that needs to be formatted. */
|
|
97
|
+
date,
|
|
98
|
+
/** The reference point in time to which `date` will be formatted in relation to. */
|
|
99
|
+
now) {
|
|
100
|
+
try {
|
|
101
|
+
if (!now) {
|
|
102
|
+
if (globalNow) {
|
|
103
|
+
now = globalNow;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
throw new Error(process.env.NODE_ENV !== 'production'
|
|
107
|
+
? `The \`now\` parameter wasn't provided and there was no global fallback configured on the provider.`
|
|
108
|
+
: undefined);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const dateDate = date instanceof Date ? date : new Date(date);
|
|
112
|
+
const nowDate = now instanceof Date ? now : new Date(now);
|
|
113
|
+
const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
|
|
114
|
+
const { unit, value } = getRelativeTimeFormatConfig(seconds);
|
|
115
|
+
return new Intl.RelativeTimeFormat(locale, {
|
|
116
|
+
numeric: 'auto'
|
|
117
|
+
}).format(value, unit);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
|
|
121
|
+
return String(date);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { dateTime, number, relativeTime };
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=createFormatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFormatter.js","sourceRoot":"","sources":["../../../src/core/createFormatter.tsx"],"names":[],"mappings":"AAEA,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAE1C,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,IAAI,GAAG,MAAM,GAAG,EAAE,CAAC;AACzB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AACtB,MAAM,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC;AACrB,MAAM,KAAK,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,gBAAgB;AAChD,MAAM,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GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;YAChE,MAAM,EAAC,IAAI,EAAE,KAAK,EAAC,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAC;YAE3D,OAAO,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE;gBACzC,OAAO,EAAE,MAAM;aAChB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;SACxB;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CACL,IAAI,SAAS,CAAC,aAAa,CAAC,gBAAgB,EAAG,KAAe,CAAC,OAAO,CAAC,CACxE,CAAC;YACF,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;SACrB;IACH,CAAC;IAED,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
locale: string;
|
|
7
|
-
timeZone?: string;
|
|
8
|
-
onError?(error: IntlError): void;
|
|
9
|
-
formats?: Partial<Formats>;
|
|
10
|
-
now?: Date;
|
|
11
|
-
};
|
|
12
|
-
export default function createIntl({ formats, locale, now: globalNow, onError, timeZone }: Props): {
|
|
13
|
-
formatDateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions | undefined) => string;
|
|
14
|
-
formatNumber: (value: number, formatOrOptions?: string | NumberFormatOptions | undefined) => string;
|
|
1
|
+
import createFormatter from './createFormatter';
|
|
2
|
+
/** @deprecated Switch to `createFormatter` */
|
|
3
|
+
export default function createIntl(...args: Parameters<typeof createFormatter>): {
|
|
4
|
+
formatDateTime: (value: number | Date, formatOrOptions?: string | import("./DateTimeFormatOptions").default | undefined) => string;
|
|
5
|
+
formatNumber: (value: number, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
|
|
15
6
|
formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
16
7
|
};
|
|
17
|
-
export {};
|