use-intl 2.14.2 → 2.14.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.
Files changed (36) hide show
  1. package/dist/core/use-intl.esm.js +30 -34
  2. package/dist/core/use-intl.esm.js.map +1 -1
  3. package/dist/core/use-intl.esm2.js +31 -126
  4. package/dist/core/use-intl.esm2.js.map +1 -1
  5. package/dist/core/use-intl.esm3.js +126 -8
  6. package/dist/core/use-intl.esm3.js.map +1 -1
  7. package/dist/core/use-intl.esm4.js +11 -30
  8. package/dist/core/use-intl.esm4.js.map +1 -1
  9. package/dist/core/use-intl.esm5.js +50 -12
  10. package/dist/core/use-intl.esm5.js.map +1 -1
  11. package/dist/core/use-intl.esm6.js +12 -50
  12. package/dist/core/use-intl.esm6.js.map +1 -1
  13. package/dist/core/use-intl.esm7.js +183 -20
  14. package/dist/core/use-intl.esm7.js.map +1 -1
  15. package/dist/core/use-intl.esm8.js +7 -188
  16. package/dist/core/use-intl.esm8.js.map +1 -1
  17. package/dist/core/use-intl.esm9.js +25 -7
  18. package/dist/core/use-intl.esm9.js.map +1 -1
  19. package/dist/react/use-intl.esm.js +1 -1
  20. package/dist/react/use-intl.esm10.js +8 -24
  21. package/dist/react/use-intl.esm10.js.map +1 -1
  22. package/dist/react/use-intl.esm11.js +3 -3
  23. package/dist/react/use-intl.esm2.js +22 -20
  24. package/dist/react/use-intl.esm2.js.map +1 -1
  25. package/dist/react/use-intl.esm3.js +1 -1
  26. package/dist/react/use-intl.esm4.js +38 -19
  27. package/dist/react/use-intl.esm4.js.map +1 -1
  28. package/dist/react/use-intl.esm5.js +4 -41
  29. package/dist/react/use-intl.esm5.js.map +1 -1
  30. package/dist/react/use-intl.esm6.js +20 -4
  31. package/dist/react/use-intl.esm6.js.map +1 -1
  32. package/dist/react/use-intl.esm7.js +2 -2
  33. package/dist/react/use-intl.esm9.js +24 -8
  34. package/dist/react/use-intl.esm9.js.map +1 -1
  35. package/dist/use-intl.esm.js +8 -8
  36. package/package.json +12 -10
@@ -1,10 +1,28 @@
1
- /**
2
- * For the strictly typed messages to work we have to wrap the namespace into
3
- * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
4
- */
5
- function resolveNamespace(namespace, namespacePrefix) {
6
- return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
1
+ import IntlError, { IntlErrorCode } from './use-intl.esm.js';
2
+
3
+ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
4
+ Object.entries(messages).forEach(function (_ref) {
5
+ var key = _ref[0],
6
+ messageOrMessages = _ref[1];
7
+ if (key.includes('.')) {
8
+ var keyLabel = key;
9
+ if (parentPath) keyLabel += " (at " + parentPath + ")";
10
+ invalidKeyLabels.push(keyLabel);
11
+ }
12
+ if (messageOrMessages != null && typeof messageOrMessages === 'object') {
13
+ validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
14
+ return part != null;
15
+ }).join('.'));
16
+ }
17
+ });
18
+ }
19
+ function validateMessages(messages, onError) {
20
+ var invalidKeyLabels = [];
21
+ validateMessagesSegment(messages, invalidKeyLabels);
22
+ if (invalidKeyLabels.length > 0) {
23
+ onError(new IntlError(IntlErrorCode.INVALID_KEY, process.env.NODE_ENV !== 'production' ? "Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid " + (invalidKeyLabels.length === 1 ? 'key' : 'keys') + ": " + invalidKeyLabels.join(', ') + "\n\nIf you're migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from \"lodash\";\n\nconst input = {\n \"one.one\": \"1.1\",\n \"one.two\": \"1.2\",\n \"two.one.one\": \"2.1.1\"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// \"one\": {\n// \"one\": \"1.1\",\n// \"two\": \"1.2\"\n// },\n// \"two\": {\n// \"one\": {\n// \"one\": \"2.1.1\"\n// }\n// }\n// }\n" : undefined));
24
+ }
7
25
  }
8
26
 
