use-intl 2.13.2 → 2.14.0

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 (83) hide show
  1. package/dist/_virtual/use-intl.esm.js +4 -28
  2. package/dist/_virtual/use-intl.esm.js.map +1 -1
  3. package/dist/core/AbstractIntlMessages.d.ts +1 -1
  4. package/dist/core/DateTimeFormatOptions.d.ts +1 -1
  5. package/dist/core/Formats.d.ts +1 -1
  6. package/dist/core/IntlConfig.d.ts +2 -2
  7. package/dist/core/TranslationValues.d.ts +3 -3
  8. package/dist/core/createBaseTranslator.d.ts +3 -3
  9. package/dist/core/createFormatter.d.ts +4 -4
  10. package/dist/core/createIntl.d.ts +1 -1
  11. package/dist/core/createTranslator.d.ts +1 -1
  12. package/dist/core/createTranslatorImpl.d.ts +2 -2
  13. package/dist/core/use-intl.esm.js +0 -9
  14. package/dist/core/use-intl.esm.js.map +1 -1
  15. package/dist/core/use-intl.esm10.js +2 -4
  16. package/dist/core/use-intl.esm10.js.map +1 -1
  17. package/dist/core/use-intl.esm2.js +9 -11
  18. package/dist/core/use-intl.esm2.js.map +1 -1
  19. package/dist/core/use-intl.esm3.js +12 -35
  20. package/dist/core/use-intl.esm3.js.map +1 -1
  21. package/dist/core/use-intl.esm4.js +0 -1
  22. package/dist/core/use-intl.esm4.js.map +1 -1
  23. package/dist/core/use-intl.esm5.js +9 -15
  24. package/dist/core/use-intl.esm5.js.map +1 -1
  25. package/dist/core/use-intl.esm6.js.map +1 -1
  26. package/dist/core/use-intl.esm7.js +27 -69
  27. package/dist/core/use-intl.esm7.js.map +1 -1
  28. package/dist/core/use-intl.esm8.js.map +1 -1
  29. package/dist/core/use-intl.esm9.js +1 -5
  30. package/dist/core/use-intl.esm9.js.map +1 -1
  31. package/dist/core/utils/MessageKeys.d.ts +1 -1
  32. package/dist/core/utils/NamespaceKeys.d.ts +1 -1
  33. package/dist/core/utils/NestedKeyOf.d.ts +1 -1
  34. package/dist/core/utils/NestedValueOf.d.ts +1 -1
  35. package/dist/react/IntlProvider.d.ts +1 -1
  36. package/dist/react/use-intl.esm.js +1 -2
  37. package/dist/react/use-intl.esm.js.map +1 -1
  38. package/dist/react/use-intl.esm10.js +0 -2
  39. package/dist/react/use-intl.esm10.js.map +1 -1
  40. package/dist/react/use-intl.esm11.js +7 -8
  41. package/dist/react/use-intl.esm11.js.map +1 -1
  42. package/dist/react/use-intl.esm2.js +4 -4
  43. package/dist/react/use-intl.esm2.js.map +1 -1
  44. package/dist/react/use-intl.esm3.js.map +1 -1
  45. package/dist/react/use-intl.esm4.js +3 -8
  46. package/dist/react/use-intl.esm4.js.map +1 -1
  47. package/dist/react/use-intl.esm5.js.map +1 -1
  48. package/dist/react/use-intl.esm6.js +5 -6
  49. package/dist/react/use-intl.esm6.js.map +1 -1
  50. package/dist/react/use-intl.esm7.js +5 -8
  51. package/dist/react/use-intl.esm7.js.map +1 -1
  52. package/dist/react/use-intl.esm8.js.map +1 -1
  53. package/dist/react/use-intl.esm9.js +3 -7
  54. package/dist/react/use-intl.esm9.js.map +1 -1
  55. package/dist/react/useFormatter.d.ts +1 -1
  56. package/dist/react/useIntl.d.ts +1 -1
  57. package/dist/react/useNow.d.ts +1 -1
  58. package/dist/src/core/AbstractIntlMessages.d.ts +1 -1
  59. package/dist/src/core/DateTimeFormatOptions.d.ts +1 -1
  60. package/dist/src/core/Formats.d.ts +1 -1
  61. package/dist/src/core/IntlConfig.d.ts +2 -2
  62. package/dist/src/core/TranslationValues.d.ts +3 -3
  63. package/dist/src/core/createBaseTranslator.d.ts +3 -3
  64. package/dist/src/core/createFormatter.d.ts +4 -4
  65. package/dist/src/core/createIntl.d.ts +1 -1
  66. package/dist/src/core/createTranslator.d.ts +1 -1
  67. package/dist/src/core/createTranslator.js +1 -1
  68. package/dist/src/core/createTranslator.js.map +1 -1
  69. package/dist/src/core/createTranslatorImpl.d.ts +2 -2
  70. package/dist/src/core/utils/MessageKeys.d.ts +1 -1
  71. package/dist/src/core/utils/NamespaceKeys.d.ts +1 -1
  72. package/dist/src/core/utils/NestedKeyOf.d.ts +1 -1
  73. package/dist/src/core/utils/NestedValueOf.d.ts +1 -1
  74. package/dist/src/react/IntlProvider.d.ts +1 -1
  75. package/dist/src/react/useFormatter.d.ts +1 -1
  76. package/dist/src/react/useIntl.d.ts +1 -1
  77. package/dist/src/react/useNow.d.ts +1 -1
  78. package/dist/use-intl.cjs.development.js +91 -221
  79. package/dist/use-intl.cjs.development.js.map +1 -1
  80. package/dist/use-intl.cjs.production.min.js +1 -1
  81. package/dist/use-intl.cjs.production.min.js.map +1 -1
  82. package/package.json +17 -17
  83. package/src/core/createTranslator.tsx +1 -1
@@ -1,49 +1,39 @@
1
1
  function _extends() {
2
- _extends = Object.assign || function (target) {
2
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
3
3
  for (var i = 1; i < arguments.length; i++) {
4
4
  var source = arguments[i];
5
-
6
5
  for (var key in source) {
7
6
  if (Object.prototype.hasOwnProperty.call(source, key)) {
8
7
  target[key] = source[key];
9
8
  }
10
9
  }
11
10
  }
12
-
13
11
  return target;
14
12
  };
15
-
16
13
  return _extends.apply(this, arguments);
17
14
  }
18
-
19
15
  function _inheritsLoose(subClass, superClass) {
20
16
  subClass.prototype = Object.create(superClass.prototype);
21
17
  subClass.prototype.constructor = subClass;
22
-
23
18
  _setPrototypeOf(subClass, superClass);
24
19
  }
25
-
26
20
  function _getPrototypeOf(o) {
27
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
21
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
28
22
  return o.__proto__ || Object.getPrototypeOf(o);
29
23
  };
30
24
  return _getPrototypeOf(o);
31
25
  }
32
-
33
26
  function _setPrototypeOf(o, p) {
34
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
27
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
35
28
  o.__proto__ = p;
36
29
  return o;
37
30
  };
38
-
39
31
  return _setPrototypeOf(o, p);
40
32
  }
