use-intl 2.17.0 → 2.17.2-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/AbstractIntlMessages.d.mts +10 -0
- package/dist/core/AbstractIntlMessages.d.ts +10 -9
- package/dist/core/AbstractIntlMessages.js +2 -0
- package/dist/core/AbstractIntlMessages.js.map +1 -0
- package/dist/core/AbstractIntlMessages.mjs +1 -0
- package/dist/core/AbstractIntlMessages.mjs.map +1 -0
- package/dist/core/DateTimeFormatOptions.d.mts +75 -0
- package/dist/core/DateTimeFormatOptions.d.ts +75 -73
- package/dist/core/DateTimeFormatOptions.js +2 -0
- package/dist/core/DateTimeFormatOptions.js.map +1 -0
- package/dist/core/DateTimeFormatOptions.mjs +1 -0
- package/dist/core/DateTimeFormatOptions.mjs.map +1 -0
- package/dist/core/Formats.d.mts +11 -0
- package/dist/core/Formats.d.ts +11 -8
- package/dist/core/Formats.js +2 -0
- package/dist/core/Formats.js.map +1 -0
- package/dist/core/Formats.mjs +1 -0
- package/dist/core/Formats.mjs.map +1 -0
- package/dist/core/IntlConfig.d.mts +60 -0
- package/dist/core/IntlConfig.d.ts +60 -54
- package/dist/core/IntlConfig.js +2 -0
- package/dist/core/IntlConfig.js.map +1 -0
- package/dist/core/IntlConfig.mjs +1 -0
- package/dist/core/IntlConfig.mjs.map +1 -0
- package/dist/core/IntlError.d.mts +15 -0
- package/dist/core/IntlError.d.ts +15 -13
- package/dist/core/IntlError.js +2 -0
- package/dist/core/IntlError.js.map +1 -0
- package/dist/core/IntlError.mjs +2 -0
- package/dist/core/IntlError.mjs.map +1 -0
- package/dist/core/NumberFormatOptions.d.mts +2 -0
- package/dist/core/NumberFormatOptions.d.ts +2 -2
- package/dist/core/NumberFormatOptions.js +2 -0
- package/dist/core/NumberFormatOptions.js.map +1 -0
- package/dist/core/NumberFormatOptions.mjs +2 -0
- package/dist/core/NumberFormatOptions.mjs.map +1 -0
- package/dist/core/TimeZone.d.mts +3 -0
- package/dist/core/TimeZone.d.ts +3 -2
- package/dist/core/TimeZone.js +2 -0
- package/dist/core/TimeZone.js.map +1 -0
- package/dist/core/TimeZone.mjs +1 -0
- package/dist/core/TimeZone.mjs.map +1 -0
- package/dist/core/TranslationValues.d.mts +7 -0
- package/dist/core/TranslationValues.d.ts +7 -5
- package/dist/core/TranslationValues.js +2 -0
- package/dist/core/TranslationValues.js.map +1 -0
- package/dist/core/TranslationValues.mjs +1 -0
- package/dist/core/TranslationValues.mjs.map +1 -0
- package/dist/core/convertFormatsToIntlMessageFormat.d.mts +16 -0
- package/dist/core/convertFormatsToIntlMessageFormat.d.ts +16 -11
- package/dist/core/convertFormatsToIntlMessageFormat.js +2 -0
- package/dist/core/convertFormatsToIntlMessageFormat.js.map +1 -0
- package/dist/core/convertFormatsToIntlMessageFormat.mjs +2 -0
- package/dist/core/convertFormatsToIntlMessageFormat.mjs.map +1 -0
- package/dist/core/createBaseTranslator.d.mts +32 -0
- package/dist/core/createBaseTranslator.d.ts +32 -26
- package/dist/core/createBaseTranslator.js +2 -0
- package/dist/core/createBaseTranslator.js.map +1 -0
- package/dist/core/createBaseTranslator.mjs +2 -0
- package/dist/core/createBaseTranslator.mjs.map +1 -0
- package/dist/core/createFormatter.d.mts +21 -0
- package/dist/core/createFormatter.d.ts +21 -19
- package/dist/core/createFormatter.js +2 -0
- package/dist/core/createFormatter.js.map +1 -0
- package/dist/core/createFormatter.mjs +2 -0
- package/dist/core/createFormatter.mjs.map +1 -0
- package/dist/core/createIntl.d.mts +15 -0
- package/dist/core/createIntl.d.ts +15 -7
- package/dist/core/createIntl.js +2 -0
- package/dist/core/createIntl.js.map +1 -0
- package/dist/core/createIntl.mjs +2 -0
- package/dist/core/createIntl.mjs.map +1 -0
- package/dist/core/createTranslator.d.mts +57 -0
- package/dist/core/createTranslator.d.ts +57 -48
- package/dist/core/createTranslator.js +2 -0
- package/dist/core/createTranslator.js.map +1 -0
- package/dist/core/createTranslator.mjs +2 -0
- package/dist/core/createTranslator.mjs.map +1 -0
- package/dist/core/createTranslatorImpl.d.mts +25 -0
- package/dist/core/createTranslatorImpl.d.ts +25 -14
- package/dist/core/createTranslatorImpl.js +2 -0
- package/dist/core/createTranslatorImpl.js.map +1 -0
- package/dist/core/createTranslatorImpl.mjs +2 -0
- package/dist/core/createTranslatorImpl.mjs.map +1 -0
- package/dist/core/defaults.d.mts +14 -0
- package/dist/core/defaults.d.ts +14 -11
- package/dist/core/defaults.js +2 -0
- package/dist/core/defaults.js.map +1 -0
- package/dist/core/defaults.mjs +2 -0
- package/dist/core/defaults.mjs.map +1 -0
- package/dist/core/index.d.mts +17 -0
- package/dist/core/index.d.ts +17 -9
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +2 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/core/resolveNamespace.d.mts +7 -0
- package/dist/core/resolveNamespace.d.ts +7 -5
- package/dist/core/resolveNamespace.js +2 -0
- package/dist/core/resolveNamespace.js.map +1 -0
- package/dist/core/resolveNamespace.mjs +2 -0
- package/dist/core/resolveNamespace.mjs.map +1 -0
- package/dist/core/utils/MessageKeys.d.mts +7 -0
- package/dist/core/utils/MessageKeys.d.ts +7 -5
- package/dist/core/utils/MessageKeys.js +2 -0
- package/dist/core/utils/MessageKeys.js.map +1 -0
- package/dist/core/utils/MessageKeys.mjs +1 -0
- package/dist/core/utils/MessageKeys.mjs.map +1 -0
- package/dist/core/utils/NamespaceKeys.d.mts +7 -0
- package/dist/core/utils/NamespaceKeys.d.ts +7 -5
- package/dist/core/utils/NamespaceKeys.js +2 -0
- package/dist/core/utils/NamespaceKeys.js.map +1 -0
- package/dist/core/utils/NamespaceKeys.mjs +1 -0
- package/dist/core/utils/NamespaceKeys.mjs.map +1 -0
- package/dist/core/utils/NestedKeyOf.d.mts +5 -0
- package/dist/core/utils/NestedKeyOf.d.ts +5 -4
- package/dist/core/utils/NestedKeyOf.js +2 -0
- package/dist/core/utils/NestedKeyOf.js.map +1 -0
- package/dist/core/utils/NestedKeyOf.mjs +1 -0
- package/dist/core/utils/NestedKeyOf.mjs.map +1 -0
- package/dist/core/utils/NestedValueOf.d.mts +3 -0
- package/dist/core/utils/NestedValueOf.d.ts +3 -2
- package/dist/core/utils/NestedValueOf.js +2 -0
- package/dist/core/utils/NestedValueOf.js.map +1 -0
- package/dist/core/utils/NestedValueOf.mjs +1 -0
- package/dist/core/utils/NestedValueOf.mjs.map +1 -0
- package/dist/core/validateMessages.d.mts +6 -0
- package/dist/core/validateMessages.d.ts +6 -3
- package/dist/core/validateMessages.js +34 -0
- package/dist/core/validateMessages.js.map +1 -0
- package/dist/core/validateMessages.mjs +34 -0
- package/dist/core/validateMessages.mjs.map +1 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.d.ts +25 -2
- package/dist/index.js +2 -8
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react/IntlContext.d.mts +13 -0
- package/dist/react/IntlContext.d.ts +13 -4
- package/dist/react/IntlContext.js +2 -0
- package/dist/react/IntlContext.js.map +1 -0
- package/dist/react/IntlContext.mjs +2 -0
- package/dist/react/IntlContext.mjs.map +1 -0
- package/dist/react/IntlProvider.d.mts +16 -0
- package/dist/react/IntlProvider.d.ts +16 -7
- package/dist/react/IntlProvider.js +2 -0
- package/dist/react/IntlProvider.js.map +1 -0
- package/dist/react/IntlProvider.mjs +2 -0
- package/dist/react/IntlProvider.mjs.map +1 -0
- package/dist/react/getInitializedConfig.d.mts +24 -0
- package/dist/react/getInitializedConfig.d.ts +24 -13
- package/dist/react/getInitializedConfig.js +2 -0
- package/dist/react/getInitializedConfig.js.map +1 -0
- package/dist/react/getInitializedConfig.mjs +2 -0
- package/dist/react/getInitializedConfig.mjs.map +1 -0
- package/dist/react/index.d.mts +21 -0
- package/dist/react/index.d.ts +21 -8
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +2 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/react/useFormatter.d.mts +12 -0
- package/dist/react/useFormatter.d.ts +12 -6
- package/dist/react/useFormatter.js +2 -0
- package/dist/react/useFormatter.js.map +1 -0
- package/dist/react/useFormatter.mjs +2 -0
- package/dist/react/useFormatter.mjs.map +1 -0
- package/dist/react/useIntl.d.mts +12 -0
- package/dist/react/useIntl.d.ts +12 -6
- package/dist/react/useIntl.js +2 -0
- package/dist/react/useIntl.js.map +1 -0
- package/dist/react/useIntl.mjs +2 -0
- package/dist/react/useIntl.mjs.map +1 -0
- package/dist/react/useIntlContext.d.mts +13 -0
- package/dist/react/useIntlContext.d.ts +13 -1
- package/dist/react/useIntlContext.js +2 -0
- package/dist/react/useIntlContext.js.map +1 -0
- package/dist/react/useIntlContext.mjs +2 -0
- package/dist/react/useIntlContext.mjs.map +1 -0
- package/dist/react/useLocale.d.mts +3 -0
- package/dist/react/useLocale.d.ts +3 -1
- package/dist/react/useLocale.js +2 -0
- package/dist/react/useLocale.js.map +1 -0
- package/dist/react/useLocale.mjs +2 -0
- package/dist/react/useLocale.mjs.map +1 -0
- package/dist/react/useMessages.d.mts +5 -0
- package/dist/react/useMessages.d.ts +5 -1
- package/dist/react/useMessages.js +2 -0
- package/dist/react/useMessages.js.map +1 -0
- package/dist/react/useMessages.mjs +2 -0
- package/dist/react/useMessages.mjs.map +1 -0
- package/dist/react/{use-intl.esm4.js → useNow.d.mts} +21 -42
- package/dist/react/useNow.d.ts +24 -23
- package/dist/react/useNow.js +2 -0
- package/dist/react/useNow.js.map +1 -0
- package/dist/react/useNow.mjs +2 -0
- package/dist/react/useNow.mjs.map +1 -0
- package/dist/react/useTimeZone.d.mts +5 -0
- package/dist/react/useTimeZone.d.ts +5 -1
- package/dist/react/useTimeZone.js +2 -0
- package/dist/react/useTimeZone.js.map +1 -0
- package/dist/react/useTimeZone.mjs +2 -0
- package/dist/react/useTimeZone.mjs.map +1 -0
- package/dist/react/useTranslations.d.mts +50 -0
- package/dist/react/useTranslations.d.ts +50 -44
- package/dist/react/useTranslations.js +2 -0
- package/dist/react/useTranslations.js.map +1 -0
- package/dist/react/useTranslations.mjs +2 -0
- package/dist/react/useTranslations.mjs.map +1 -0
- package/dist/react/useTranslationsImpl.d.mts +16 -0
- package/dist/react/useTranslationsImpl.d.ts +16 -8
- package/dist/react/useTranslationsImpl.js +2 -0
- package/dist/react/useTranslationsImpl.js.map +1 -0
- package/dist/react/useTranslationsImpl.mjs +2 -0
- package/dist/react/useTranslationsImpl.mjs.map +1 -0
- package/dist/src/core/AbstractIntlMessages.d.mts +10 -0
- package/dist/src/core/AbstractIntlMessages.d.ts +2 -1
- package/dist/src/core/AbstractIntlMessages.js +1 -1
- package/dist/src/core/AbstractIntlMessages.js.map +1 -1
- package/dist/src/core/AbstractIntlMessages.mjs +1 -0
- package/dist/src/core/AbstractIntlMessages.mjs.map +1 -0
- package/dist/src/core/DateTimeFormatOptions.d.mts +75 -0
- package/dist/src/core/DateTimeFormatOptions.d.ts +4 -2
- package/dist/src/core/DateTimeFormatOptions.js +1 -2
- package/dist/src/core/DateTimeFormatOptions.js.map +1 -1
- package/dist/src/core/DateTimeFormatOptions.mjs +1 -0
- package/dist/src/core/DateTimeFormatOptions.mjs.map +1 -0
- package/dist/src/core/Formats.d.mts +11 -0
- package/dist/src/core/Formats.d.ts +6 -3
- package/dist/src/core/Formats.js +1 -1
- package/dist/src/core/Formats.js.map +1 -1
- package/dist/src/core/Formats.mjs +1 -0
- package/dist/src/core/Formats.mjs.map +1 -0
- package/dist/src/core/IntlConfig.d.mts +60 -0
- package/dist/src/core/IntlConfig.d.ts +12 -6
- package/dist/src/core/IntlConfig.js +1 -1
- package/dist/src/core/IntlConfig.js.map +1 -1
- package/dist/src/core/IntlConfig.mjs +1 -0
- package/dist/src/core/IntlConfig.mjs.map +1 -0
- package/dist/src/core/IntlError.d.mts +15 -0
- package/dist/src/core/IntlError.d.ts +4 -2
- package/dist/src/core/IntlError.js +1 -22
- package/dist/src/core/IntlError.js.map +1 -1
- package/dist/src/core/IntlError.mjs +2 -0
- package/dist/src/core/IntlError.mjs.map +1 -0
- package/dist/src/core/NumberFormatOptions.d.mts +2 -0
- package/dist/src/core/NumberFormatOptions.d.ts +2 -2
- package/dist/src/core/NumberFormatOptions.js +1 -1
- package/dist/src/core/NumberFormatOptions.js.map +1 -1
- package/dist/src/core/NumberFormatOptions.mjs +2 -0
- package/dist/src/core/NumberFormatOptions.mjs.map +1 -0
- package/dist/src/core/TimeZone.d.mts +3 -0
- package/dist/src/core/TimeZone.d.ts +2 -1
- package/dist/src/core/TimeZone.js +1 -1
- package/dist/src/core/TimeZone.js.map +1 -1
- package/dist/src/core/TimeZone.mjs +1 -0
- package/dist/src/core/TimeZone.mjs.map +1 -0
- package/dist/src/core/TranslationValues.d.mts +7 -0
- package/dist/src/core/TranslationValues.d.ts +5 -3
- package/dist/src/core/TranslationValues.js +1 -1
- package/dist/src/core/TranslationValues.js.map +1 -1
- package/dist/src/core/TranslationValues.mjs +1 -0
- package/dist/src/core/TranslationValues.mjs.map +1 -0
- package/dist/src/core/convertFormatsToIntlMessageFormat.d.mts +16 -0
- package/dist/src/core/convertFormatsToIntlMessageFormat.d.ts +9 -4
- package/dist/src/core/convertFormatsToIntlMessageFormat.js +1 -30
- package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +1 -1
- package/dist/src/core/convertFormatsToIntlMessageFormat.mjs +2 -0
- package/dist/src/core/convertFormatsToIntlMessageFormat.mjs.map +1 -0
- package/dist/src/core/createBaseTranslator.d.mts +32 -0
- package/dist/src/core/createBaseTranslator.d.ts +17 -11
- package/dist/src/core/createBaseTranslator.js +1 -205
- package/dist/src/core/createBaseTranslator.js.map +1 -1
- package/dist/src/core/createBaseTranslator.mjs +2 -0
- package/dist/src/core/createBaseTranslator.mjs.map +1 -0
- package/dist/src/core/createFormatter.d.mts +21 -0
- package/dist/src/core/createFormatter.d.ts +9 -7
- package/dist/src/core/createFormatter.js +1 -128
- package/dist/src/core/createFormatter.js.map +1 -1
- package/dist/src/core/createFormatter.mjs +2 -0
- package/dist/src/core/createFormatter.mjs.map +1 -0
- package/dist/src/core/createIntl.d.mts +15 -0
- package/dist/src/core/createIntl.d.ts +12 -4
- package/dist/src/core/createIntl.js +1 -10
- package/dist/src/core/createIntl.js.map +1 -1
- package/dist/src/core/createIntl.mjs +2 -0
- package/dist/src/core/createIntl.mjs.map +1 -0
- package/dist/src/core/createTranslator.d.mts +57 -0
- package/dist/src/core/createTranslator.d.ts +18 -9
- package/dist/src/core/createTranslator.js +1 -23
- package/dist/src/core/createTranslator.js.map +1 -1
- package/dist/src/core/createTranslator.mjs +2 -0
- package/dist/src/core/createTranslator.mjs.map +1 -0
- package/dist/src/core/createTranslatorImpl.d.mts +25 -0
- package/dist/src/core/createTranslatorImpl.d.ts +20 -9
- package/dist/src/core/createTranslatorImpl.js +1 -42
- package/dist/src/core/createTranslatorImpl.js.map +1 -1
- package/dist/src/core/createTranslatorImpl.mjs +2 -0
- package/dist/src/core/createTranslatorImpl.mjs.map +1 -0
- package/dist/src/core/defaults.d.mts +14 -0
- package/dist/src/core/defaults.d.ts +6 -3
- package/dist/src/core/defaults.js +1 -10
- package/dist/src/core/defaults.js.map +1 -1
- package/dist/src/core/defaults.mjs +2 -0
- package/dist/src/core/defaults.mjs.map +1 -0
- package/dist/src/core/index.d.mts +17 -0
- package/dist/src/core/index.d.ts +17 -9
- package/dist/src/core/index.js +1 -5
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/index.mjs +2 -0
- package/dist/src/core/index.mjs.map +1 -0
- package/dist/src/core/resolveNamespace.d.mts +7 -0
- package/dist/src/core/resolveNamespace.d.ts +3 -1
- package/dist/src/core/resolveNamespace.js +1 -9
- package/dist/src/core/resolveNamespace.js.map +1 -1
- package/dist/src/core/resolveNamespace.mjs +2 -0
- package/dist/src/core/resolveNamespace.mjs.map +1 -0
- package/dist/src/core/utils/MessageKeys.d.mts +7 -0
- package/dist/src/core/utils/MessageKeys.d.ts +4 -2
- package/dist/src/core/utils/MessageKeys.js +1 -1
- package/dist/src/core/utils/MessageKeys.js.map +1 -1
- package/dist/src/core/utils/MessageKeys.mjs +1 -0
- package/dist/src/core/utils/MessageKeys.mjs.map +1 -0
- package/dist/src/core/utils/NamespaceKeys.d.mts +7 -0
- package/dist/src/core/utils/NamespaceKeys.d.ts +4 -2
- package/dist/src/core/utils/NamespaceKeys.js +1 -1
- package/dist/src/core/utils/NamespaceKeys.js.map +1 -1
- package/dist/src/core/utils/NamespaceKeys.mjs +1 -0
- package/dist/src/core/utils/NamespaceKeys.mjs.map +1 -0
- package/dist/src/core/utils/NestedKeyOf.d.mts +5 -0
- package/dist/src/core/utils/NestedKeyOf.d.ts +2 -1
- package/dist/src/core/utils/NestedKeyOf.js +1 -1
- package/dist/src/core/utils/NestedKeyOf.js.map +1 -1
- package/dist/src/core/utils/NestedKeyOf.mjs +1 -0
- package/dist/src/core/utils/NestedKeyOf.mjs.map +1 -0
- package/dist/src/core/utils/NestedValueOf.d.mts +3 -0
- package/dist/src/core/utils/NestedValueOf.d.ts +2 -1
- package/dist/src/core/utils/NestedValueOf.js +1 -1
- package/dist/src/core/utils/NestedValueOf.js.map +1 -1
- package/dist/src/core/utils/NestedValueOf.mjs +1 -0
- package/dist/src/core/utils/NestedValueOf.mjs.map +1 -0
- package/dist/src/core/validateMessages.d.mts +6 -0
- package/dist/src/core/validateMessages.d.ts +6 -3
- package/dist/src/core/validateMessages.js +3 -25
- package/dist/src/core/validateMessages.js.map +1 -1
- package/dist/src/core/validateMessages.mjs +34 -0
- package/dist/src/core/validateMessages.mjs.map +1 -0
- package/dist/src/index.d.mts +25 -0
- package/dist/src/index.d.ts +25 -2
- package/dist/src/index.js +1 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +2 -0
- package/dist/src/index.mjs.map +1 -0
- package/dist/src/react/IntlContext.d.mts +13 -0
- package/dist/src/react/IntlContext.d.ts +13 -4
- package/dist/src/react/IntlContext.js +1 -3
- package/dist/src/react/IntlContext.js.map +1 -1
- package/dist/src/react/IntlContext.mjs +2 -0
- package/dist/src/react/IntlContext.mjs.map +1 -0
- package/dist/src/react/IntlProvider.d.mts +16 -0
- package/dist/src/react/IntlProvider.d.ts +12 -3
- package/dist/src/react/IntlProvider.js +1 -6
- package/dist/src/react/IntlProvider.js.map +1 -1
- package/dist/src/react/IntlProvider.mjs +2 -0
- package/dist/src/react/IntlProvider.mjs.map +1 -0
- package/dist/src/react/getInitializedConfig.d.mts +24 -0
- package/dist/src/react/getInitializedConfig.d.ts +16 -5
- package/dist/src/react/getInitializedConfig.js +1 -20
- package/dist/src/react/getInitializedConfig.js.map +1 -1
- package/dist/src/react/getInitializedConfig.mjs +2 -0
- package/dist/src/react/getInitializedConfig.mjs.map +1 -0
- package/dist/src/react/index.d.mts +21 -0
- package/dist/src/react/index.d.ts +21 -8
- package/dist/src/react/index.js +1 -9
- package/dist/src/react/index.js.map +1 -1
- package/dist/src/react/index.mjs +2 -0
- package/dist/src/react/index.mjs.map +1 -0
- package/dist/src/react/useFormatter.d.mts +12 -0
- package/dist/src/react/useFormatter.d.ts +9 -3
- package/dist/src/react/useFormatter.js +1 -13
- package/dist/src/react/useFormatter.js.map +1 -1
- package/dist/src/react/useFormatter.mjs +2 -0
- package/dist/src/react/useFormatter.mjs.map +1 -0
- package/dist/src/react/useIntl.d.mts +12 -0
- package/dist/src/react/useIntl.d.ts +9 -3
- package/dist/src/react/useIntl.js +1 -19
- package/dist/src/react/useIntl.js.map +1 -1
- package/dist/src/react/useIntl.mjs +2 -0
- package/dist/src/react/useIntl.mjs.map +1 -0
- package/dist/src/react/useIntlContext.d.mts +13 -0
- package/dist/src/react/useIntlContext.d.ts +13 -1
- package/dist/src/react/useIntlContext.js +1 -11
- package/dist/src/react/useIntlContext.js.map +1 -1
- package/dist/src/react/useIntlContext.mjs +2 -0
- package/dist/src/react/useIntlContext.mjs.map +1 -0
- package/dist/src/react/useLocale.d.mts +3 -0
- package/dist/src/react/useLocale.d.ts +3 -1
- package/dist/src/react/useLocale.js +1 -4
- package/dist/src/react/useLocale.js.map +1 -1
- package/dist/src/react/useLocale.mjs +2 -0
- package/dist/src/react/useLocale.mjs.map +1 -0
- package/dist/src/react/useMessages.d.mts +5 -0
- package/dist/src/react/useMessages.d.ts +5 -1
- package/dist/src/react/useMessages.js +1 -4
- package/dist/src/react/useMessages.js.map +1 -1
- package/dist/src/react/useMessages.mjs +2 -0
- package/dist/src/react/useMessages.mjs.map +1 -0
- package/dist/src/react/useNow.d.mts +24 -0
- package/dist/src/react/useNow.d.ts +3 -2
- package/dist/src/react/useNow.js +1 -39
- package/dist/src/react/useNow.js.map +1 -1
- package/dist/src/react/useNow.mjs +2 -0
- package/dist/src/react/useNow.mjs.map +1 -0
- package/dist/src/react/useTimeZone.d.mts +5 -0
- package/dist/src/react/useTimeZone.d.ts +5 -1
- package/dist/src/react/useTimeZone.js +1 -4
- package/dist/src/react/useTimeZone.js.map +1 -1
- package/dist/src/react/useTimeZone.mjs +2 -0
- package/dist/src/react/useTimeZone.mjs.map +1 -0
- package/dist/src/react/useTranslations.d.mts +50 -0
- package/dist/src/react/useTranslations.d.ts +13 -7
- package/dist/src/react/useTranslations.js +1 -20
- package/dist/src/react/useTranslations.js.map +1 -1
- package/dist/src/react/useTranslations.mjs +2 -0
- package/dist/src/react/useTranslations.mjs.map +1 -0
- package/dist/src/react/useTranslationsImpl.d.mts +16 -0
- package/dist/src/react/useTranslationsImpl.d.ts +14 -6
- package/dist/src/react/useTranslationsImpl.js +1 -34
- package/dist/src/react/useTranslationsImpl.js.map +1 -1
- package/dist/src/react/useTranslationsImpl.mjs +2 -0
- package/dist/src/react/useTranslationsImpl.mjs.map +1 -0
- package/package.json +11 -21
- package/src/core/index.tsx +5 -5
- package/dist/_virtual/use-intl.esm.js +0 -102
- package/dist/_virtual/use-intl.esm.js.map +0 -1
- package/dist/core/IntlMessages.d.ts +0 -2
- package/dist/core/use-intl.esm.js +0 -33
- package/dist/core/use-intl.esm.js.map +0 -1
- package/dist/core/use-intl.esm10.js +0 -32
- package/dist/core/use-intl.esm10.js.map +0 -1
- package/dist/core/use-intl.esm2.js +0 -37
- package/dist/core/use-intl.esm2.js.map +0 -1
- package/dist/core/use-intl.esm3.js +0 -138
- package/dist/core/use-intl.esm3.js.map +0 -1
- package/dist/core/use-intl.esm4.js +0 -14
- package/dist/core/use-intl.esm4.js.map +0 -1
- package/dist/core/use-intl.esm5.js +0 -53
- package/dist/core/use-intl.esm5.js.map +0 -1
- package/dist/core/use-intl.esm6.js +0 -15
- package/dist/core/use-intl.esm6.js.map +0 -1
- package/dist/core/use-intl.esm7.js +0 -191
- package/dist/core/use-intl.esm7.js.map +0 -1
- package/dist/core/use-intl.esm8.js +0 -10
- package/dist/core/use-intl.esm8.js.map +0 -1
- package/dist/core/use-intl.esm9.js +0 -28
- package/dist/core/use-intl.esm9.js.map +0 -1
- package/dist/react/use-intl.esm.js +0 -16
- package/dist/react/use-intl.esm.js.map +0 -1
- package/dist/react/use-intl.esm10.js +0 -29
- package/dist/react/use-intl.esm10.js.map +0 -1
- package/dist/react/use-intl.esm11.js +0 -13
- package/dist/react/use-intl.esm11.js.map +0 -1
- package/dist/react/use-intl.esm12.js +0 -43
- package/dist/react/use-intl.esm12.js.map +0 -1
- package/dist/react/use-intl.esm2.js +0 -26
- package/dist/react/use-intl.esm2.js.map +0 -1
- package/dist/react/use-intl.esm3.js +0 -8
- package/dist/react/use-intl.esm3.js.map +0 -1
- package/dist/react/use-intl.esm4.js.map +0 -1
- package/dist/react/use-intl.esm5.js +0 -8
- package/dist/react/use-intl.esm5.js.map +0 -1
- package/dist/react/use-intl.esm6.js +0 -8
- package/dist/react/use-intl.esm6.js.map +0 -1
- package/dist/react/use-intl.esm7.js +0 -24
- package/dist/react/use-intl.esm7.js.map +0 -1
- package/dist/react/use-intl.esm8.js +0 -30
- package/dist/react/use-intl.esm8.js.map +0 -1
- package/dist/react/use-intl.esm9.js +0 -6
- package/dist/react/use-intl.esm9.js.map +0 -1
- package/dist/src/core/IntlMessages.d.ts +0 -2
- package/dist/src/core/IntlMessages.js +0 -4
- package/dist/src/core/IntlMessages.js.map +0 -1
- package/dist/use-intl.cjs.development.js +0 -821
- package/dist/use-intl.cjs.development.js.map +0 -1
- package/dist/use-intl.cjs.production.min.js +0 -2
- package/dist/use-intl.cjs.production.min.js.map +0 -1
- package/dist/use-intl.esm.js +0 -13
- package/dist/use-intl.esm.js.map +0 -1
- package/src/core/IntlMessages.tsx +0 -5
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import DateTimeFormatOptions from './DateTimeFormatOptions';
|
|
2
|
-
import Formats from './Formats';
|
|
3
|
-
import IntlError from './IntlError';
|
|
4
|
-
import NumberFormatOptions from '
|
|
5
|
-
import TimeZone from './TimeZone';
|
|
1
|
+
import DateTimeFormatOptions from './DateTimeFormatOptions.js';
|
|
2
|
+
import Formats from './Formats.js';
|
|
3
|
+
import IntlError from './IntlError.js';
|
|
4
|
+
import { NumberFormatOptions } from '@formatjs/ecma402-abstract/types/number';
|
|
5
|
+
import TimeZone from './TimeZone.js';
|
|
6
|
+
|
|
6
7
|
type Props = {
|
|
7
8
|
locale: string;
|
|
8
9
|
timeZone?: TimeZone;
|
|
@@ -10,10 +11,11 @@ type Props = {
|
|
|
10
11
|
formats?: Partial<Formats>;
|
|
11
12
|
now?: Date;
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
+
declare function createFormatter({ formats, locale, now: globalNow, onError, timeZone }: Props): {
|
|
14
15
|
dateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions) => string;
|
|
15
16
|
number: (value: number | bigint, formatOrOptions?: string | NumberFormatOptions) => string;
|
|
16
17
|
relativeTime: (date: number | Date, now?: number | Date) => string;
|
|
17
18
|
list: (value: Iterable<string>, formatOrOptions?: string | Intl.ListFormatOptions) => string;
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
export { createFormatter as default };
|
|
@@ -1,129 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { defaultOnError } from './defaults';
|
|
3
|
-
const MINUTE = 60;
|
|
4
|
-
const HOUR = MINUTE * 60;
|
|
5
|
-
const DAY = HOUR * 24;
|
|
6
|
-
const WEEK = DAY * 7;
|
|
7
|
-
const MONTH = DAY * (365 / 12); // Approximation
|
|
8
|
-
const YEAR = DAY * 365;
|
|
9
|
-
function getRelativeTimeFormatConfig(seconds) {
|
|
10
|
-
const absValue = Math.abs(seconds);
|
|
11
|
-
let value, unit;
|
|
12
|
-
// We have to round the resulting values, as `Intl.RelativeTimeFormat`
|
|
13
|
-
// will include fractions like '2.1 hours ago'.
|
|
14
|
-
if (absValue < MINUTE) {
|
|
15
|
-
unit = 'second';
|
|
16
|
-
value = Math.round(seconds);
|
|
17
|
-
}
|
|
18
|
-
else if (absValue < HOUR) {
|
|
19
|
-
unit = 'minute';
|
|
20
|
-
value = Math.round(seconds / MINUTE);
|
|
21
|
-
}
|
|
22
|
-
else if (absValue < DAY) {
|
|
23
|
-
unit = 'hour';
|
|
24
|
-
value = Math.round(seconds / HOUR);
|
|
25
|
-
}
|
|
26
|
-
else if (absValue < WEEK) {
|
|
27
|
-
unit = 'day';
|
|
28
|
-
value = Math.round(seconds / DAY);
|
|
29
|
-
}
|
|
30
|
-
else if (absValue < MONTH) {
|
|
31
|
-
unit = 'week';
|
|
32
|
-
value = Math.round(seconds / WEEK);
|
|
33
|
-
}
|
|
34
|
-
else if (absValue < YEAR) {
|
|
35
|
-
unit = 'month';
|
|
36
|
-
value = Math.round(seconds / MONTH);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
unit = 'year';
|
|
40
|
-
value = Math.round(seconds / YEAR);
|
|
41
|
-
}
|
|
42
|
-
return { value, unit };
|
|
43
|
-
}
|
|
44
|
-
export default function createFormatter({ formats, locale, now: globalNow, onError = defaultOnError, timeZone }) {
|
|
45
|
-
function resolveFormatOrOptions(typeFormats, formatOrOptions) {
|
|
46
|
-
let options;
|
|
47
|
-
if (typeof formatOrOptions === 'string') {
|
|
48
|
-
const formatName = formatOrOptions;
|
|
49
|
-
options = typeFormats?.[formatName];
|
|
50
|
-
if (!options) {
|
|
51
|
-
const error = new IntlError(IntlErrorCode.MISSING_FORMAT, process.env.NODE_ENV !== 'production'
|
|
52
|
-
? `Format \`${formatName}\` is not available. You can configure it on the provider or provide custom options.`
|
|
53
|
-
: undefined);
|
|
54
|
-
onError(error);
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
options = formatOrOptions;
|
|
60
|
-
}
|
|
61
|
-
return options;
|
|
62
|
-
}
|
|
63
|
-
function getFormattedValue(value, formatOrOptions, typeFormats, formatter) {
|
|
64
|
-
let options;
|
|
65
|
-
try {
|
|
66
|
-
options = resolveFormatOrOptions(typeFormats, formatOrOptions);
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
return String(value);
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
return formatter(options);
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
|
|
76
|
-
return String(value);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function dateTime(
|
|
80
|
-
/** If a number is supplied, this is interpreted as a UTC timestamp. */
|
|
81
|
-
value,
|
|
82
|
-
/** If a time zone is supplied, the `value` is converted to that time zone.
|
|
83
|
-
* Otherwise the user time zone will be used. */
|
|
84
|
-
formatOrOptions) {
|
|
85
|
-
return getFormattedValue(value, formatOrOptions, formats?.dateTime, (options) => {
|
|
86
|
-
if (timeZone && !options?.timeZone) {
|
|
87
|
-
options = { ...options, timeZone };
|
|
88
|
-
}
|
|
89
|
-
return new Intl.DateTimeFormat(locale, options).format(value);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
function number(value, formatOrOptions) {
|
|
93
|
-
return getFormattedValue(value, formatOrOptions, formats?.number, (options) => new Intl.NumberFormat(locale, options).format(value));
|
|
94
|
-
}
|
|
95
|
-
function relativeTime(
|
|
96
|
-
/** The date time that needs to be formatted. */
|
|
97
|
-
date,
|
|
98
|
-
/** The reference point in time to which `date` will be formatted in relation to. */
|
|
99
|
-
now) {
|
|
100
|
-
try {
|
|
101
|
-
if (!now) {
|
|
102
|
-
if (globalNow) {
|
|
103
|
-
now = globalNow;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
throw new Error(process.env.NODE_ENV !== 'production'
|
|
107
|
-
? `The \`now\` parameter wasn't provided and there was no global fallback configured on the provider.`
|
|
108
|
-
: undefined);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const dateDate = date instanceof Date ? date : new Date(date);
|
|
112
|
-
const nowDate = now instanceof Date ? now : new Date(now);
|
|
113
|
-
const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
|
|
114
|
-
const { unit, value } = getRelativeTimeFormatConfig(seconds);
|
|
115
|
-
return new Intl.RelativeTimeFormat(locale, {
|
|
116
|
-
numeric: 'auto'
|
|
117
|
-
}).format(value, unit);
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
|
|
121
|
-
return String(date);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function list(value, formatOrOptions) {
|
|
125
|
-
return getFormattedValue(value, formatOrOptions, formats?.list, (options) => new Intl.ListFormat(locale, options).format(value));
|
|
126
|
-
}
|
|
127
|
-
return { dateTime, number, relativeTime, list };
|
|
128
|
-
}
|
|
1
|
+
"use strict";var y=Object.create;var p=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var G=(t,r)=>{for(var e in r)p(t,e,{get:r[e],enumerable:!0})},F=(t,r,e,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let m of A(r))!_.call(t,m)&&m!==e&&p(t,m,{get:()=>r[m],enumerable:!(a=V(r,m))||a.enumerable});return t};var P=(t,r,e)=>(e=t!=null?y(S(t)):{},F(r||!t||!t.__esModule?p(e,"default",{value:t,enumerable:!0}):e,t)),U=t=>F(p({},"__esModule",{value:!0}),t);var Z={};G(Z,{default:()=>E});module.exports=U(Z);var s=P(require("./IntlError")),D=require("./defaults");const g=60,T=g*60,c=T*24,O=c*7,h=c*(365/12),b=c*365;function Y(t){const r=Math.abs(t);let e,a;return r<g?(a="second",e=Math.round(t)):r<T?(a="minute",e=Math.round(t/g)):r<c?(a="hour",e=Math.round(t/T)):r<O?(a="day",e=Math.round(t/c)):r<h?(a="week",e=Math.round(t/O)):r<b?(a="month",e=Math.round(t/h)):(a="year",e=Math.round(t/b)),{value:e,unit:a}}function E({formats:t,locale:r,now:e,onError:a=D.defaultOnError,timeZone:m}){function R(o,i){let n;if(typeof i=="string"){const f=i;if(n=o?.[f],!n){const u=new s.default(s.IntlErrorCode.MISSING_FORMAT,process.env.NODE_ENV!=="production"?`Format \`${f}\` is not available. You can configure it on the provider or provide custom options.`:void 0);throw (a(u), u)}}else n=i;return n}function d(o,i,n,f){let u;try{u=R(n,i)}catch{return String(o)}try{return f(u)}catch(l){return a(new s.default(s.IntlErrorCode.FORMATTING_ERROR,l.message)),String(o)}}function I(o,i){return d(o,i,t?.dateTime,n=>(m&&!n?.timeZone&&(n={...n,timeZone:m}),new Intl.DateTimeFormat(r,n).format(o)))}function w(o,i){return d(o,i,t?.number,n=>new Intl.NumberFormat(r,n).format(o))}function M(o,i){try{if(!i)if(e)i=e;else throw new Error(process.env.NODE_ENV!=="production"?"The `now` parameter wasn't provided and there was no global fallback configured on the provider.":void 0);const n=o instanceof Date?o:new Date(o),f=i instanceof Date?i:new Date(i),u=(n.getTime()-f.getTime())/1e3,{unit:l,value:v}=Y(u);return new Intl.RelativeTimeFormat(r,{numeric:"auto"}).format(v,l)}catch(n){return a(new s.default(s.IntlErrorCode.FORMATTING_ERROR,n.message)),String(o)}}function N(o,i){return d(o,i,t?.list,n=>new Intl.ListFormat(r,n).format(o))}return{dateTime:I,number:w,relativeTime:M,list:N}}
|
|
129
2
|
//# sourceMappingURL=createFormatter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../src/core/createFormatter.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport TimeZone from './TimeZone';\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?: TimeZone;\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 function list(\n value: Iterable<string>,\n formatOrOptions?: string | Intl.ListFormatOptions\n ) {\n return getFormattedValue(value, formatOrOptions, formats?.list, (options) =>\n new Intl.ListFormat(locale, options).format(value)\n );\n }\n\n return {dateTime, number, relativeTime, list};\n}\n"],"mappings":"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","names":["createFormatter_exports","__export","createFormatter","__toCommonJS","import_IntlError","import_defaults","MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","value","unit","formats","locale","globalNow","onError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","getFormattedValue","formatter","dateTime","number","relativeTime","date","now","dateDate","nowDate","list"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import l,{IntlErrorCode as p}from"./IntlError.mjs";import{defaultOnError as M}from"./defaults.mjs";const d=60,g=d*60,u=g*24,F=u*7,O=u*(365/12),h=u*365;function N(n){const i=Math.abs(n);let a,o;return i<d?(o="second",a=Math.round(n)):i<g?(o="minute",a=Math.round(n/d)):i<u?(o="hour",a=Math.round(n/g)):i<F?(o="day",a=Math.round(n/u)):i<O?(o="week",a=Math.round(n/F)):i<h?(o="month",a=Math.round(n/O)):(o="year",a=Math.round(n/h)),{value:a,unit:o}}function v({formats:n,locale:i,now:a,onError:o=M,timeZone:T}){function b(r,e){let t;if(typeof e=="string"){const s=e;if(t=r?.[s],!t){const m=new l(p.MISSING_FORMAT,process.env.NODE_ENV!=="production"?`Format \`${s}\` is not available. You can configure it on the provider or provide custom options.`:void 0);throw (o(m), m)}}else t=e;return t}function c(r,e,t,s){let m;try{m=b(t,e)}catch{return String(r)}try{return s(m)}catch(f){return o(new l(p.FORMATTING_ERROR,f.message)),String(r)}}function D(r,e){return c(r,e,n?.dateTime,t=>(T&&!t?.timeZone&&(t={...t,timeZone:T}),new Intl.DateTimeFormat(i,t).format(r)))}function E(r,e){return c(r,e,n?.number,t=>new Intl.NumberFormat(i,t).format(r))}function R(r,e){try{if(!e)if(a)e=a;else throw new Error(process.env.NODE_ENV!=="production"?"The `now` parameter wasn't provided and there was no global fallback configured on the provider.":void 0);const t=r instanceof Date?r:new Date(r),s=e instanceof Date?e:new Date(e),m=(t.getTime()-s.getTime())/1e3,{unit:f,value:w}=N(m);return new Intl.RelativeTimeFormat(i,{numeric:"auto"}).format(w,f)}catch(t){return o(new l(p.FORMATTING_ERROR,t.message)),String(r)}}function I(r,e){return c(r,e,n?.list,t=>new Intl.ListFormat(i,t).format(r))}return{dateTime:D,number:E,relativeTime:R,list:I}}export{v as default};
|
|
2
|
+
//# sourceMappingURL=createFormatter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/createFormatter.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport TimeZone from './TimeZone';\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?: TimeZone;\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 function list(\n value: Iterable<string>,\n formatOrOptions?: string | Intl.ListFormatOptions\n ) {\n return getFormattedValue(value, formatOrOptions, formats?.list, (options) =>\n new Intl.ListFormat(locale, options).format(value)\n );\n }\n\n return {dateTime, number, relativeTime, list};\n}\n"],"mappings":"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","names":["IntlError","IntlErrorCode","defaultOnError","MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","value","unit","createFormatter","formats","locale","globalNow","onError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","getFormattedValue","formatter","dateTime","number","relativeTime","date","now","dateDate","nowDate","list"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as _formatjs_ecma402_abstract_types_number from '@formatjs/ecma402-abstract/types/number';
|
|
2
|
+
import DateTimeFormatOptions from './DateTimeFormatOptions.mjs';
|
|
3
|
+
import createFormatter from './createFormatter.mjs';
|
|
4
|
+
import './TimeZone.mjs';
|
|
5
|
+
import './Formats.mjs';
|
|
6
|
+
import './IntlError.mjs';
|
|
7
|
+
|
|
8
|
+
/** @deprecated Switch to `createFormatter` */
|
|
9
|
+
declare function createIntl(...args: Parameters<typeof createFormatter>): {
|
|
10
|
+
formatDateTime: (value: number | Date, formatOrOptions?: string | DateTimeFormatOptions | undefined) => string;
|
|
11
|
+
formatNumber: (value: number | bigint, formatOrOptions?: string | _formatjs_ecma402_abstract_types_number.NumberFormatOptions | undefined) => string;
|
|
12
|
+
formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { createIntl as default };
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _formatjs_ecma402_abstract_types_number from '@formatjs/ecma402-abstract/types/number';
|
|
2
|
+
import DateTimeFormatOptions from './DateTimeFormatOptions.js';
|
|
3
|
+
import createFormatter from './createFormatter.js';
|
|
4
|
+
import './TimeZone.js';
|
|
5
|
+
import './Formats.js';
|
|
6
|
+
import './IntlError.js';
|
|
7
|
+
|
|
2
8
|
/** @deprecated Switch to `createFormatter` */
|
|
3
|
-
|
|
4
|
-
formatDateTime: (value: number | Date, formatOrOptions?: string |
|
|
5
|
-
formatNumber: (value: number | bigint, formatOrOptions?: string |
|
|
9
|
+
declare function createIntl(...args: Parameters<typeof createFormatter>): {
|
|
10
|
+
formatDateTime: (value: number | Date, formatOrOptions?: string | DateTimeFormatOptions | undefined) => string;
|
|
11
|
+
formatNumber: (value: number | bigint, formatOrOptions?: string | _formatjs_ecma402_abstract_types_number.NumberFormatOptions | undefined) => string;
|
|
6
12
|
formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
7
13
|
};
|
|
14
|
+
|
|
15
|
+
export { createIntl as default };
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/** @deprecated Switch to `createFormatter` */
|
|
3
|
-
export default function createIntl(...args) {
|
|
4
|
-
const formatter = createFormatter(...args);
|
|
5
|
-
return {
|
|
6
|
-
formatDateTime: formatter.dateTime,
|
|
7
|
-
formatNumber: formatter.number,
|
|
8
|
-
formatRelativeTime: formatter.relativeTime
|
|
9
|
-
};
|
|
10
|
-
}
|
|
1
|
+
"use strict";var c=Object.create;var m=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var b=(e,t)=>{for(var r in t)m(e,r,{get:t[r],enumerable:!0})},f=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of l(t))!p.call(e,a)&&a!==r&&m(e,a,{get:()=>t[a],enumerable:!(o=u(t,a))||o.enumerable});return e};var d=(e,t,r)=>(r=e!=null?c(T(e)):{},f(t||!e||!e.__esModule?m(r,"default",{value:e,enumerable:!0}):r,e)),s=e=>f(m({},"__esModule",{value:!0}),e);var v={};b(v,{default:()=>n});module.exports=s(v);var i=d(require("./createFormatter"));function n(...e){const t=(0,i.default)(...e);return{formatDateTime:t.dateTime,formatNumber:t.number,formatRelativeTime:t.relativeTime}}
|
|
11
2
|
//# sourceMappingURL=createIntl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"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"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA4B,gCAGb,SAARF,KACFG,EACH,CACA,MAAMC,KAAY,EAAAC,SAAgB,GAAGF,CAAI,EACzC,MAAO,CACL,eAAgBC,EAAU,SAC1B,aAAcA,EAAU,OACxB,mBAAoBA,EAAU,YAChC,CACF","names":["createIntl_exports","__export","createIntl","__toCommonJS","import_createFormatter","args","formatter","createFormatter"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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"],"mappings":"AAAA,OAAOA,MAAqB,oBAGb,SAARC,KACFC,EACH,CACA,MAAMC,EAAYH,EAAgB,GAAGE,CAAI,EACzC,MAAO,CACL,eAAgBC,EAAU,SAC1B,aAAcA,EAAU,OACxB,mBAAoBA,EAAU,YAChC,CACF","names":["createFormatter","createIntl","args","formatter"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Formats from './Formats.mjs';
|
|
2
|
+
import IntlConfig from './IntlConfig.mjs';
|
|
3
|
+
import TranslationValues from './TranslationValues.mjs';
|
|
4
|
+
import { CoreRichTranslationValues } from './createTranslatorImpl.mjs';
|
|
5
|
+
import MessageKeys from './utils/MessageKeys.mjs';
|
|
6
|
+
import NamespaceKeys from './utils/NamespaceKeys.mjs';
|
|
7
|
+
import NestedKeyOf from './utils/NestedKeyOf.mjs';
|
|
8
|
+
import NestedValueOf from './utils/NestedValueOf.mjs';
|
|
9
|
+
import './DateTimeFormatOptions.mjs';
|
|
10
|
+
import './TimeZone.mjs';
|
|
11
|
+
import '@formatjs/ecma402-abstract/types/number';
|
|
12
|
+
import './IntlError.mjs';
|
|
13
|
+
import './AbstractIntlMessages.mjs';
|
|
14
|
+
import 'react';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Translates messages from the given namespace by using the ICU syntax.
|
|
18
|
+
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
19
|
+
*
|
|
20
|
+
* If no namespace is provided, all available messages are returned.
|
|
21
|
+
* The namespace can also indicate nesting by using a dot
|
|
22
|
+
* (e.g. `namespace.Component`).
|
|
23
|
+
*/
|
|
24
|
+
declare function createTranslator<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>({ getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {
|
|
25
|
+
messages: NonNullable<IntlConfig<IntlMessages>['messages']>;
|
|
26
|
+
namespace?: NestedKey;
|
|
27
|
+
}): {
|
|
28
|
+
<TargetKey extends MessageKeys<NestedValueOf<{
|
|
29
|
+
'!': IntlMessages;
|
|
30
|
+
}, [
|
|
31
|
+
NestedKey
|
|
32
|
+
] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
|
|
33
|
+
'!': IntlMessages;
|
|
34
|
+
}, [
|
|
35
|
+
NestedKey
|
|
36
|
+
] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
|
|
37
|
+
rich<TargetKey extends MessageKeys<NestedValueOf<{
|
|
38
|
+
'!': IntlMessages;
|
|
39
|
+
}, [
|
|
40
|
+
NestedKey
|
|
41
|
+
] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
|
|
42
|
+
'!': IntlMessages;
|
|
43
|
+
}, [
|
|
44
|
+
NestedKey
|
|
45
|
+
] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: CoreRichTranslationValues, formats?: Partial<Formats>): string;
|
|
46
|
+
raw<TargetKey extends MessageKeys<NestedValueOf<{
|
|
47
|
+
'!': IntlMessages;
|
|
48
|
+
}, [
|
|
49
|
+
NestedKey
|
|
50
|
+
] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
|
|
51
|
+
'!': IntlMessages;
|
|
52
|
+
}, [
|
|
53
|
+
NestedKey
|
|
54
|
+
] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export { createTranslator as default };
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import Formats from './Formats';
|
|
2
|
-
import IntlConfig from './IntlConfig';
|
|
3
|
-
import TranslationValues from './TranslationValues';
|
|
4
|
-
import { CoreRichTranslationValues } from './createTranslatorImpl';
|
|
5
|
-
import MessageKeys from './utils/MessageKeys';
|
|
6
|
-
import NamespaceKeys from './utils/NamespaceKeys';
|
|
7
|
-
import NestedKeyOf from './utils/NestedKeyOf';
|
|
8
|
-
import NestedValueOf from './utils/NestedValueOf';
|
|
1
|
+
import Formats from './Formats.js';
|
|
2
|
+
import IntlConfig from './IntlConfig.js';
|
|
3
|
+
import TranslationValues from './TranslationValues.js';
|
|
4
|
+
import { CoreRichTranslationValues } from './createTranslatorImpl.js';
|
|
5
|
+
import MessageKeys from './utils/MessageKeys.js';
|
|
6
|
+
import NamespaceKeys from './utils/NamespaceKeys.js';
|
|
7
|
+
import NestedKeyOf from './utils/NestedKeyOf.js';
|
|
8
|
+
import NestedValueOf from './utils/NestedValueOf.js';
|
|
9
|
+
import './DateTimeFormatOptions.js';
|
|
10
|
+
import './TimeZone.js';
|
|
11
|
+
import '@formatjs/ecma402-abstract/types/number';
|
|
12
|
+
import './IntlError.js';
|
|
13
|
+
import './AbstractIntlMessages.js';
|
|
14
|
+
import 'react';
|
|
15
|
+
|
|
9
16
|
/**
|
|
10
17
|
* Translates messages from the given namespace by using the ICU syntax.
|
|
11
18
|
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
@@ -14,7 +21,7 @@ import NestedValueOf from './utils/NestedValueOf';
|
|
|
14
21
|
* The namespace can also indicate nesting by using a dot
|
|
15
22
|
* (e.g. `namespace.Component`).
|
|
16
23
|
*/
|
|
17
|
-
|
|
24
|
+
declare function createTranslator<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>({ getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {
|
|
18
25
|
messages: NonNullable<IntlConfig<IntlMessages>['messages']>;
|
|
19
26
|
namespace?: NestedKey;
|
|
20
27
|
}): {
|
|
@@ -46,3 +53,5 @@ export default function createTranslator<NestedKey extends NamespaceKeys<IntlMes
|
|
|
46
53
|
NestedKey
|
|
47
54
|
] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
|
|
48
55
|
};
|
|
56
|
+
|
|
57
|
+
export { createTranslator as default };
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { defaultGetMessageFallback, defaultOnError } from './defaults';
|
|
3
|
-
/**
|
|
4
|
-
* Translates messages from the given namespace by using the ICU syntax.
|
|
5
|
-
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
6
|
-
*
|
|
7
|
-
* If no namespace is provided, all available messages are returned.
|
|
8
|
-
* The namespace can also indicate nesting by using a dot
|
|
9
|
-
* (e.g. `namespace.Component`).
|
|
10
|
-
*/
|
|
11
|
-
export default function createTranslator({ getMessageFallback = defaultGetMessageFallback, messages, namespace, onError = defaultOnError, ...rest }) {
|
|
12
|
-
// We have to wrap the actual function so the type inference for the optional
|
|
13
|
-
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
14
|
-
// The prefix ("!") is arbitrary.
|
|
15
|
-
return createTranslatorImpl({
|
|
16
|
-
...rest,
|
|
17
|
-
onError,
|
|
18
|
-
getMessageFallback,
|
|
19
|
-
messages: { '!': messages },
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
namespace: namespace ? `!.${namespace}` : '!'
|
|
22
|
-
}, '!');
|
|
23
|
-
}
|
|
1
|
+
"use strict";var K=Object.create;var n=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var i=(e,s)=>{for(var t in s)n(e,t,{get:s[t],enumerable:!0})},d=(e,s,t,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let a of N(s))!g.call(e,a)&&a!==t&&n(e,a,{get:()=>s[a],enumerable:!(r=m(s,a))||r.enumerable});return e};var u=(e,s,t)=>(t=e!=null?K(f(e)):{},d(s||!e||!e.__esModule?n(t,"default",{value:e,enumerable:!0}):t,e)),M=e=>d(n({},"__esModule",{value:!0}),e);var I={};i(I,{default:()=>y});module.exports=M(I);var o=u(require("./createTranslatorImpl")),l=require("./defaults");function y({getMessageFallback:e=l.defaultGetMessageFallback,messages:s,namespace:t,onError:r=l.defaultOnError,...a}){return(0,o.default)({...a,onError:r,getMessageFallback:e,messages:{"!":s},namespace:t?`!.${t}`:"!"},"!")}
|
|
24
2
|
//# sourceMappingURL=createTranslator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"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"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAGA,IAAAI,EAEO,qCACPC,EAAwD,sBAczC,SAARH,EAKL,CACA,mBAAAI,EAAqB,4BACrB,SAAAC,EACA,UAAAC,EACA,QAAAC,EAAU,iBACV,GAAGC,CACL,EA8DE,CAIA,SAAO,EAAAC,SAIL,CACE,GAAGD,EACH,QAAAD,EACA,mBAAAH,EACA,SAAU,CAAC,IAAKC,CAAQ,EAExB,UAAWC,EAAY,KAAKA,CAAS,GAAK,GAC5C,EACA,GACF,CACF","names":["createTranslator_exports","__export","createTranslator","__toCommonJS","import_createTranslatorImpl","import_defaults","getMessageFallback","messages","namespace","onError","rest","createTranslatorImpl"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import n from"./createTranslatorImpl.mjs";import{defaultGetMessageFallback as l,defaultOnError as d}from"./defaults.mjs";function o({getMessageFallback:s=l,messages:t,namespace:e,onError:a=d,...r}){return n({...r,onError:a,getMessageFallback:s,messages:{"!":t},namespace:e?`!.${e}`:"!"},"!")}export{o as default};
|
|
2
|
+
//# sourceMappingURL=createTranslator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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"],"mappings":"AAGA,OAAOA,MAEA,yBACP,OAAQ,6BAAAC,EAA2B,kBAAAC,MAAqB,aAczC,SAARC,EAKL,CACA,mBAAAC,EAAqBH,EACrB,SAAAI,EACA,UAAAC,EACA,QAAAC,EAAUL,EACV,GAAGM,CACL,EA8DE,CAIA,OAAOR,EAIL,CACE,GAAGQ,EACH,QAAAD,EACA,mBAAAH,EACA,SAAU,CAAC,IAAKC,CAAQ,EAExB,UAAWC,EAAY,KAAKA,CAAS,GAAK,GAC5C,EACA,GACF,CACF","names":["createTranslatorImpl","defaultGetMessageFallback","defaultOnError","createTranslator","getMessageFallback","messages","namespace","onError","rest"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Formats from './Formats.mjs';
|
|
2
|
+
import TranslationValues, { TranslationValue } from './TranslationValues.mjs';
|
|
3
|
+
import MessageKeys from './utils/MessageKeys.mjs';
|
|
4
|
+
import NestedValueOf from './utils/NestedValueOf.mjs';
|
|
5
|
+
import AbstractIntlMessages from './AbstractIntlMessages.mjs';
|
|
6
|
+
import { InitializedIntlConfig } from './IntlConfig.mjs';
|
|
7
|
+
import NestedKeyOf from './utils/NestedKeyOf.mjs';
|
|
8
|
+
import './DateTimeFormatOptions.mjs';
|
|
9
|
+
import './TimeZone.mjs';
|
|
10
|
+
import '@formatjs/ecma402-abstract/types/number';
|
|
11
|
+
import 'react';
|
|
12
|
+
import './IntlError.mjs';
|
|
13
|
+
|
|
14
|
+
type CoreRichTranslationValues = Record<string, TranslationValue | ((chunks: string) => string)>;
|
|
15
|
+
type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
|
|
16
|
+
namespace: string;
|
|
17
|
+
messages: Messages;
|
|
18
|
+
};
|
|
19
|
+
declare function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ getMessageFallback, messages, namespace, onError, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: string): {
|
|
20
|
+
(key: MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>, values?: TranslationValues | undefined, formats?: Partial<Formats> | undefined): string;
|
|
21
|
+
rich(key: string, values: CoreRichTranslationValues, formats?: Partial<Formats> | undefined): string;
|
|
22
|
+
raw: (key: string) => any;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { CoreRichTranslationValues, CreateTranslatorImplProps, createTranslatorImpl as default };
|
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import Formats from './Formats.js';
|
|
2
|
+
import TranslationValues, { TranslationValue } from './TranslationValues.js';
|
|
3
|
+
import MessageKeys from './utils/MessageKeys.js';
|
|
4
|
+
import NestedValueOf from './utils/NestedValueOf.js';
|
|
5
|
+
import AbstractIntlMessages from './AbstractIntlMessages.js';
|
|
6
|
+
import { InitializedIntlConfig } from './IntlConfig.js';
|
|
7
|
+
import NestedKeyOf from './utils/NestedKeyOf.js';
|
|
8
|
+
import './DateTimeFormatOptions.js';
|
|
9
|
+
import './TimeZone.js';
|
|
10
|
+
import '@formatjs/ecma402-abstract/types/number';
|
|
11
|
+
import 'react';
|
|
12
|
+
import './IntlError.js';
|
|
13
|
+
|
|
14
|
+
type CoreRichTranslationValues = Record<string, TranslationValue | ((chunks: string) => string)>;
|
|
15
|
+
type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
|
|
7
16
|
namespace: string;
|
|
8
17
|
messages: Messages;
|
|
9
18
|
};
|
|
10
|
-
|
|
11
|
-
(key:
|
|
12
|
-
rich(key: string, values: CoreRichTranslationValues, formats?: Partial<
|
|
19
|
+
declare function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ getMessageFallback, messages, namespace, onError, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: string): {
|
|
20
|
+
(key: MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>, values?: TranslationValues | undefined, formats?: Partial<Formats> | undefined): string;
|
|
21
|
+
rich(key: string, values: CoreRichTranslationValues, formats?: Partial<Formats> | undefined): string;
|
|
13
22
|
raw: (key: string) => any;
|
|
14
23
|
};
|
|
24
|
+
|
|
25
|
+
export { CoreRichTranslationValues, CreateTranslatorImplProps, createTranslatorImpl as default };
|
|
@@ -1,43 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import createBaseTranslator, { getMessagesOrError } from './createBaseTranslator';
|
|
3
|
-
import resolveNamespace from './resolveNamespace';
|
|
4
|
-
export default function createTranslatorImpl({ getMessageFallback, messages, namespace, onError, ...rest }, namespacePrefix) {
|
|
5
|
-
// The `namespacePrefix` is part of the type system.
|
|
6
|
-
// See the comment in the function invocation.
|
|
7
|
-
messages = messages[namespacePrefix];
|
|
8
|
-
namespace = resolveNamespace(namespace, namespacePrefix);
|
|
9
|
-
const translator = createBaseTranslator({
|
|
10
|
-
...rest,
|
|
11
|
-
onError,
|
|
12
|
-
getMessageFallback,
|
|
13
|
-
messagesOrError: getMessagesOrError({
|
|
14
|
-
messages,
|
|
15
|
-
namespace,
|
|
16
|
-
onError
|
|
17
|
-
})
|
|
18
|
-
});
|
|
19
|
-
const originalRich = translator.rich;
|
|
20
|
-
function base(...args) {
|
|
21
|
-
return translator(...args);
|
|
22
|
-
}
|
|
23
|
-
// Augment `t.rich` to return plain strings
|
|
24
|
-
base.rich = (key,
|
|
25
|
-
/** Key value pairs for values to interpolate into the message. */
|
|
26
|
-
values, formats) => {
|
|
27
|
-
// `chunks` is returned as a string when no React element
|
|
28
|
-
// is used, therefore it's safe to cast this type.
|
|
29
|
-
const result = originalRich(key, values, formats);
|
|
30
|
-
// When only string chunks are provided to the parser, only strings should be returned here.
|
|
31
|
-
if (typeof result !== 'string') {
|
|
32
|
-
const error = new IntlError(IntlErrorCode.FORMATTING_ERROR, process.env.NODE_ENV !== 'production'
|
|
33
|
-
? "`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})"
|
|
34
|
-
: undefined);
|
|
35
|
-
onError(error);
|
|
36
|
-
return getMessageFallback({ error, key, namespace });
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
base.raw = translator.raw;
|
|
41
|
-
return base;
|
|
42
|
-
}
|
|
1
|
+
"use strict";var M=Object.create;var o=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var V=(r,e)=>{for(var s in e)o(r,s,{get:e[s],enumerable:!0})},d=(r,e,s,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of O(e))!E.call(r,t)&&t!==s&&o(r,t,{get:()=>e[t],enumerable:!(a=N(e,t))||a.enumerable});return r};var f=(r,e,s)=>(s=r!=null?M(C(r)):{},d(e||!r||!r.__esModule?o(s,"default",{value:r,enumerable:!0}):s,r)),b=r=>d(o({},"__esModule",{value:!0}),r);var x={};V(x,{default:()=>I});module.exports=b(x);var i=f(require("./IntlError")),l=f(require("./createBaseTranslator")),h=f(require("./resolveNamespace"));function I({getMessageFallback:r,messages:e,namespace:s,onError:a,...t},p){e=e[p],s=(0,h.default)(s,p);const c=(0,l.default)({...t,onError:a,getMessageFallback:r,messagesOrError:(0,l.getMessagesOrError)({messages:e,namespace:s,onError:a})}),T=c.rich;function g(...n){return c(...n)}return g.rich=(n,R,y)=>{const m=T(n,R,y);if(typeof m!="string"){const u=new i.default(i.IntlErrorCode.FORMATTING_ERROR,process.env.NODE_ENV!=="production"?"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})":void 0);return a(u),r({error:u,key:n,namespace:s})}return m},g.raw=c.raw,g}
|
|
43
2
|
//# sourceMappingURL=createTranslatorImpl.js.map
|