9
- export { resolveNamespace as default };
27
+ export { validateMessages as default };
10
28
  //# sourceMappingURL=use-intl.esm9.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm9.js","sources":["../../src/core/resolveNamespace.tsx"],"sourcesContent":["/**\n * For the strictly typed messages to work we have to wrap the namespace into\n * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045\n */\nexport default function resolveNamespace(\n namespace: string,\n namespacePrefix: string\n) {\n return namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length);\n}\n"],"names":["resolveNamespace","namespace","namespacePrefix","undefined","slice","length"],"mappings":"AAAA;;;AAGG;AACW,SAAUA,gBAAgBA,CACtCC,SAAiB,EACjBC,eAAuB,EAAA;AAEvB,EAAA,OAAOD,SAAS,KAAKC,eAAe,GAChCC,SAAS,GACTF,SAAS,CAACG,KAAK,CAAC,CAACF,eAAe,GAAG,GAAG,EAAEG,MAAM,CAAC,CAAA;AACrD;;;;"}
1
+ {"version":3,"file":"use-intl.esm9.js","sources":["../../src/core/validateMessages.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport IntlError, {IntlErrorCode} from './IntlError';\n\nfunction validateMessagesSegment(\n messages: AbstractIntlMessages,\n invalidKeyLabels: Array<string>,\n parentPath?: string\n) {\n Object.entries(messages).forEach(([key, messageOrMessages]) => {\n if (key.includes('.')) {\n let keyLabel = key;\n if (parentPath) keyLabel += ` (at ${parentPath})`;\n invalidKeyLabels.push(keyLabel);\n }\n\n if (messageOrMessages != null && typeof messageOrMessages === 'object') {\n validateMessagesSegment(\n messageOrMessages,\n invalidKeyLabels,\n [parentPath, key].filter((part) => part != null).join('.')\n );\n }\n });\n}\n\nexport default function validateMessages(\n messages: AbstractIntlMessages,\n onError: (error: IntlError) => void\n) {\n const invalidKeyLabels: Array<string> = [];\n validateMessagesSegment(messages, invalidKeyLabels);\n\n if (invalidKeyLabels.length > 0) {\n onError(\n new IntlError(\n IntlErrorCode.INVALID_KEY,\n process.env.NODE_ENV !== 'production'\n ? `Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid ${\n invalidKeyLabels.length === 1 ? 'key' : 'keys'\n }: ${invalidKeyLabels.join(', ')}\n\nIf you're migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from \"lodash\";\n\nconst input = {\n \"one.one\": \"1.1\",\n \"one.two\": \"1.2\",\n \"two.one.one\": \"2.1.1\"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// \"one\": {\n// \"one\": \"1.1\",\n// \"two\": \"1.2\"\n// },\n// \"two\": {\n// \"one\": {\n// \"one\": \"2.1.1\"\n// }\n// }\n// }\n`\n : undefined\n )\n );\n }\n}\n"],"names":["validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","_ref","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","IntlError","IntlErrorCode","INVALID_KEY","process","env","NODE_ENV","undefined"],"mappings":";;AAGA,SAASA,uBAAuBA,CAC9BC,QAA8B,EAC9BC,gBAA+B,EAC/BC,UAAmB,EAAA;EAEnBC,MAAM,CAACC,OAAO,CAACJ,QAAQ,CAAC,CAACK,OAAO,CAAC,UAAAC,IAAA,EAA6B;IAAA,IAA3BC,GAAG,GAAAD,IAAA,CAAA,CAAA,CAAA;AAAEE,MAAAA,iBAAiB,GAAAF,IAAA,CAAA,CAAA,CAAA,CAAA;AACvD,IAAA,IAAIC,GAAG,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;MACrB,IAAIC,QAAQ,GAAGH,GAAG,CAAA;AAClB,MAAA,IAAIL,UAAU,EAAEQ,QAAQ,IAAA,OAAA,GAAYR,UAAU,GAAG,GAAA,CAAA;AACjDD,MAAAA,gBAAgB,CAACU,IAAI,CAACD,QAAQ,CAAC,CAAA;AAChC,KAAA;IAED,IAAIF,iBAAiB,IAAI,IAAI,IAAI,OAAOA,iBAAiB,KAAK,QAAQ,EAAE;AACtET,MAAAA,uBAAuB,CACrBS,iBAAiB,EACjBP,gBAAgB,EAChB,CAACC,UAAU,EAAEK,GAAG,CAAC,CAACK,MAAM,CAAC,UAACC,IAAI,EAAA;QAAA,OAAKA,IAAI,IAAI,IAAI,CAAA;AAAA,OAAA,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAC3D,CAAA;AACF,KAAA;AACH,GAAC,CAAC,CAAA;AACJ,CAAA;AAEc,SAAUC,gBAAgBA,CACtCf,QAA8B,EAC9BgB,OAAmC,EAAA;EAEnC,IAAMf,gBAAgB,GAAkB,EAAE,CAAA;AAC1CF,EAAAA,uBAAuB,CAACC,QAAQ,EAAEC,gBAAgB,CAAC,CAAA;AAEnD,EAAA,IAAIA,gBAAgB,CAACgB,MAAM,GAAG,CAAC,EAAE;AAC/BD,IAAAA,OAAO,CACL,IAAIE,SAAS,CACXC,aAAa,CAACC,WAAW,EACzBC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAI/BtB,2JAAAA,IAAAA,gBAAgB,CAACgB,MAAM,KAAK,CAAC,GAAG,KAAK,GAAG,MAC1C,CAAKhB,GAAAA,IAAAA,GAAAA,gBAAgB,CAACa,IAAI,CAAC,IAAI,CAAC,GA+BhCU,4gBAAAA,GAAAA,SAAS,CACd,CACF,CAAA;AACF,GAAA;AACH;;;;"}
@@ -1,7 +1,7 @@
1
1
  import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../_virtual/use-intl.esm.js';