41
-
42
33
  function _isNativeReflectConstruct() {
43
34
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
44
35
  if (Reflect.construct.sham) return false;
45
36
  if (typeof Proxy === "function") return true;
46
-
47
37
  try {
48
38
  Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
49
39
  return true;
@@ -51,10 +41,9 @@ function _isNativeReflectConstruct() {
51
41
  return false;
52
42
  }
53
43
  }
54
-
55
44
  function _construct(Parent, args, Class) {
56
45
  if (_isNativeReflectConstruct()) {
57
- _construct = Reflect.construct;
46
+ _construct = Reflect.construct.bind();
58
47
  } else {
59
48
  _construct = function _construct(Parent, args, Class) {
60
49
  var a = [null];
@@ -65,34 +54,25 @@ function _construct(Parent, args, Class) {
65
54
  return instance;
66
55
  };
67
56
  }
68
-
69
57
  return _construct.apply(null, arguments);
70
58
  }
71
-
72
59
  function _isNativeFunction(fn) {
73
60
  return Function.toString.call(fn).indexOf("[native code]") !== -1;
74
61
  }
75
-
76
62
  function _wrapNativeSuper(Class) {
77
63
  var _cache = typeof Map === "function" ? new Map() : undefined;
78
-
79
64
  _wrapNativeSuper = function _wrapNativeSuper(Class) {
80
65
  if (Class === null || !_isNativeFunction(Class)) return Class;
81
-
82
66
  if (typeof Class !== "function") {
83
67
  throw new TypeError("Super expression must either be null or a function");
84
68
  }
85
-
86
69
  if (typeof _cache !== "undefined") {
87
70
  if (_cache.has(Class)) return _cache.get(Class);
88
-
89
71
  _cache.set(Class, Wrapper);
90
72
  }
91
-
92
73
  function Wrapper() {
93
74
  return _construct(Class, arguments, _getPrototypeOf(this).constructor);
94
75
  }
95
-
96
76
  Wrapper.prototype = Object.create(Class.prototype, {
97
77
  constructor: {
98
78
  value: Wrapper,
@@ -103,22 +83,18 @@ function _wrapNativeSuper(Class) {
103
83
  });
104
84
  return _setPrototypeOf(Wrapper, Class);
105
85
  };
106
-
107
86
  return _wrapNativeSuper(Class);
108
87
  }
109
-
110
88
  function _objectWithoutPropertiesLoose(source, excluded) {
111
89
  if (source == null) return {};
112
90
  var target = {};
113
91
  var sourceKeys = Object.keys(source);
114
92
  var key, i;
115
-
116
93
  for (i = 0; i < sourceKeys.length; i++) {
117
94
  key = sourceKeys[i];
118
95
  if (excluded.indexOf(key) >= 0) continue;
119
96
  target[key] = source[key];
120
97
  }
121
-
122
98
  return target;
123
99
  }
124
100
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"use-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -3,7 +3,7 @@
3
3
  * Optionally `IntlMessages` can be provided to get type safety for message
4
4
  * namespaces and keys. See https://next-intl-docs.vercel.app/docs/usage/typescript
5
5
  */
6
- declare type AbstractIntlMessages = {
6
+ type AbstractIntlMessages = {
7
7
  [id: string]: AbstractIntlMessages | string;
8
8
  };
9
9
  export default AbstractIntlMessages;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
3
3
  */
4
- declare type DateTimeFormatOptions = Intl.DateTimeFormatOptions & {
4
+ type DateTimeFormatOptions = Intl.DateTimeFormatOptions & {
5
5
  /**
6
6
  * Examples:
7
7
  * - numeric: "2021"
@@ -1,6 +1,6 @@
1
1
  import DateTimeFormatOptions from './DateTimeFormatOptions';
2
2
  import NumberFormatOptions from './NumberFormatOptions';
3
- declare type Formats = {
3
+ type Formats = {
4
4
  number: Record<string, NumberFormatOptions>;
5
5
  dateTime: Record<string, DateTimeFormatOptions>;
6
6
  };
@@ -4,7 +4,7 @@ import { AbstractIntlMessages, RichTranslationValues } from '.';
4
4
  /**
5
5
  * Should be used for entry points that configure the library.
6
6
  */
7
- declare type IntlConfig<Messages = AbstractIntlMessages> = {
7
+ type IntlConfig<Messages = AbstractIntlMessages> = {
8
8
  /** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
9
9
  locale: string;
10
10
  /** Global formats can be provided to achieve consistent
@@ -46,7 +46,7 @@ declare type IntlConfig<Messages = AbstractIntlMessages> = {
46
46
  * A stricter set of the configuration that should be used internally
47
47
  * once defaults are assigned to `IntlConfiguration`.
48
48
  */
49
- export declare type InitializedIntlConfig<Messages = AbstractIntlMessages> = IntlConfig<Messages> & {
49
+ export type InitializedIntlConfig<Messages = AbstractIntlMessages> = IntlConfig<Messages> & {
50
50
  onError: NonNullable<IntlConfig<Messages>['onError']>;
51
51
  getMessageFallback: NonNullable<IntlConfig<Messages>['getMessageFallback']>;
52
52
  };
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- export declare type TranslationValue = string | number | boolean | Date | null | undefined;
3
- declare type TranslationValues = Record<string, TranslationValue>;
4
- export declare type RichTranslationValues = Record<string, TranslationValue | ((chunks: ReactNode) => ReactNode)>;
2
+ export type TranslationValue = string | number | boolean | Date | null | undefined;
3
+ type TranslationValues = Record<string, TranslationValue>;
4
+ export type RichTranslationValues = Record<string, TranslationValue | ((chunks: ReactNode) => ReactNode)>;
5
5
  export default TranslationValues;
@@ -13,14 +13,14 @@ export declare function getMessagesOrError<Messages extends AbstractIntlMessages
13
13
  namespace?: string;
14
14
  onError?(error: IntlError): void;
15
15
  }): AbstractIntlMessages | IntlError;
16
- export declare type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
16
+ export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
17
17
  cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;
18
18
  defaultTranslationValues?: RichTranslationValues;
19
19
  namespace?: string;
20
20
  messagesOrError: Messages | IntlError;
21
21
  };
22
22
  export default function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ cachedFormatsByLocale, defaultTranslationValues, formats: globalFormats, getMessageFallback, locale, messagesOrError, namespace, onError, timeZone }: CreateBaseTranslatorProps<Messages>): {
23
- <TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues | undefined, formats?: Partial<Formats> | undefined): string;
24
- rich: (key: string, values?: RichTranslationValues | undefined, formats?: Partial<Formats> | undefined) => string | ReactElement | ReactNodeArray;
23
+ <TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
24
+ rich: (key: string, values?: RichTranslationValues, formats?: Partial<Formats>) => string | ReactElement | ReactNodeArray;
25
25
  raw(key: string): any;
26
26
  };
@@ -2,7 +2,7 @@ import DateTimeFormatOptions from './DateTimeFormatOptions';
2
2
  import Formats from './Formats';
3
3
  import IntlError from './IntlError';
4
4
  import NumberFormatOptions from './NumberFormatOptions';
5
- declare type Props = {
5
+ type Props = {
6
6
  locale: string;
7
7
  timeZone?: string;
8
8
  onError?(error: IntlError): void;
@@ -10,8 +10,8 @@ declare type Props = {
10
10
  now?: Date;
11
11
  };
12
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 | bigint, formatOrOptions?: string | NumberFormatOptions | undefined) => string;
15
- relativeTime: (date: number | Date, now?: number | Date | undefined) => string;
13
+ dateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions) => string;
14
+ number: (value: number | bigint, formatOrOptions?: string | NumberFormatOptions) => string;
15
+ relativeTime: (date: number | Date, now?: number | Date) => string;
16
16
  };
17
17
  export {};
@@ -2,6 +2,6 @@ import createFormatter from './createFormatter';
2
2
  /** @deprecated Switch to `createFormatter` */
3
3
  export default function createIntl(...args: Parameters<typeof createFormatter>): {
4
4
  formatDateTime: (value: number | Date, formatOrOptions?: string | import("./DateTimeFormatOptions").default | undefined) => string;
5
- formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
5
+ formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
6
6
  formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
7
7
  };
@@ -14,7 +14,7 @@ import NestedValueOf from './utils/NestedValueOf';
14
14
  * The namespace can also indicate nesting by using a dot
15
15
  * (e.g. `namespace.Component`).
16
16
  */
17
- export default function createTranslator<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>({ onError, getMessageFallback, messages, namespace, ...rest }: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {
17
+ export default function createTranslator<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>({ getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {
18
18
  messages: NonNullable<IntlConfig<IntlMessages>['messages']>;
19
19
  namespace?: NestedKey;
20
20
  }): {
@@ -2,8 +2,8 @@ import AbstractIntlMessages from './AbstractIntlMessages';
2
2
  import { InitializedIntlConfig } from './IntlConfig';
3
3
  import { TranslationValue } from './TranslationValues';
4
4
  import NestedKeyOf from './utils/NestedKeyOf';
5
- export declare type CoreRichTranslationValues = Record<string, TranslationValue | ((chunks: string) => string)>;
6
- export declare type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
5
+ export type CoreRichTranslationValues = Record<string, TranslationValue | ((chunks: string) => string)>;
6
+ export type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
7
7
  namespace: string;
8
8
  messages: Messages;
9
9
  };
@@ -1,7 +1,6 @@
1
1
  import { inheritsLoose as _inheritsLoose, wrapNativeSuper as _wrapNativeSuper } from '../_virtual/use-intl.esm.js';
2
2
 
3
3
  var IntlErrorCode;
4
-
5
4
  (function (IntlErrorCode) {
6
5
  IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
7
6
  IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
@@ -10,31 +9,23 @@ var IntlErrorCode;
10
9
  IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
11
10
  IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
12
11
  })(IntlErrorCode || (IntlErrorCode = {}));
13
-
14
12
  var IntlError = /*#__PURE__*/function (_Error) {
15
13
  _inheritsLoose(IntlError, _Error);
16
-
17
14
  function IntlError(code, originalMessage) {
18
15
  var _this;
19
-
20
16
  var message = code;
21
-
22
17
  if (originalMessage) {
23
18
  message += ': ' + originalMessage;
24
19
  }
25
-
26
20
  _this = _Error.call(this, message) || this;
27
21
  _this.code = void 0;
28
22
  _this.originalMessage = void 0;
29
23
  _this.code = code;
30
-
31
24
  if (originalMessage) {
32
25
  _this.originalMessage = originalMessage;
33
26
  }
34
-
35
27
  return _this;
36
28
  }
37
-
38
29
  return IntlError;
39
30
  }( /*#__PURE__*/_wrapNativeSuper(Error));
40
31
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm.js","sources":["../../src/core/IntlError.tsx"],"sourcesContent":["export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\n INVALID_KEY = 'INVALID_KEY',\n FORMATTING_ERROR = 'FORMATTING_ERROR'\n}\n\nexport default class IntlError extends Error {\n public readonly code: IntlErrorCode;\n public readonly originalMessage: string | undefined;\n\n constructor(code: IntlErrorCode, originalMessage?: string) {\n let message: string = code;\n if (originalMessage) {\n message += ': ' + originalMessage;\n }\n super(message);\n\n this.code = code;\n if (originalMessage) {\n this.originalMessage = originalMessage;\n }\n }\n}\n"],"names":["IntlErrorCode","IntlError","code","originalMessage","message","Error"],"mappings":";;IAAYA,cAAZ;;AAAA,CAAA,UAAYA,aAAZ,EAAyB;AACvBA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,gBAAA,CAAA,GAAA,gBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,mBAAA,CAAA,GAAA,mBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,kBAAA,CAAA;AACD,CAPD,EAAYA,aAAa,KAAbA,aAAa,GAOxB,EAPwB,CAAzB,CAAA,CAAA;;IASqBC;;;AAInB,EAAYC,SAAAA,SAAAA,CAAAA,IAAZ,EAAiCC,eAAjC,EAAyD;AAAA,IAAA,IAAA,KAAA,CAAA;;AACvD,IAAIC,IAAAA,OAAO,GAAWF,IAAtB,CAAA;;AACA,IAAA,IAAIC,eAAJ,EAAqB;AACnBC,MAAAA,OAAO,IAAI,IAAA,GAAOD,eAAlB,CAAA;AACD,KAAA;;AACD,IAAA,KAAA,GAAA,MAAA,CAAA,IAAA,CAAA,IAAA,EAAMC,OAAN,CAAA,IAAA,IAAA,CAAA;AALuD,IAAA,KAAA,CAHzCF,IAGyC,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,KAAA,CAFzCC,eAEyC,GAAA,KAAA,CAAA,CAAA;AAOvD,IAAKD,KAAAA,CAAAA,IAAL,GAAYA,IAAZ,CAAA;;AACA,IAAA,IAAIC,eAAJ,EAAqB;AACnB,MAAKA,KAAAA,CAAAA,eAAL,GAAuBA,eAAvB,CAAA;AACD,KAAA;;AAVsD,IAAA,OAAA,KAAA,CAAA;AAWxD,GAAA;;;iCAfoCE;;;;"}
1
+ {"version":3,"file":"use-intl.esm.js","sources":["../../src/core/IntlError.tsx"],"sourcesContent":["export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\n INVALID_KEY = 'INVALID_KEY',\n FORMATTING_ERROR = 'FORMATTING_ERROR'\n}\n\nexport default class IntlError extends Error {\n public readonly code: IntlErrorCode;\n public readonly originalMessage: string | undefined;\n\n constructor(code: IntlErrorCode, originalMessage?: string) {\n let message: string = code;\n if (originalMessage) {\n message += ': ' + originalMessage;\n }\n super(message);\n\n this.code = code;\n if (originalMessage) {\n this.originalMessage = originalMessage;\n }\n }\n}\n"],"names":["IntlErrorCode","IntlError","_Error","_inheritsLoose","code","originalMessage","_this","message","call","_wrapNativeSuper","Error"],"mappings":";;IAAYA,cAOX;AAPD,CAAA,UAAYA,aAAa,EAAA;AACvBA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC,CAAA;AACnCA,EAAAA,aAAA,CAAA,gBAAA,CAAA,GAAA,gBAAiC,CAAA;AACjCA,EAAAA,aAAA,CAAA,mBAAA,CAAA,GAAA,mBAAuC,CAAA;AACvCA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC,CAAA;AACnCA,EAAAA,aAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;AAC3BA,EAAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,kBAAqC,CAAA;AACvC,CAAC,EAPWA,aAAa,KAAbA,aAAa,GAOxB,EAAA,CAAA,CAAA,CAAA;AAEoBC,IAAAA,SAAU,0BAAAC,MAAA,EAAA;EAAAC,cAAA,CAAAF,SAAA,EAAAC,MAAA,CAAA,CAAA;AAI7B,EAAA,SAAAD,SAAYG,CAAAA,IAAmB,EAAEC,eAAwB,EAAA;AAAA,IAAA,IAAAC,KAAA,CAAA;IACvD,IAAIC,OAAO,GAAWH,IAAI,CAAA;AAC1B,IAAA,IAAIC,eAAe,EAAE;MACnBE,OAAO,IAAI,IAAI,GAAGF,eAAe,CAAA;AAClC,KAAA;AACDC,IAAAA,KAAA,GAAAJ,MAAA,CAAAM,IAAA,CAAA,IAAA,EAAMD,OAAO,CAAC,IAAA,IAAA,CAAA;AAACD,IAAAA,KAAA,CARDF,IAAI,GAAA,KAAA,CAAA,CAAA;AAAAE,IAAAA,KAAA,CACJD,eAAe,GAAA,KAAA,CAAA,CAAA;IAS7BC,KAAA,CAAKF,IAAI,GAAGA,IAAI,CAAA;AAChB,IAAA,IAAIC,eAAe,EAAE;MACnBC,KAAA,CAAKD,eAAe,GAAGA,eAAe,CAAA;AACvC,KAAA;AAAA,IAAA,OAAAC,KAAA,CAAA;AACH,GAAA;AAAC,EAAA,OAAAL,SAAA,CAAA;AAAA,CAAAQ,eAAAA,gBAAA,CAfoCC,KAAK,CAAA;;;;"}
@@ -1,9 +1,9 @@
1
1
  import { extends as _extends } from '../_virtual/use-intl.esm.js';
2
2
 
3
3
  function setTimeZoneInFormats(formats, timeZone) {
4
- if (!formats) return formats; // The only way to set a time zone with `intl-messageformat` is to merge it into the formats
4
+ if (!formats) return formats;
5
+ // The only way to set a time zone with `intl-messageformat` is to merge it into the formats
5
6
  // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15
6
-
7
7
  return Object.keys(formats).reduce(function (acc, key) {
8
8
  acc[key] = _extends({
9
9
  timeZone: timeZone
@@ -18,8 +18,6 @@ function setTimeZoneInFormats(formats, timeZone) {
18
18
  * seem so useful. We offer a single `dateTime` namespace instead, but we have
19
19
  * to convert the format before `intl-messageformat` can be used.
20
20
  */
21
-
22
-
23
21
  function convertFormatsToIntlMessageFormat(formats, timeZone) {
24
22
  var formatsWithTimeZone = timeZone ? _extends({}, formats, {
25
23
  dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm10.js","sources":["../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["import {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: string\n) {\n if (!formats) return formats;\n\n // The only way to set a time zone with `intl-messageformat` is to merge it into the formats\n // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15\n return Object.keys(formats).reduce(\n (acc: Record<string, DateTimeFormatOptions>, key) => {\n acc[key] = {\n timeZone,\n ...formats[key]\n };\n return acc;\n },\n {}\n );\n}\n\n/**\n * `intl-messageformat` uses separate keys for `date` and `time`, but there's\n * only one native API: `Intl.DateTimeFormat`. Additionally you might want to\n * include both a time and a date in a value, therefore the separation doesn't\n * seem so useful. We offer a single `dateTime` namespace instead, but we have\n * to convert the format before `intl-messageformat` can be used.\n */\nexport default function convertFormatsToIntlMessageFormat(\n formats: Partial<Formats>,\n timeZone?: string\n): Partial<IntlFormats> {\n const formatsWithTimeZone = timeZone\n ? {...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)}\n : formats;\n\n return {\n ...formatsWithTimeZone,\n date: formatsWithTimeZone?.dateTime,\n time: formatsWithTimeZone?.dateTime\n };\n}\n"],"names":["setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","key","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time"],"mappings":";;AAIA,SAASA,oBAAT,CACEC,OADF,EAEEC,QAFF,EAEkB;AAEhB,EAAA,IAAI,CAACD,OAAL,EAAc,OAAOA,OAAP,CAFE;AAKhB;;AACA,EAAA,OAAOE,MAAM,CAACC,IAAP,CAAYH,OAAZ,CAAA,CAAqBI,MAArB,CACL,UAACC,GAAD,EAA6CC,GAA7C,EAAoD;AAClDD,IAAAA,GAAG,CAACC,GAAD,CAAH,GAAA,QAAA,CAAA;AACEL,MAAAA,QAAQ,EAARA,QAAAA;AADF,KAEKD,EAAAA,OAAO,CAACM,GAAD,CAFZ,CAAA,CAAA;AAIA,IAAA,OAAOD,GAAP,CAAA;AACD,GAPI,EAQL,EARK,CAAP,CAAA;AAUD,CAAA;AAED;;;;;;AAMG;;;AACW,SAAUE,iCAAV,CACZP,OADY,EAEZC,QAFY,EAEK;AAEjB,EAAA,IAAMO,mBAAmB,GAAGP,QAAQ,GAAA,QAAA,CAAA,EAAA,EAC5BD,OAD4B,EAAA;AACnBS,IAAAA,QAAQ,EAAEV,oBAAoB,CAACC,OAAO,CAACS,QAAT,EAAmBR,QAAnB,CAAA;AADX,GAAA,CAAA,GAEhCD,OAFJ,CAAA;AAIA,EAAA,OAAA,QAAA,CAAA,EAAA,EACKQ,mBADL,EAAA;AAEEE,IAAAA,IAAI,EAAEF,mBAAF,IAAEA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,mBAAmB,CAAEC,QAF7B;AAGEE,IAAAA,IAAI,EAAEH,mBAAF,IAAA,IAAA,GAAA,KAAA,CAAA,GAAEA,mBAAmB,CAAEC,QAAAA;AAH7B,GAAA,CAAA,CAAA;AAKD;;;;"}
1
+ {"version":3,"file":"use-intl.esm10.js","sources":["../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["import {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: string\n) {\n if (!formats) return formats;\n\n // The only way to set a time zone with `intl-messageformat` is to merge it into the formats\n // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15\n return Object.keys(formats).reduce(\n (acc: Record<string, DateTimeFormatOptions>, key) => {\n acc[key] = {\n timeZone,\n ...formats[key]\n };\n return acc;\n },\n {}\n );\n}\n\n/**\n * `intl-messageformat` uses separate keys for `date` and `time`, but there's\n * only one native API: `Intl.DateTimeFormat`. Additionally you might want to\n * include both a time and a date in a value, therefore the separation doesn't\n * seem so useful. We offer a single `dateTime` namespace instead, but we have\n * to convert the format before `intl-messageformat` can be used.\n */\nexport default function convertFormatsToIntlMessageFormat(\n formats: Partial<Formats>,\n timeZone?: string\n): Partial<IntlFormats> {\n const formatsWithTimeZone = timeZone\n ? {...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)}\n : formats;\n\n return {\n ...formatsWithTimeZone,\n date: formatsWithTimeZone?.dateTime,\n time: formatsWithTimeZone?.dateTime\n };\n}\n"],"names":["setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","key","_extends","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time"],"mappings":";;AAIA,SAASA,oBAAoBA,CAC3BC,OAA0D,EAC1DC,QAAgB,EAAA;AAEhB,EAAA,IAAI,CAACD,OAAO,EAAE,OAAOA,OAAO,CAAA;AAE5B;AACA;AACA,EAAA,OAAOE,MAAM,CAACC,IAAI,CAACH,OAAO,CAAC,CAACI,MAAM,CAChC,UAACC,GAA0C,EAAEC,GAAG,EAAI;AAClDD,IAAAA,GAAG,CAACC,GAAG,CAAC,GAAAC,QAAA,CAAA;AACNN,MAAAA,QAAQ,EAARA,QAAAA;AAAQ,KAAA,EACLD,OAAO,CAACM,GAAG,CAAC,CAChB,CAAA;AACD,IAAA,OAAOD,GAAG,CAAA;GACX,EACD,EAAE,CACH,CAAA;AACH,CAAA;AAEA;;;;;;AAMG;AACW,SAAUG,iCAAiCA,CACvDR,OAAyB,EACzBC,QAAiB,EAAA;AAEjB,EAAA,IAAMQ,mBAAmB,GAAGR,QAAQ,GAAAM,QAAA,KAC5BP,OAAO,EAAA;AAAEU,IAAAA,QAAQ,EAAEX,oBAAoB,CAACC,OAAO,CAACU,QAAQ,EAAET,QAAQ,CAAA;AAAC,GAAA,CAAA,GACvED,OAAO,CAAA;EAEX,OAAAO,QAAA,KACKE,mBAAmB,EAAA;AACtBE,IAAAA,IAAI,EAAEF,mBAAmB,IAAnBA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,mBAAmB,CAAEC,QAAQ;AACnCE,IAAAA,IAAI,EAAEH,mBAAmB,IAAnBA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,mBAAmB,CAAEC,QAAAA;AAAQ,GAAA,CAAA,CAAA;AAEvC;;;;"}
@@ -1,8 +1,8 @@
1
1
  import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
2
  import createTranslatorImpl from './use-intl.esm5.js';
3
- import { defaultOnError, defaultGetMessageFallback } from './use-intl.esm6.js';
3
+ import { defaultGetMessageFallback, defaultOnError } from './use-intl.esm6.js';
4
4
 
5
- var _excluded = ["onError", "getMessageFallback", "messages", "namespace"];
5
+ var _excluded = ["getMessageFallback", "messages", "namespace", "onError"];
6
6
  /**
7
7
  * Translates messages from the given namespace by using the ICU syntax.
8
8
  * See https://formatjs.io/docs/core-concepts/icu-syntax.
@@ -11,16 +11,14 @@ var _excluded = ["onError", "getMessageFallback", "messages", "namespace"];
11
11
  * The namespace can also indicate nesting by using a dot
12
12
  * (e.g. `namespace.Component`).
13
13
  */
14
-
15
14
  function createTranslator(_ref) {
16
- var _ref$onError = _ref.onError,
17
- onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
18
- _ref$getMessageFallba = _ref.getMessageFallback,
19
- getMessageFallback = _ref$getMessageFallba === void 0 ? defaultGetMessageFallback : _ref$getMessageFallba,
20
- messages = _ref.messages,
21
- namespace = _ref.namespace,
22
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
23
-
15
+ var _ref$getMessageFallba = _ref.getMessageFallback,
16
+ getMessageFallback = _ref$getMessageFallba === void 0 ? defaultGetMessageFallback : _ref$getMessageFallba,
17
+ messages = _ref.messages,
18
+ namespace = _ref.namespace,
19
+ _ref$onError = _ref.onError,
20
+ onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
21
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
24
22
  // We have to wrap the actual function so the type inference for the optional
25
23
  // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
26
24
  // The prefix ("!") is arbitrary.
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm2.js","sources":["../../src/core/createTranslator.tsx"],"sourcesContent":["import Formats from './Formats';\nimport IntlConfig from './IntlConfig';\nimport TranslationValues from './TranslationValues';\nimport createTranslatorImpl, {\n CoreRichTranslationValues\n} from './createTranslatorImpl';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NamespaceKeys from './utils/NamespaceKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\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 createTranslator<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>({\n onError = defaultOnError,\n getMessageFallback = defaultGetMessageFallback,\n messages,\n namespace,\n ...rest\n}: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {\n messages: NonNullable<IntlConfig<IntlMessages>['messages']>;\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?: CoreRichTranslationValues,\n formats?: Partial<Formats>\n ): string;\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 // We have to wrap the actual function 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 createTranslatorImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {\n ...rest,\n onError,\n getMessageFallback,\n messages: {'!': messages},\n // @ts-ignore\n namespace: namespace ? `!.${namespace}` : '!'\n },\n '!'\n );\n}\n"],"names":["createTranslator","onError","defaultOnError","getMessageFallback","defaultGetMessageFallback","messages","namespace","rest","createTranslatorImpl"],"mappings":";;;;;AAYA;;;;;;;AAOG;;AACqB,SAAAA,gBAAA,CAcvB,IAAA,EAAA;AAAA,EAAA,IAAA,YAAA,GAAA,IAAA,CARCC,OAQD;AAAA,MARCA,OAQD,6BARWC,cAQX,GAAA,YAAA;AAAA,MAAA,qBAAA,GAAA,IAAA,CAPCC,kBAOD;AAAA,MAPCA,kBAOD,sCAPsBC,yBAOtB,GAAA,qBAAA;AAAA,MANCC,QAMD,QANCA,QAMD;AAAA,MALCC,SAKD,QALCA,SAKD;AAAA,MAJIC,IAIJ,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AA4DC;AACA;AACA;AACA,EAAOC,OAAAA,oBAAoB,cAKpBD,IALoB,EAAA;AAMvBN,IAAAA,OAAO,EAAPA,OANuB;AAOvBE,IAAAA,kBAAkB,EAAlBA,kBAPuB;AAQvBE,IAAAA,QAAQ,EAAE;AAAC,MAAKA,GAAAA,EAAAA,QAAAA;AAAN,KARa;AASvB;AACAC,IAAAA,SAAS,EAAEA,SAAS,GAAA,IAAA,GAAQA,SAAR,GAAsB,GAAA;AAVnB,GAAA,CAAA,EAYzB,GAZyB,CAA3B,CAAA;AAcD;;;;"}
1
+ {"version":3,"file":"use-intl.esm2.js","sources":["../../src/core/createFormatter.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport {defaultOnError} from './defaults';\n\nconst MINUTE = 60;\nconst HOUR = MINUTE * 60;\nconst DAY = HOUR * 24;\nconst WEEK = DAY * 7;\nconst MONTH = DAY * (365 / 12); // Approximation\nconst YEAR = DAY * 365;\n\nfunction getRelativeTimeFormatConfig(seconds: number) {\n const absValue = Math.abs(seconds);\n let value, unit: Intl.RelativeTimeFormatUnit;\n\n // We have to round the resulting values, as `Intl.RelativeTimeFormat`\n // will include fractions like '2.1 hours ago'.\n\n if (absValue < MINUTE) {\n unit = 'second';\n value = Math.round(seconds);\n } else if (absValue < HOUR) {\n unit = 'minute';\n value = Math.round(seconds / MINUTE);\n } else if (absValue < DAY) {\n unit = 'hour';\n value = Math.round(seconds / HOUR);\n } else if (absValue < WEEK) {\n unit = 'day';\n value = Math.round(seconds / DAY);\n } else if (absValue < MONTH) {\n unit = 'week';\n value = Math.round(seconds / WEEK);\n } else if (absValue < YEAR) {\n unit = 'month';\n value = Math.round(seconds / MONTH);\n } else {\n unit = 'year';\n value = Math.round(seconds / YEAR);\n }\n\n return {value, unit};\n}\n\ntype Props = {\n locale: string;\n timeZone?: string;\n onError?(error: IntlError): void;\n formats?: Partial<Formats>;\n now?: Date;\n};\n\nexport default function createFormatter({\n formats,\n locale,\n now: globalNow,\n onError = defaultOnError,\n timeZone\n}: Props) {\n function resolveFormatOrOptions<Options>(\n typeFormats: Record<string, Options> | undefined,\n formatOrOptions?: string | Options\n ) {\n let options;\n if (typeof formatOrOptions === 'string') {\n const formatName = formatOrOptions;\n options = typeFormats?.[formatName];\n\n if (!options) {\n const error = new IntlError(\n IntlErrorCode.MISSING_FORMAT,\n process.env.NODE_ENV !== 'production'\n ? `Format \\`${formatName}\\` is not available. You can configure it on the provider or provide custom options.`\n : undefined\n );\n onError(error);\n throw error;\n }\n } else {\n options = formatOrOptions;\n }\n\n return options;\n }\n\n function getFormattedValue<Value, Options>(\n value: Value,\n formatOrOptions: string | Options | undefined,\n typeFormats: Record<string, Options> | undefined,\n formatter: (options?: Options) => string\n ) {\n let options;\n try {\n options = resolveFormatOrOptions(typeFormats, formatOrOptions);\n } catch (error) {\n return String(value);\n }\n\n try {\n return formatter(options);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(value);\n }\n }\n\n function dateTime(\n /** If a number is supplied, this is interpreted as a UTC timestamp. */\n value: Date | number,\n /** If a time zone is supplied, the `value` is converted to that time zone.\n * Otherwise the user time zone will be used. */\n formatOrOptions?: string | DateTimeFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.dateTime,\n (options) => {\n if (timeZone && !options?.timeZone) {\n options = {...options, timeZone};\n }\n\n return new Intl.DateTimeFormat(locale, options).format(value);\n }\n );\n }\n\n function number(\n value: number | bigint,\n formatOrOptions?: string | NumberFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.number,\n (options) => new Intl.NumberFormat(locale, options).format(value)\n );\n }\n\n function relativeTime(\n /** The date time that needs to be formatted. */\n date: number | Date,\n /** The reference point in time to which `date` will be formatted in relation to. */\n now?: number | Date\n ) {\n try {\n if (!now) {\n if (globalNow) {\n now = globalNow;\n } else {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `The \\`now\\` parameter wasn't provided and there was no global fallback configured on the provider.`\n : undefined\n );\n }\n }\n\n const dateDate = date instanceof Date ? date : new Date(date);\n const nowDate = now instanceof Date ? now : new Date(now);\n\n const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;\n const {unit, value} = getRelativeTimeFormatConfig(seconds);\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto'\n }).format(value, unit);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(date);\n }\n }\n\n return {dateTime, number, relativeTime};\n}\n"],"names":["MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","value","unit","round","createFormatter","_ref","formats","locale","globalNow","now","_ref$onError","onError","defaultOnError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","process","env","NODE_ENV","undefined","getFormattedValue","formatter","String","FORMATTING_ERROR","message","dateTime","_options","_extends","Intl","DateTimeFormat","format","number","NumberFormat","relativeTime","date","Error","dateDate","Date","nowDate","getTime","_getRelativeTimeForma","RelativeTimeFormat","numeric"],"mappings":";;;;AAMA,IAAMA,MAAM,GAAG,EAAE,CAAA;AACjB,IAAMC,IAAI,GAAGD,MAAM,GAAG,EAAE,CAAA;AACxB,IAAME,GAAG,GAAGD,IAAI,GAAG,EAAE,CAAA;AACrB,IAAME,IAAI,GAAGD,GAAG,GAAG,CAAC,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,CAAA;AAElB,MAAA,OAAO,IAAIkC,IAAI,CAACa,kBAAkB,CAACzC,MAAM,EAAE;AACzC0C,QAAAA,OAAO,EAAE,MAAA;AACV,OAAA,CAAC,CAACZ,MAAM,CAACpC,KAAK,EAAEC,IAAI,CAAC,CAAA;KACvB,CAAC,OAAOiB,KAAK,EAAE;AACdR,MAAAA,OAAO,CACL,IAAIS,SAAS,CAACC,aAAa,CAACS,gBAAgB,EAAGX,KAAe,CAACY,OAAO,CAAC,CACxE,CAAA;MACD,OAAOF,MAAM,CAACY,IAAI,CAAC,CAAA;AACpB,KAAA;AACH,GAAA;EAEA,OAAO;AAACT,IAAAA,QAAQ,EAARA,QAAQ;AAAEM,IAAAA,MAAM,EAANA,MAAM;AAAEE,IAAAA,YAAY,EAAZA,YAAAA;GAAa,CAAA;AACzC;;;;"}
@@ -7,14 +7,12 @@ var HOUR = MINUTE * 60;
7
7
  var DAY = HOUR * 24;
8
8
  var WEEK = DAY * 7;
9
9
  var MONTH = DAY * (365 / 12); // Approximation
10
-
11
10
  var YEAR = DAY * 365;
12
-
13
11
  function getRelativeTimeFormatConfig(seconds) {
14
12
  var absValue = Math.abs(seconds);
15
- var value, unit; // We have to round the resulting values, as `Intl.RelativeTimeFormat`
13
+ var value, unit;
14
+ // We have to round the resulting values, as `Intl.RelativeTimeFormat`
16
15
  // will include fractions like '2.1 hours ago'.
17
-
18
16
  if (absValue < MINUTE) {
19
17
  unit = 'second';
20
18
  value = Math.round(seconds);
@@ -37,28 +35,23 @@ function getRelativeTimeFormatConfig(seconds) {
37
35
  unit = 'year';
38
36
  value = Math.round(seconds / YEAR);
39
37
  }
40
-
41
38
  return {
42
39
  value: value,
43
40
  unit: unit
44
41
  };
45
42
  }
46
-
47
43
  function createFormatter(_ref) {
48
44
  var formats = _ref.formats,
49
- locale = _ref.locale,
50
- globalNow = _ref.now,
51
- _ref$onError = _ref.onError,
52
- onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
53
- timeZone = _ref.timeZone;
54
-
45
+ locale = _ref.locale,
46
+ globalNow = _ref.now,
47
+ _ref$onError = _ref.onError,
48
+ onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
49
+ timeZone = _ref.timeZone;
55
50
  function resolveFormatOrOptions(typeFormats, formatOrOptions) {
56
51
  var options;
57
-
58
52
  if (typeof formatOrOptions === 'string') {
59
53
  var formatName = formatOrOptions;
60
54
  options = typeFormats == null ? void 0 : typeFormats[formatName];
61
-
62
55
  if (!options) {
63
56
  var error = new IntlError(IntlErrorCode.MISSING_FORMAT, process.env.NODE_ENV !== 'production' ? "Format `" + formatName + "` is not available. You can configure it on the provider or provide custom options." : undefined);
64
57
  onError(error);
@@ -67,19 +60,15 @@ function createFormatter(_ref) {
67
60
  } else {
68
61
  options = formatOrOptions;
69
62
  }
70
-
71
63
  return options;
72
64
  }
73
-
74
65
  function getFormattedValue(value, formatOrOptions, typeFormats, formatter) {
75
66
  var options;
76
-
77
67
  try {
78
68
  options = resolveFormatOrOptions(typeFormats, formatOrOptions);
79
69
  } catch (error) {
80
70
  return String(value);
81
71
  }
82
-
83
72
  try {
84
73
  return formatter(options);
85
74
  } catch (error) {
@@ -87,36 +76,28 @@ function createFormatter(_ref) {
87
76
  return String(value);
88
77
  }
89
78
  }
90
-
91
- function dateTime(
92
- /** If a number is supplied, this is interpreted as a UTC timestamp. */
79
+ function dateTime( /** If a number is supplied, this is interpreted as a UTC timestamp. */
93
80
  value,
94
81
  /** If a time zone is supplied, the `value` is converted to that time zone.
95
82
  * Otherwise the user time zone will be used. */
96
83
  formatOrOptions) {
97
84
  return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.dateTime, function (options) {
98
85
  var _options;
99
-
100
86
  if (timeZone && !((_options = options) != null && _options.timeZone)) {
101
87
  options = _extends({}, options, {
102
88
  timeZone: timeZone
103
89
  });
104
90
  }
105
-
106
91
  return new Intl.DateTimeFormat(locale, options).format(value);
107
92
  });
108
93
  }
109
-
110
94
  function number(value, formatOrOptions) {
111
95
  return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.number, function (options) {
112
96
  return new Intl.NumberFormat(locale, options).format(value);
113
97
  });
114
98
  }
115
-
116
- function relativeTime(
117
- /** The date time that needs to be formatted. */
118
- date,
119
- /** The reference point in time to which `date` will be formatted in relation to. */
99
+ function relativeTime( /** The date time that needs to be formatted. */
100
+ date, /** The reference point in time to which `date` will be formatted in relation to. */
120
101
  now) {
121
102
  try {
122
103
  if (!now) {
@@ -126,15 +107,12 @@ function createFormatter(_ref) {
126
107
  throw new Error(process.env.NODE_ENV !== 'production' ? "The `now` parameter wasn't provided and there was no global fallback configured on the provider." : undefined);
127
108
  }
128
109
  }
129
-
130
110
  var dateDate = date instanceof Date ? date : new Date(date);
131
111
  var nowDate = now instanceof Date ? now : new Date(now);
132
112
  var seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
133
-
134
113
  var _getRelativeTimeForma = getRelativeTimeFormatConfig(seconds),
135
- unit = _getRelativeTimeForma.unit,
136
- value = _getRelativeTimeForma.value;
137
-
114
+ unit = _getRelativeTimeForma.unit,
115
+ value = _getRelativeTimeForma.value;
138
116
  return new Intl.RelativeTimeFormat(locale, {
139
117
  numeric: 'auto'
140
118
  }).format(value, unit);
@@ -143,7 +121,6 @@ function createFormatter(_ref) {
143
121
  return String(date);
144
122
  }
145
123
  }
146
-
147
124
  return {
148
125
  dateTime: dateTime,
149
126
  number: number,
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm3.js","sources":["../../src/core/createFormatter.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport {defaultOnError} from './defaults';\n\nconst MINUTE = 60;\nconst HOUR = MINUTE * 60;\nconst DAY = HOUR * 24;\nconst WEEK = DAY * 7;\nconst MONTH = DAY * (365 / 12); // Approximation\nconst YEAR = DAY * 365;\n\nfunction getRelativeTimeFormatConfig(seconds: number) {\n const absValue = Math.abs(seconds);\n let value, unit: Intl.RelativeTimeFormatUnit;\n\n // We have to round the resulting values, as `Intl.RelativeTimeFormat`\n // will include fractions like '2.1 hours ago'.\n\n if (absValue < MINUTE) {\n unit = 'second';\n value = Math.round(seconds);\n } else if (absValue < HOUR) {\n unit = 'minute';\n value = Math.round(seconds / MINUTE);\n } else if (absValue < DAY) {\n unit = 'hour';\n value = Math.round(seconds / HOUR);\n } else if (absValue < WEEK) {\n unit = 'day';\n value = Math.round(seconds / DAY);\n } else if (absValue < MONTH) {\n unit = 'week';\n value = Math.round(seconds / WEEK);\n } else if (absValue < YEAR) {\n unit = 'month';\n value = Math.round(seconds / MONTH);\n } else {\n unit = 'year';\n value = Math.round(seconds / YEAR);\n }\n\n return {value, unit};\n}\n\ntype Props = {\n locale: string;\n timeZone?: string;\n onError?(error: IntlError): void;\n formats?: Partial<Formats>;\n now?: Date;\n};\n\nexport default function createFormatter({\n formats,\n locale,\n now: globalNow,\n onError = defaultOnError,\n timeZone\n}: Props) {\n function resolveFormatOrOptions<Options>(\n typeFormats: Record<string, Options> | undefined,\n formatOrOptions?: string | Options\n ) {\n let options;\n if (typeof formatOrOptions === 'string') {\n const formatName = formatOrOptions;\n options = typeFormats?.[formatName];\n\n if (!options) {\n const error = new IntlError(\n IntlErrorCode.MISSING_FORMAT,\n process.env.NODE_ENV !== 'production'\n ? `Format \\`${formatName}\\` is not available. You can configure it on the provider or provide custom options.`\n : undefined\n );\n onError(error);\n throw error;\n }\n } else {\n options = formatOrOptions;\n }\n\n return options;\n }\n\n function getFormattedValue<Value, Options>(\n value: Value,\n formatOrOptions: string | Options | undefined,\n typeFormats: Record<string, Options> | undefined,\n formatter: (options?: Options) => string\n ) {\n let options;\n try {\n options = resolveFormatOrOptions(typeFormats, formatOrOptions);\n } catch (error) {\n return String(value);\n }\n\n try {\n return formatter(options);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(value);\n }\n }\n\n function dateTime(\n /** If a number is supplied, this is interpreted as a UTC timestamp. */\n value: Date | number,\n /** If a time zone is supplied, the `value` is converted to that time zone.\n * Otherwise the user time zone will be used. */\n formatOrOptions?: string | DateTimeFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.dateTime,\n (options) => {\n if (timeZone && !options?.timeZone) {\n options = {...options, timeZone};\n }\n\n return new Intl.DateTimeFormat(locale, options).format(value);\n }\n );\n }\n\n function number(\n value: number | bigint,\n formatOrOptions?: string | NumberFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.number,\n (options) => new Intl.NumberFormat(locale, options).format(value)\n );\n }\n\n function relativeTime(\n /** The date time that needs to be formatted. */\n date: number | Date,\n /** The reference point in time to which `date` will be formatted in relation to. */\n now?: number | Date\n ) {\n try {\n if (!now) {\n if (globalNow) {\n now = globalNow;\n } else {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `The \\`now\\` parameter wasn't provided and there was no global fallback configured on the provider.`\n : undefined\n );\n }\n }\n\n const dateDate = date instanceof Date ? date : new Date(date);\n const nowDate = now instanceof Date ? now : new Date(now);\n\n const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;\n const {unit, value} = getRelativeTimeFormatConfig(seconds);\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto'\n }).format(value, unit);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(date);\n }\n }\n\n return {dateTime, number, relativeTime};\n}\n"],"names":["MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","value","unit","round","createFormatter","formats","locale","globalNow","now","onError","defaultOnError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","process","env","NODE_ENV","undefined","getFormattedValue","formatter","String","FORMATTING_ERROR","message","dateTime","Intl","DateTimeFormat","format","number","NumberFormat","relativeTime","date","Error","dateDate","Date","nowDate","getTime","RelativeTimeFormat","numeric"],"mappings":";;;;AAMA,IAAMA,MAAM,GAAG,EAAf,CAAA;AACA,IAAMC,IAAI,GAAGD,MAAM,GAAG,EAAtB,CAAA;AACA,IAAME,GAAG,GAAGD,IAAI,GAAG,EAAnB,CAAA;AACA,IAAME,IAAI,GAAGD,GAAG,GAAG,CAAnB,CAAA;AACA,IAAME,KAAK,GAAGF,GAAG,IAAI,MAAM,EAAV,CAAjB;;AACA,IAAMG,IAAI,GAAGH,GAAG,GAAG,GAAnB,CAAA;;AAEA,SAASI,2BAAT,CAAqCC,OAArC,EAAoD;AAClD,EAAA,IAAMC,QAAQ,GAAGC,IAAI,CAACC,GAAL,CAASH,OAAT,CAAjB,CAAA;AACA,EAAA,IAAII,KAAJ,EAAWC,IAAX,CAFkD;AAKlD;;AAEA,EAAIJ,IAAAA,QAAQ,GAAGR,MAAf,EAAuB;AACrBY,IAAAA,IAAI,GAAG,QAAP,CAAA;AACAD,IAAAA,KAAK,GAAGF,IAAI,CAACI,KAAL,CAAWN,OAAX,CAAR,CAAA;AACD,GAHD,MAGO,IAAIC,QAAQ,GAAGP,IAAf,EAAqB;AAC1BW,IAAAA,IAAI,GAAG,QAAP,CAAA;AACAD,IAAAA,KAAK,GAAGF,IAAI,CAACI,KAAL,CAAWN,OAAO,GAAGP,MAArB,CAAR,CAAA;AACD,GAHM,MAGA,IAAIQ,QAAQ,GAAGN,GAAf,EAAoB;AACzBU,IAAAA,IAAI,GAAG,MAAP,CAAA;AACAD,IAAAA,KAAK,GAAGF,IAAI,CAACI,KAAL,CAAWN,OAAO,GAAGN,IAArB,CAAR,CAAA;AACD,GAHM,MAGA,IAAIO,QAAQ,GAAGL,IAAf,EAAqB;AAC1BS,IAAAA,IAAI,GAAG,KAAP,CAAA;AACAD,IAAAA,KAAK,GAAGF,IAAI,CAACI,KAAL,CAAWN,OAAO,GAAGL,GAArB,CAA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C,CAAA;AACA,MAAA,IAAMI,OAAO,GAAGjC,GAAG,YAAYgC,IAAf,GAAsBhC,GAAtB,GAA4B,IAAIgC,IAAJ,CAAShC,GAAT,CAA5C,CAAA;AAEA,MAAA,IAAMX,OAAO,GAAG,CAAC0C,QAAQ,CAACG,OAAT,EAAqBD,GAAAA,OAAO,CAACC,OAAR,EAAtB,IAA2C,IAA3D,CAAA;;AACA,MAAsB9C,IAAAA,qBAAAA,GAAAA,2BAA2B,CAACC,OAAD,CAAjD;AAAA,UAAOK,IAAP,yBAAOA,IAAP;AAAA,UAAaD,KAAb,yBAAaA,KAAb,CAAA;;AAEA,MAAA,OAAO,IAAI8B,IAAI,CAACY,kBAAT,CAA4BrC,MAA5B,EAAoC;AACzCsC,QAAAA,OAAO,EAAE,MAAA;AADgC,OAApC,EAEJX,MAFI,CAEGhC,KAFH,EAEUC,IAFV,CAAP,CAAA;AAGD,KAtBD,CAsBE,OAAOe,KAAP,EAAc;AACdR,MAAAA,OAAO,CACL,IAAIS,SAAJ,CAAcC,aAAa,CAACS,gBAA5B,EAA+CX,KAAe,CAACY,OAA/D,CADK,CAAP,CAAA;AAGA,MAAOF,OAAAA,MAAM,CAACU,IAAD,CAAb,CAAA;AACD,KAAA;AACF,GAAA;;AAED,EAAO,OAAA;AAACP,IAAAA,QAAQ,EAARA,QAAD;AAAWI,IAAAA,MAAM,EAANA,MAAX;AAAmBE,IAAAA,YAAY,EAAZA,YAAAA;AAAnB,GAAP,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm3.js","sources":["../../src/core/createIntl.tsx"],"sourcesContent":["import createFormatter from './createFormatter';\n\n/** @deprecated Switch to `createFormatter` */\nexport default function createIntl(\n ...args: Parameters<typeof createFormatter>\n) {\n const formatter = createFormatter(...args);\n return {\n formatDateTime: formatter.dateTime,\n formatNumber: formatter.number,\n formatRelativeTime: formatter.relativeTime\n };\n}\n"],"names":["createIntl","formatter","createFormatter","apply","arguments","formatDateTime","dateTime","formatNumber","number","formatRelativeTime","relativeTime"],"mappings":";;AAEA;AACc,SAAUA,UAAUA,GACW;AAE3C,EAAA,IAAMC,SAAS,GAAGC,eAAe,CAAAC,KAAA,CAAA,KAAA,CAAA,EAAAC,SAAQ,CAAC,CAAA;EAC1C,OAAO;IACLC,cAAc,EAAEJ,SAAS,CAACK,QAAQ;IAClCC,YAAY,EAAEN,SAAS,CAACO,MAAM;IAC9BC,kBAAkB,EAAER,SAAS,CAACS,YAAAA;GAC/B,CAAA;AACH;;;;"}
@@ -1,7 +1,6 @@
1
1
  import createFormatter from './use-intl.esm3.js';
2
2
 
3
3
  /** @deprecated Switch to `createFormatter` */
4
-
5
4
  function createIntl() {
6
5
  var formatter = createFormatter.apply(void 0, arguments);
7
6
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm4.js","sources":["../../src/core/createIntl.tsx"],"sourcesContent":["import createFormatter from './createFormatter';\n\n/** @deprecated Switch to `createFormatter` */\nexport default function createIntl(\n ...args: Parameters<typeof createFormatter>\n) {\n const formatter = createFormatter(...args);\n return {\n formatDateTime: formatter.dateTime,\n formatNumber: formatter.number,\n formatRelativeTime: formatter.relativeTime\n };\n}\n"],"names":["createIntl","formatter","createFormatter","formatDateTime","dateTime","formatNumber","number","formatRelativeTime","relativeTime"],"mappings":";;AAEA;;AACc,SAAUA,UAAV,GAC+B;AAE3C,EAAA,IAAMC,SAAS,GAAGC,eAAe,CAAA,KAAf,CAAlB,KAAA,CAAA,EAAA,SAAA,CAAA,CAAA;AACA,EAAO,OAAA;AACLC,IAAAA,cAAc,EAAEF,SAAS,CAACG,QADrB;AAELC,IAAAA,YAAY,EAAEJ,SAAS,CAACK,MAFnB;AAGLC,IAAAA,kBAAkB,EAAEN,SAAS,CAACO,YAAAA;AAHzB,GAAP,CAAA;AAKD;;;;"}
1
+ {"version":3,"file":"use-intl.esm4.js","sources":["../../src/core/createTranslator.tsx"],"sourcesContent":["import Formats from './Formats';\nimport IntlConfig from './IntlConfig';\nimport TranslationValues from './TranslationValues';\nimport createTranslatorImpl, {\n CoreRichTranslationValues\n} from './createTranslatorImpl';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NamespaceKeys from './utils/NamespaceKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\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 createTranslator<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>({\n getMessageFallback = defaultGetMessageFallback,\n messages,\n namespace,\n onError = defaultOnError,\n ...rest\n}: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {\n messages: NonNullable<IntlConfig<IntlMessages>['messages']>;\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?: CoreRichTranslationValues,\n formats?: Partial<Formats>\n ): string;\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 // We have to wrap the actual function 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 createTranslatorImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {\n ...rest,\n onError,\n getMessageFallback,\n messages: {'!': messages},\n // @ts-ignore\n namespace: namespace ? `!.${namespace}` : '!'\n },\n '!'\n );\n}\n"],"names":["createTranslator","_ref","_ref$getMessageFallba","getMessageFallback","defaultGetMessageFallback","messages","namespace","_ref$onError","onError","defaultOnError","rest","_objectWithoutPropertiesLoose","_excluded","createTranslatorImpl","_extends"],"mappings":";;;;;AAYA;;;;;;;AAOG;AACqB,SAAAA,gBAAgBA,CAAAC,IAAA,EAcvC;AAAA,EAAA,IAAAC,qBAAA,GAAAD,IAAA,CARCE,kBAAkB;AAAlBA,IAAAA,kBAAkB,GAAAD,qBAAA,KAAGE,KAAAA,CAAAA,GAAAA,yBAAyB,GAAAF,qBAAA;IAC9CG,QAAQ,GAAAJ,IAAA,CAARI,QAAQ;IACRC,SAAS,GAAAL,IAAA,CAATK,SAAS;IAAAC,YAAA,GAAAN,IAAA,CACTO,OAAO;AAAPA,IAAAA,OAAO,GAAAD,YAAA,KAAGE,KAAAA,CAAAA,GAAAA,cAAc,GAAAF,YAAA;AACrBG,IAAAA,IAAI,GAAAC,6BAAA,CAAAV,IAAA,EAAAW,SAAA,CAAA,CAAA;AAgEP;AACA;AACA;AACA,EAAA,OAAOC,oBAAoB,CAAAC,QAAA,CAAA,EAAA,EAKpBJ,IAAI,EAAA;AACPF,IAAAA,OAAO,EAAPA,OAAO;AACPL,IAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBE,IAAAA,QAAQ,EAAE;AAAC,MAAA,GAAG,EAAEA,QAAAA;KAAS;AACzB;AACAC,IAAAA,SAAS,EAAEA,SAAS,GAAQA,IAAAA,GAAAA,SAAS,GAAK,GAAA;AAAG,GAAA,CAAA,EAE/C,GAAG,CACJ,CAAA;AACH;;;;"}