2
2
  import React from 'react';
3
3
  import IntlContext from './use-intl.esm8.js';
4
- import getInitializedConfig from './use-intl.esm10.js';
4
+ import getInitializedConfig from './use-intl.esm9.js';
5
5
 
6
6
  var _excluded = ["children"];
7
7
  function IntlProvider(_ref) {
@@ -1,29 +1,13 @@
1
- import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
- import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm5.js';
3
- import validateMessages from '../core/use-intl.esm7.js';
1
+ import { useContext } from 'react';
2
+ import IntlContext from './use-intl.esm8.js';
4
3
 
5
- var _excluded = ["getMessageFallback", "messages", "onError"];
6
- /**
7
- * Enhances the incoming props with defaults.
8
- */
9
- function getInitializedConfig(_ref) {
10
- var getMessageFallback = _ref.getMessageFallback,
11
- messages = _ref.messages,
12
- onError = _ref.onError,
13
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
14
- var finalOnError = onError || defaultOnError;
15
- var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
16
- if (process.env.NODE_ENV !== 'production') {
17
- if (messages) {
18
- validateMessages(messages, finalOnError);
19
- }
4
+ function useIntlContext() {
5
+ var context = useContext(IntlContext);
6
+ if (!context) {
7
+ throw new Error(process.env.NODE_ENV !== 'production' ? 'No intl context found. Have you configured the provider?' : undefined);
20
8
  }
21
- return _extends({}, rest, {
22
- messages: messages,
23
- onError: finalOnError,
24
- getMessageFallback: finalGetMessageFallback
25
- });
9
+ return context;
26
10
  }
27
11
 
28
- export { getInitializedConfig as default };
12
+ export { useIntlContext as default };
29
13
  //# sourceMappingURL=use-intl.esm10.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm10.js","sources":["../../src/react/getInitializedConfig.tsx"],"sourcesContent":["import IntlConfig from '../core/IntlConfig';\nimport {defaultGetMessageFallback, defaultOnError} from '../core/defaults';\nimport validateMessages from '../core/validateMessages';\n\n/**\n * Enhances the incoming props with defaults.\n */\nexport default function getInitializedConfig<\n // This is a generic to allow for stricter typing. E.g.\n // the RSC integration always provides a `now` value.\n Props extends Omit<IntlConfig, 'children'>\n>({getMessageFallback, messages, onError, ...rest}: Props) {\n const finalOnError = onError || defaultOnError;\n const finalGetMessageFallback =\n getMessageFallback || defaultGetMessageFallback;\n\n if (process.env.NODE_ENV !== 'production') {\n if (messages) {\n validateMessages(messages, finalOnError);\n }\n }\n\n return {\n ...rest,\n messages,\n onError: finalOnError,\n getMessageFallback: finalGetMessageFallback\n };\n}\n"],"names":["getInitializedConfig","_ref","getMessageFallback","messages","onError","rest","_objectWithoutPropertiesLoose","_excluded","finalOnError","defaultOnError","finalGetMessageFallback","defaultGetMessageFallback","process","env","NODE_ENV","validateMessages","_extends"],"mappings":";;;;;AAIA;;AAEG;AACqB,SAAAA,oBAAoBA,CAAAC,IAAA,EAIa;AAAA,EAAA,IAAtDC,kBAAkB,GAAAD,IAAA,CAAlBC,kBAAkB;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IAAEC,OAAO,GAAAH,IAAA,CAAPG,OAAO;AAAKC,IAAAA,IAAI,GAAAC,6BAAA,CAAAL,IAAA,EAAAM,SAAA,CAAA,CAAA;AAC/C,EAAA,IAAMC,YAAY,GAAGJ,OAAO,IAAIK,cAAc,CAAA;AAC9C,EAAA,IAAMC,uBAAuB,GAC3BR,kBAAkB,IAAIS,yBAAyB,CAAA;AAEjD,EAAA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;AACzC,IAAA,IAAIX,QAAQ,EAAE;AACZY,MAAAA,gBAAgB,CAACZ,QAAQ,EAAEK,YAAY,CAAC,CAAA;AACzC,KAAA;AACF,GAAA;EAED,OAAAQ,QAAA,KACKX,IAAI,EAAA;AACPF,IAAAA,QAAQ,EAARA,QAAQ;AACRC,IAAAA,OAAO,EAAEI,YAAY;AACrBN,IAAAA,kBAAkB,EAAEQ,uBAAAA;AAAuB,GAAA,CAAA,CAAA;AAE/C;;;;"}
1
+ {"version":3,"file":"use-intl.esm10.js","sources":["../../src/react/useIntlContext.tsx"],"sourcesContent":["import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n"],"names":["useIntlContext","context","useContext","IntlContext","Error","process","env","NODE_ENV","undefined"],"mappings":";;;AAGc,SAAUA,cAAcA,GAAA;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAW,CAAC,CAAA;EAEvC,IAAI,CAACF,OAAO,EAAE;AACZ,IAAA,MAAM,IAAIG,KAAK,CACbC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,0DAA0D,GAC1DC,SAAS,CACd,CAAA;AACF,GAAA;AAED,EAAA,OAAOP,OAAO,CAAA;AAChB;;;;"}
@@ -1,7 +1,7 @@
1
1
  import { useRef, useMemo } from 'react';
2
- import createBaseTranslator, { getMessagesOrError } from '../core/use-intl.esm8.js';
3
- import resolveNamespace from '../core/use-intl.esm9.js';
4
- import useIntlContext from './use-intl.esm9.js';
2
+ import createBaseTranslator, { getMessagesOrError } from '../core/use-intl.esm7.js';
3
+ import resolveNamespace from '../core/use-intl.esm8.js';
4
+ import useIntlContext from './use-intl.esm10.js';
5
5
 
6
6
  function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
7
7
  var _useIntlContext = useIntlContext(),
@@ -1,24 +1,26 @@
1
- import { useMemo } from 'react';
2
- import createFormatter from '../core/use-intl.esm2.js';
3
- import useIntlContext from './use-intl.esm9.js';
1
+ import useIntlContext from './use-intl.esm10.js';
2
+ import useTranslationsImpl from './use-intl.esm11.js';
4
3
 
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
- return useMemo(function () {
13
- return createFormatter({
14
- formats: formats,
15
- locale: locale,
16
- now: globalNow,
17
- onError: onError,
18
- timeZone: timeZone
19
- });
20
- }, [formats, globalNow, locale, onError, timeZone]);
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
+ function useTranslations(namespace) {
13
+ var context = useIntlContext();
14
+ var messages = context.messages;
15
+ // 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
+ return useTranslationsImpl({
19
+ '!': messages
20
+ },
21
+ // @ts-ignore
22
+ namespace ? "!." + namespace : '!', '!');
21
23
  }
22
24
 
23
- export { useFormatter as default };
25
+ export { useTranslations as default };
24
26
  //# sourceMappingURL=use-intl.esm2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm2.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","useIntlContext","formats","locale","globalNow","now","onError","timeZone","useMemo","createFormatter"],"mappings":";;;;AAIc,SAAUA,YAAYA,GAAA;AAClC,EAAA,IAAAC,eAAA,GAA6DC,cAAc,EAAE;IAAtEC,OAAO,GAAAF,eAAA,CAAPE,OAAO;IAAEC,MAAM,GAAAH,eAAA,CAANG,MAAM;IAAOC,SAAS,GAAAJ,eAAA,CAAdK,GAAG;IAAaC,OAAO,GAAAN,eAAA,CAAPM,OAAO;IAAEC,QAAQ,GAAAP,eAAA,CAARO,QAAQ,CAAA;AAEzD,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,eAAe,CAAC;AACdP,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,MAAM,EAANA,MAAM;AACNE,MAAAA,GAAG,EAAED,SAAS;AACdE,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACL,OAAO,EAAEE,SAAS,EAAED,MAAM,EAAEG,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"use-intl.esm2.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,eAAeA,CAMrCC,SAAqB,EAAA;AA6DrB,EAAA,IAAMC,OAAO,GAAGC,cAAc,EAAE,CAAA;AAChC,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAwB,CAAA;AAEjD;AACA;AACA;AACA,EAAA,OAAOC,mBAAmB,CAIxB;AAAC,IAAA,GAAG,EAAED,QAAAA;GAAS;AACf;AACAH,EAAAA,SAAS,UAAQA,SAAS,GAAK,GAAG,EAClC,GAAG,CACJ,CAAA;AACH;;;;"}
@@ -1,4 +1,4 @@
1
- import useIntlContext from './use-intl.esm9.js';
1
+ import useIntlContext from './use-intl.esm10.js';
2
2
 
3
3
  function useLocale() {
4
4
  return useIntlContext().locale;
@@ -1,26 +1,45 @@
1
- import useIntlContext from './use-intl.esm9.js';
2
- import useTranslationsImpl from './use-intl.esm11.js';
1
+ import { useState, useEffect } from 'react';
2
+ import useIntlContext from './use-intl.esm10.js';
3
3
 
4
+ function getNow() {
5
+ return new Date();
6
+ }
4
7
  /**
5
- * Translates messages from the given namespace by using the ICU syntax.
6
- * See https://formatjs.io/docs/core-concepts/icu-syntax.
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
- * 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`).
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
- function useTranslations(namespace) {
13
- var context = useIntlContext();
14
- var messages = context.messages;
15
- // 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
- return useTranslationsImpl({
19
- '!': messages
20
- },
21
- // @ts-ignore
22
- namespace ? "!." + namespace : '!', '!');
25
+ function useNow(options) {
26
+ var updateInterval = options == null ? void 0 : options.updateInterval;
27
+ var _useIntlContext = useIntlContext(),
28
+ globalNow = _useIntlContext.now;
29
+ var _useState = useState(globalNow || getNow()),
30
+ now = _useState[0],
31
+ setNow = _useState[1];
32
+ useEffect(function () {
33
+ if (!updateInterval) return;
34
+ var intervalId = setInterval(function () {
35
+ setNow(getNow());
36
+ }, updateInterval);
37
+ return function () {
38
+ clearInterval(intervalId);
39
+ };
40
+ }, [globalNow, updateInterval]);
41
+ return now;
23
42
  }
24
43
 
25
- export { useTranslations as default };
44
+ export { useNow as default };
26
45
  //# sourceMappingURL=use-intl.esm4.js.map
@@ -1 +1 @@
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,eAAeA,CAMrCC,SAAqB,EAAA;AA6DrB,EAAA,IAAMC,OAAO,GAAGC,cAAc,EAAE,CAAA;AAChC,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAwB,CAAA;AAEjD;AACA;AACA;AACA,EAAA,OAAOC,mBAAmB,CAIxB;AAAC,IAAA,GAAG,EAAED,QAAAA;GAAS;AACf;AACAH,EAAAA,SAAS,UAAQA,SAAS,GAAK,GAAG,EAClC,GAAG,CACJ,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"use-intl.esm4.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","useIntlContext","globalNow","now","_useState","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAMA,GAAA;EACb,OAAO,IAAIC,IAAI,EAAE,CAAA;AACnB,CAAA;AAEA;;;;;;;;;;;;;;;;;AAiBG;AACqB,SAAAC,MAAMA,CAACC,OAAiB,EAAA;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAO,IAAPA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAc,CAAA;AAE9C,EAAA,IAAAC,eAAA,GAAyBC,cAAc,EAAE;IAA7BC,SAAS,GAAAF,eAAA,CAAdG,GAAG,CAAA;EACV,IAAAC,SAAA,GAAsBC,QAAQ,CAACH,SAAS,IAAIP,MAAM,EAAE,CAAC;AAA9CQ,IAAAA,GAAG,GAAAC,SAAA,CAAA,CAAA,CAAA;AAAEE,IAAAA,MAAM,GAAAF,SAAA,CAAA,CAAA,CAAA,CAAA;AAElBG,EAAAA,SAAS,CAAC,YAAK;IACb,IAAI,CAACR,cAAc,EAAE,OAAA;AAErB,IAAA,IAAMS,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACX,MAAM,EAAE,CAAC,CAAA;KACjB,EAAEI,cAAc,CAAC,CAAA;AAElB,IAAA,OAAO,YAAK;MACVW,aAAa,CAACF,UAAU,CAAC,CAAA;KAC1B,CAAA;AACH,GAAC,EAAE,CAACN,SAAS,EAAEH,cAAc,CAAC,CAAC,CAAA;AAE/B,EAAA,OAAOI,GAAG,CAAA;AACZ;;;;"}
@@ -1,45 +1,8 @@
1
- import { useState, useEffect } from 'react';
2
- import useIntlContext from './use-intl.esm9.js';
1
+ import useIntlContext from './use-intl.esm10.js';
3
2
 
4
- function getNow() {
5
- return new Date();
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
- function useNow(options) {
26
- var updateInterval = options == null ? void 0 : options.updateInterval;
27
- var _useIntlContext = useIntlContext(),
28
- globalNow = _useIntlContext.now;
29
- var _useState = useState(globalNow || getNow()),
30
- now = _useState[0],
31
- setNow = _useState[1];
32
- useEffect(function () {
33
- if (!updateInterval) return;
34
- var intervalId = setInterval(function () {
35
- setNow(getNow());
36
- }, updateInterval);
37
- return function () {
38
- clearInterval(intervalId);
39
- };
40
- }, [globalNow, updateInterval]);
41
- return now;
3
+ function useTimeZone() {
4
+ return useIntlContext().timeZone;
42
5
  }
43
6
 
44
- export { useNow as default };
7
+ export { useTimeZone as default };
45
8
  //# sourceMappingURL=use-intl.esm5.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm5.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","useIntlContext","globalNow","now","_useState","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAMA,GAAA;EACb,OAAO,IAAIC,IAAI,EAAE,CAAA;AACnB,CAAA;AAEA;;;;;;;;;;;;;;;;;AAiBG;AACqB,SAAAC,MAAMA,CAACC,OAAiB,EAAA;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAO,IAAPA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAc,CAAA;AAE9C,EAAA,IAAAC,eAAA,GAAyBC,cAAc,EAAE;IAA7BC,SAAS,GAAAF,eAAA,CAAdG,GAAG,CAAA;EACV,IAAAC,SAAA,GAAsBC,QAAQ,CAACH,SAAS,IAAIP,MAAM,EAAE,CAAC;AAA9CQ,IAAAA,GAAG,GAAAC,SAAA,CAAA,CAAA,CAAA;AAAEE,IAAAA,MAAM,GAAAF,SAAA,CAAA,CAAA,CAAA,CAAA;AAElBG,EAAAA,SAAS,CAAC,YAAK;IACb,IAAI,CAACR,cAAc,EAAE,OAAA;AAErB,IAAA,IAAMS,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACX,MAAM,EAAE,CAAC,CAAA;KACjB,EAAEI,cAAc,CAAC,CAAA;AAElB,IAAA,OAAO,YAAK;MACVW,aAAa,CAACF,UAAU,CAAC,CAAA;KAC1B,CAAA;AACH,GAAC,EAAE,CAACN,SAAS,EAAEH,cAAc,CAAC,CAAC,CAAA;AAE/B,EAAA,OAAOI,GAAG,CAAA;AACZ;;;;"}
1
+ {"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAWA,GAAA;AACjC,EAAA,OAAOC,cAAc,EAAE,CAACC,QAAQ,CAAA;AAClC;;;;"}
@@ -1,8 +1,24 @@
1
- import useIntlContext from './use-intl.esm9.js';
1
+ import { useMemo } from 'react';
2
+ import createFormatter from '../core/use-intl.esm3.js';
3
+ import useIntlContext from './use-intl.esm10.js';
2
4
 
3
- function useTimeZone() {
4
- return useIntlContext().timeZone;
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
+ return useMemo(function () {
13
+ return createFormatter({
14
+ formats: formats,
15
+ locale: locale,
16
+ now: globalNow,
17
+ onError: onError,
18
+ timeZone: timeZone
19
+ });
20
+ }, [formats, globalNow, locale, onError, timeZone]);
5
21
  }
6
22
 
7
- export { useTimeZone as default };
23
+ export { useFormatter as default };
8
24
  //# sourceMappingURL=use-intl.esm6.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm6.js","sources":["../../src/react/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAWA,GAAA;AACjC,EAAA,OAAOC,cAAc,EAAE,CAACC,QAAQ,CAAA;AAClC;;;;"}
1
+ {"version":3,"file":"use-intl.esm6.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","useIntlContext","formats","locale","globalNow","now","onError","timeZone","useMemo","createFormatter"],"mappings":";;;;AAIc,SAAUA,YAAYA,GAAA;AAClC,EAAA,IAAAC,eAAA,GAA6DC,cAAc,EAAE;IAAtEC,OAAO,GAAAF,eAAA,CAAPE,OAAO;IAAEC,MAAM,GAAAH,eAAA,CAANG,MAAM;IAAOC,SAAS,GAAAJ,eAAA,CAAdK,GAAG;IAAaC,OAAO,GAAAN,eAAA,CAAPM,OAAO;IAAEC,QAAQ,GAAAP,eAAA,CAARO,QAAQ,CAAA;AAEzD,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,eAAe,CAAC;AACdP,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,MAAM,EAANA,MAAM;AACNE,MAAAA,GAAG,EAAED,SAAS;AACdE,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACL,OAAO,EAAEE,SAAS,EAAED,MAAM,EAAEG,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { useMemo } from 'react';
2
- import createIntl from '../core/use-intl.esm3.js';
3
- import useIntlContext from './use-intl.esm9.js';
2
+ import createIntl from '../core/use-intl.esm4.js';
3
+ import useIntlContext from './use-intl.esm10.js';
4
4
 
5
5
  var hasWarned = false;
6
6
  /** @deprecated Switch to `useFormatter` instead. */
@@ -1,13 +1,29 @@
1
- import { useContext } from 'react';
2
- import IntlContext from './use-intl.esm8.js';
1
+ import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
+ import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm6.js';
3
+ import validateMessages from '../core/use-intl.esm9.js';
3
4
 
4
- function useIntlContext() {
5
- var context = useContext(IntlContext);
6
- if (!context) {
7
- throw new Error(process.env.NODE_ENV !== 'production' ? 'No intl context found. Have you configured the provider?' : undefined);
5
+ var _excluded = ["getMessageFallback", "messages", "onError"];
6
+ /**
7
+ * Enhances the incoming props with defaults.
8
+ */
9
+ function getInitializedConfig(_ref) {
10
+ var getMessageFallback = _ref.getMessageFallback,
11
+ messages = _ref.messages,
12
+ onError = _ref.onError,
13
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
14
+ var finalOnError = onError || defaultOnError;
15
+ var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
16
+ if (process.env.NODE_ENV !== 'production') {
17
+ if (messages) {
18
+ validateMessages(messages, finalOnError);
19
+ }
8
20
  }
9
- return context;
21
+ return _extends({}, rest, {
22
+ messages: messages,
23
+ onError: finalOnError,
24
+ getMessageFallback: finalGetMessageFallback
25
+ });
10
26
  }
11
27
 
12
- export { useIntlContext as default };
28
+ export { getInitializedConfig as default };
13
29
  //# sourceMappingURL=use-intl.esm9.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/useIntlContext.tsx"],"sourcesContent":["import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n"],"names":["useIntlContext","context","useContext","IntlContext","Error","process","env","NODE_ENV","undefined"],"mappings":";;;AAGc,SAAUA,cAAcA,GAAA;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAW,CAAC,CAAA;EAEvC,IAAI,CAACF,OAAO,EAAE;AACZ,IAAA,MAAM,IAAIG,KAAK,CACbC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,0DAA0D,GAC1DC,SAAS,CACd,CAAA;AACF,GAAA;AAED,EAAA,OAAOP,OAAO,CAAA;AAChB;;;;"}
1
+ {"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/getInitializedConfig.tsx"],"sourcesContent":["import IntlConfig from '../core/IntlConfig';\nimport {defaultGetMessageFallback, defaultOnError} from '../core/defaults';\nimport validateMessages from '../core/validateMessages';\n\n/**\n * Enhances the incoming props with defaults.\n */\nexport default function getInitializedConfig<\n // This is a generic to allow for stricter typing. E.g.\n // the RSC integration always provides a `now` value.\n Props extends Omit<IntlConfig, 'children'>\n>({getMessageFallback, messages, onError, ...rest}: Props) {\n const finalOnError = onError || defaultOnError;\n const finalGetMessageFallback =\n getMessageFallback || defaultGetMessageFallback;\n\n if (process.env.NODE_ENV !== 'production') {\n if (messages) {\n validateMessages(messages, finalOnError);\n }\n }\n\n return {\n ...rest,\n messages,\n onError: finalOnError,\n getMessageFallback: finalGetMessageFallback\n };\n}\n"],"names":["getInitializedConfig","_ref","getMessageFallback","messages","onError","rest","_objectWithoutPropertiesLoose","_excluded","finalOnError","defaultOnError","finalGetMessageFallback","defaultGetMessageFallback","process","env","NODE_ENV","validateMessages","_extends"],"mappings":";;;;;AAIA;;AAEG;AACqB,SAAAA,oBAAoBA,CAAAC,IAAA,EAIa;AAAA,EAAA,IAAtDC,kBAAkB,GAAAD,IAAA,CAAlBC,kBAAkB;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IAAEC,OAAO,GAAAH,IAAA,CAAPG,OAAO;AAAKC,IAAAA,IAAI,GAAAC,6BAAA,CAAAL,IAAA,EAAAM,SAAA,CAAA,CAAA;AAC/C,EAAA,IAAMC,YAAY,GAAGJ,OAAO,IAAIK,cAAc,CAAA;AAC9C,EAAA,IAAMC,uBAAuB,GAC3BR,kBAAkB,IAAIS,yBAAyB,CAAA;AAEjD,EAAA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;AACzC,IAAA,IAAIX,QAAQ,EAAE;AACZY,MAAAA,gBAAgB,CAACZ,QAAQ,EAAEK,YAAY,CAAC,CAAA;AACzC,KAAA;AACF,GAAA;EAED,OAAAQ,QAAA,KACKX,IAAI,EAAA;AACPF,IAAAA,QAAQ,EAARA,QAAQ;AACRC,IAAAA,OAAO,EAAEI,YAAY;AACrBN,IAAAA,kBAAkB,EAAEQ,uBAAAA;AAAuB,GAAA,CAAA,CAAA;AAE/C;;;;"}
@@ -1,12 +1,12 @@
1
- export { default as IntlError, IntlErrorCode } from './core/use-intl.esm4.js';
2
- export { default as createTranslator } from './core/use-intl.esm.js';
3
- export { default as createFormatter } from './core/use-intl.esm2.js';
4
- export { default as createIntl } from './core/use-intl.esm3.js';
1
+ export { default as IntlError, IntlErrorCode } from './core/use-intl.esm.js';
2
+ export { default as createTranslator } from './core/use-intl.esm2.js';
3
+ export { default as createFormatter } from './core/use-intl.esm3.js';
4
+ export { default as createIntl } from './core/use-intl.esm4.js';
5
5
  export { default as IntlProvider } from './react/use-intl.esm.js';
6
- export { default as useTranslations } from './react/use-intl.esm4.js';
6
+ export { default as useTranslations } from './react/use-intl.esm2.js';
7
7
  export { default as useLocale } from './react/use-intl.esm3.js';
8
- export { default as useNow } from './react/use-intl.esm5.js';
9
- export { default as useTimeZone } from './react/use-intl.esm6.js';
10
- export { default as useFormatter } from './react/use-intl.esm2.js';
8
+ export { default as useNow } from './react/use-intl.esm4.js';
9
+ export { default as useTimeZone } from './react/use-intl.esm5.js';
10
+ export { default as useFormatter } from './react/use-intl.esm6.js';
11
11
  export { default as useIntl } from './react/use-intl.esm7.js';
12
12
  //# sourceMappingURL=use-intl.esm.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "2.14.2",
3
+ "version": "2.14.6",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "description": "Minimal, but complete solution for managing internationalization in React apps.",
@@ -10,6 +10,15 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/amannn/next-intl/tree/main/packages/use-intl"
12
12
  },
13
+ "scripts": {
14
+ "start": "dts watch",
15
+ "build": "pnpm build:default && pnpm build:rsc",
16
+ "build:default": "rm -rf dist && dts build",
17
+ "build:rsc": "tsc && rm -rf dist/test",
18
+ "test": "TZ=Europe/Berlin dts test --testPathIgnorePatterns=dist",
19
+ "lint": "eslint src test && tsc --noEmit",
20
+ "prepublishOnly": "turbo test && turbo lint && turbo build"
21
+ },
13
22
  "main": "dist/index.js",
14
23
  "module": "dist/use-intl.esm.js",
15
24
  "typings": "dist/index.d.ts",
@@ -55,12 +64,5 @@
55
64
  "engines": {
56
65
  "node": ">=10"
57
66
  },
58
- "scripts": {
59
- "start": "dts watch",
60
- "build": "pnpm build:default && pnpm build:rsc",
61
- "build:default": "rm -rf dist && dts build",
62
- "build:rsc": "tsc && rm -rf dist/test",
63
- "test": "TZ=Europe/Berlin dts test --testPathIgnorePatterns=dist",
64
- "lint": "eslint src test && tsc --noEmit"
65
- }
66
- }
67
+ "gitHead": "a1854592a86b33a4de19a70deec8709c23f3d802"
68
+ }