@formatjs/intl 2.3.1 → 2.3.2

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 (106) hide show
  1. package/BUILD +79 -0
  2. package/CHANGELOG.md +537 -0
  3. package/LICENSE.md +0 -0
  4. package/README.md +0 -0
  5. package/index.ts +38 -0
  6. package/package.json +12 -8
  7. package/src/create-intl.ts +159 -0
  8. package/src/dateTime.ts +204 -0
  9. package/src/displayName.ts +54 -0
  10. package/src/error.ts +106 -0
  11. package/src/list.ts +119 -0
  12. package/src/message.ts +246 -0
  13. package/src/number.ts +101 -0
  14. package/src/plural.ts +45 -0
  15. package/src/relativeTime.ts +74 -0
  16. package/src/types.ts +234 -0
  17. package/src/utils.ts +177 -0
  18. package/tests/__snapshots__/formatDate.test.ts.snap +13 -0
  19. package/tests/__snapshots__/formatMessage.test.ts.snap +45 -0
  20. package/tests/__snapshots__/formatNumber.test.ts.snap +13 -0
  21. package/tests/__snapshots__/formatRelativeTime.test.ts.snap +19 -0
  22. package/tests/__snapshots__/formatTime.test.ts.snap +13 -0
  23. package/tests/create-intl.test.ts +60 -0
  24. package/tests/error.test.ts +25 -0
  25. package/tests/formatDate.test.ts +167 -0
  26. package/tests/formatDisplayNames.test.ts +63 -0
  27. package/tests/formatList.test.ts +51 -0
  28. package/tests/formatMessage.test.ts +495 -0
  29. package/tests/formatNumber.test.ts +172 -0
  30. package/tests/formatPlural.test.ts +119 -0
  31. package/tests/formatRelativeTime.test.ts +145 -0
  32. package/tests/formatTime.test.ts +234 -0
  33. package/tests/global.d.ts +7 -0
  34. package/tsconfig.json +5 -0
  35. package/index.d.ts +0 -17
  36. package/index.d.ts.map +0 -1
  37. package/index.js +0 -40
  38. package/lib/index.d.ts +0 -17
  39. package/lib/index.d.ts.map +0 -1
  40. package/lib/index.js +0 -17
  41. package/lib/src/create-intl.d.ts +0 -11
  42. package/lib/src/create-intl.d.ts.map +0 -1
  43. package/lib/src/create-intl.js +0 -51
  44. package/lib/src/dateTime.d.ts +0 -38
  45. package/lib/src/dateTime.d.ts.map +0 -1
  46. package/lib/src/dateTime.js +0 -117
  47. package/lib/src/displayName.d.ts +0 -6
  48. package/lib/src/displayName.d.ts.map +0 -1
  49. package/lib/src/displayName.js +0 -22
  50. package/lib/src/error.d.ts +0 -34
  51. package/lib/src/error.d.ts.map +0 -1
  52. package/lib/src/error.js +0 -88
  53. package/lib/src/list.d.ts +0 -11
  54. package/lib/src/list.d.ts.map +0 -1
  55. package/lib/src/list.js +0 -61
  56. package/lib/src/message.d.ts +0 -16
  57. package/lib/src/message.d.ts.map +0 -1
  58. package/lib/src/message.js +0 -103
  59. package/lib/src/number.d.ts +0 -17
  60. package/lib/src/number.d.ts.map +0 -1
  61. package/lib/src/number.js +0 -54
  62. package/lib/src/plural.d.ts +0 -7
  63. package/lib/src/plural.d.ts.map +0 -1
  64. package/lib/src/plural.js +0 -19
  65. package/lib/src/relativeTime.d.ts +0 -7
  66. package/lib/src/relativeTime.d.ts.map +0 -1
  67. package/lib/src/relativeTime.js +0 -29
  68. package/lib/src/types.d.ts +0 -103
  69. package/lib/src/types.d.ts.map +0 -1
  70. package/lib/src/types.js +0 -1
  71. package/lib/src/utils.d.ts +0 -12
  72. package/lib/src/utils.d.ts.map +0 -1
  73. package/lib/src/utils.js +0 -162
  74. package/src/create-intl.d.ts +0 -11
  75. package/src/create-intl.d.ts.map +0 -1
  76. package/src/create-intl.js +0 -55
  77. package/src/dateTime.d.ts +0 -38
  78. package/src/dateTime.d.ts.map +0 -1
  79. package/src/dateTime.js +0 -126
  80. package/src/displayName.d.ts +0 -6
  81. package/src/displayName.d.ts.map +0 -1
  82. package/src/displayName.js +0 -26
  83. package/src/error.d.ts +0 -34
  84. package/src/error.d.ts.map +0 -1
  85. package/src/error.js +0 -91
  86. package/src/list.d.ts +0 -11
  87. package/src/list.d.ts.map +0 -1
  88. package/src/list.js +0 -66
  89. package/src/message.d.ts +0 -16
  90. package/src/message.d.ts.map +0 -1
  91. package/src/message.js +0 -107
  92. package/src/number.d.ts +0 -17
  93. package/src/number.d.ts.map +0 -1
  94. package/src/number.js +0 -60
  95. package/src/plural.d.ts +0 -7
  96. package/src/plural.d.ts.map +0 -1
  97. package/src/plural.js +0 -23
  98. package/src/relativeTime.d.ts +0 -7
  99. package/src/relativeTime.d.ts.map +0 -1
  100. package/src/relativeTime.js +0 -33
  101. package/src/types.d.ts +0 -103
  102. package/src/types.d.ts.map +0 -1
  103. package/src/types.js +0 -2
  104. package/src/utils.d.ts +0 -12
  105. package/src/utils.d.ts.map +0 -1
  106. package/src/utils.js +0 -169
package/lib/src/number.js DELETED
@@ -1,54 +0,0 @@
1
- import { getNamedFormat, filterProps } from './utils';
2
- import { IntlError, IntlErrorCode } from './error';
3
- var NUMBER_FORMAT_OPTIONS = [
4
- 'style',
5
- 'currency',
6
- 'currencyDisplay',
7
- 'unit',
8
- 'unitDisplay',
9
- 'useGrouping',
10
- 'minimumIntegerDigits',
11
- 'minimumFractionDigits',
12
- 'maximumFractionDigits',
13
- 'minimumSignificantDigits',
14
- 'maximumSignificantDigits',
15
- // ES2020 NumberFormat
16
- 'compactDisplay',
17
- 'currencyDisplay',
18
- 'currencySign',
19
- 'notation',
20
- 'signDisplay',
21
- 'unit',
22
- 'unitDisplay',
23
- 'numberingSystem',
24
- ];
25
- export function getFormatter(_a, getNumberFormat, options) {
26
- var locale = _a.locale, formats = _a.formats, onError = _a.onError;
27
- if (options === void 0) { options = {}; }
28
- var format = options.format;
29
- var defaults = ((format &&
30
- getNamedFormat(formats, 'number', format, onError)) ||
31
- {});
32
- var filteredOptions = filterProps(options, NUMBER_FORMAT_OPTIONS, defaults);
33
- return getNumberFormat(locale, filteredOptions);
34
- }
35
- export function formatNumber(config, getNumberFormat, value, options) {
36
- if (options === void 0) { options = {}; }
37
- try {
38
- return getFormatter(config, getNumberFormat, options).format(value);
39
- }
40
- catch (e) {
41
- config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting number.', e));
42
- }
43
- return String(value);
44
- }
45
- export function formatNumberToParts(config, getNumberFormat, value, options) {
46
- if (options === void 0) { options = {}; }
47
- try {
48
- return getFormatter(config, getNumberFormat, options).formatToParts(value);
49
- }
50
- catch (e) {
51
- config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting number.', e));
52
- }
53
- return [];
54
- }
@@ -1,7 +0,0 @@
1
- import { Formatters, IntlFormatters, OnErrorFn } from './types';
2
- import { LDMLPluralRule } from '@formatjs/ecma402-abstract';
3
- export declare function formatPlural({ locale, onError, }: {
4
- locale: string;
5
- onError: OnErrorFn;
6
- }, getPluralRules: Formatters['getPluralRules'], value: Parameters<IntlFormatters['formatPlural']>[0], options?: Parameters<IntlFormatters['formatPlural']>[1]): LDMLPluralRule;
7
- //# sourceMappingURL=plural.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/plural.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAI7D,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAA;AAIzD,wBAAgB,YAAY,CAC1B,EACE,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,EAC5C,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,EACpD,OAAO,GAAE,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAM,GAC1D,cAAc,CAyBhB"}
package/lib/src/plural.js DELETED
@@ -1,19 +0,0 @@
1
- import { filterProps } from './utils';
2
- import { IntlFormatError } from './error';
3
- import { ErrorCode, FormatError } from 'intl-messageformat';
4
- var PLURAL_FORMAT_OPTIONS = ['type'];
5
- export function formatPlural(_a, getPluralRules, value, options) {
6
- var locale = _a.locale, onError = _a.onError;
7
- if (options === void 0) { options = {}; }
8
- if (!Intl.PluralRules) {
9
- onError(new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", ErrorCode.MISSING_INTL_API));
10
- }
11
- var filteredOptions = filterProps(options, PLURAL_FORMAT_OPTIONS);
12
- try {
13
- return getPluralRules(locale, filteredOptions).select(value);
14
- }
15
- catch (e) {
16
- onError(new IntlFormatError('Error formatting plural.', locale, e));
17
- }
18
- return 'other';
19
- }
@@ -1,7 +0,0 @@
1
- import { IntlFormatters, Formatters, CustomFormats, OnErrorFn } from './types';
2
- export declare function formatRelativeTime(config: {
3
- locale: string;
4
- formats: CustomFormats;
5
- onError: OnErrorFn;
6
- }, getRelativeTimeFormat: Formatters['getRelativeTimeFormat'], value: Parameters<IntlFormatters['formatRelativeTime']>[0], unit?: Parameters<IntlFormatters['formatRelativeTime']>[1], options?: Parameters<IntlFormatters['formatRelativeTime']>[2]): string;
7
- //# sourceMappingURL=relativeTime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"relativeTime.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/relativeTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAoC5E,wBAAgB,kBAAkB,CAChC,MAAM,EAAE;IACN,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,qBAAqB,EAAE,UAAU,CAAC,uBAAuB,CAAC,EAC1D,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EAC1D,IAAI,CAAC,EAAE,UAAU,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EAC1D,OAAO,GAAE,UAAU,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAM,GAChE,MAAM,CA2BR"}
@@ -1,29 +0,0 @@
1
- import { getNamedFormat, filterProps } from './utils';
2
- import { FormatError, ErrorCode } from 'intl-messageformat';
3
- import { IntlFormatError } from './error';
4
- var RELATIVE_TIME_FORMAT_OPTIONS = ['numeric', 'style'];
5
- function getFormatter(_a, getRelativeTimeFormat, options) {
6
- var locale = _a.locale, formats = _a.formats, onError = _a.onError;
7
- if (options === void 0) { options = {}; }
8
- var format = options.format;
9
- var defaults = (!!format && getNamedFormat(formats, 'relative', format, onError)) || {};
10
- var filteredOptions = filterProps(options, RELATIVE_TIME_FORMAT_OPTIONS, defaults);
11
- return getRelativeTimeFormat(locale, filteredOptions);
12
- }
13
- export function formatRelativeTime(config, getRelativeTimeFormat, value, unit, options) {
14
- if (options === void 0) { options = {}; }
15
- if (!unit) {
16
- unit = 'second';
17
- }
18
- var RelativeTimeFormat = Intl.RelativeTimeFormat;
19
- if (!RelativeTimeFormat) {
20
- config.onError(new FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n", ErrorCode.MISSING_INTL_API));
21
- }
22
- try {
23
- return getFormatter(config, getRelativeTimeFormat, options).format(value, unit);
24
- }
25
- catch (e) {
26
- config.onError(new IntlFormatError('Error formatting relative time.', config.locale, e));
27
- }
28
- return String(value);
29
- }
@@ -1,103 +0,0 @@
1
- import { IntlMessageFormat, Formats, FormatXMLElementFn, FormatError, PrimitiveType, Options as IntlMessageFormatOptions } from 'intl-messageformat';
2
- import { DateTimeFormat } from '@formatjs/ecma402-abstract';
3
- import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
4
- import IntlListFormat, { IntlListFormatOptions, Part } from '@formatjs/intl-listformat';
5
- import { DisplayNames, DisplayNamesOptions } from '@formatjs/intl-displaynames';
6
- import { MissingTranslationError, MessageFormatError, MissingDataError, InvalidConfigError, UnsupportedFormatterError } from './error';
7
- import { DEFAULT_INTL_CONFIG } from './utils';
8
- import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
9
- declare global {
10
- namespace FormatjsIntl {
11
- interface Message {
12
- }
13
- interface IntlConfig {
14
- }
15
- interface Formats {
16
- }
17
- }
18
- }
19
- declare type MessageIds = FormatjsIntl.Message extends {
20
- ids: string;
21
- } ? FormatjsIntl.Message['ids'] : string;
22
- declare type Locale = FormatjsIntl.IntlConfig extends {
23
- locale: string;
24
- } ? FormatjsIntl.IntlConfig['locale'] : string;
25
- export declare type OnErrorFn = (err: MissingTranslationError | MessageFormatError | MissingDataError | InvalidConfigError | UnsupportedFormatterError | FormatError) => void;
26
- export declare type OnWarnFn = (warning: string) => void;
27
- /**
28
- * Config for intl object.
29
- * Generic type T is the type of potential rich text element. For example:
30
- * With React, T would be React.ReactNode
31
- */
32
- export interface ResolvedIntlConfig<T = string> {
33
- locale: Locale;
34
- timeZone?: string;
35
- fallbackOnEmptyString?: boolean;
36
- formats: CustomFormats;
37
- messages: Record<MessageIds, string> | Record<MessageIds, MessageFormatElement[]>;
38
- defaultLocale: string;
39
- defaultFormats: CustomFormats;
40
- defaultRichTextElements?: Record<string, FormatXMLElementFn<T>>;
41
- onError: OnErrorFn;
42
- onWarn?: OnWarnFn;
43
- }
44
- export interface CustomFormats extends Partial<Formats> {
45
- relative?: Record<string, Intl.RelativeTimeFormatOptions>;
46
- }
47
- export interface CustomFormatConfig<Source = string> {
48
- format?: Source extends keyof FormatjsIntl.Formats ? FormatjsIntl.Formats[Source] : string;
49
- }
50
- export declare type FormatDateOptions = Omit<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'date'>;
51
- export declare type FormatNumberOptions = Omit<NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig<'number'>;
52
- export declare type FormatRelativeTimeOptions = Omit<Intl.RelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'time'>;
53
- export declare type FormatPluralOptions = Omit<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;
54
- export declare type FormatListOptions = Omit<IntlListFormatOptions, 'localeMatcher'>;
55
- export declare type FormatDisplayNameOptions = Omit<DisplayNamesOptions, 'localeMatcher'>;
56
- export interface IntlFormatters<T = any, R = T> {
57
- formatDateTimeRange(from: Parameters<DateTimeFormat['formatRange']>[0], to: Parameters<DateTimeFormat['formatRange']>[1], opts?: FormatDateOptions): string;
58
- formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
59
- formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
60
- formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
61
- formatTimeToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
62
- formatRelativeTime(value: Parameters<Intl.RelativeTimeFormat['format']>[0], unit?: Parameters<Intl.RelativeTimeFormat['format']>[1], opts?: FormatRelativeTimeOptions): string;
63
- formatNumber(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): string;
64
- formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
65
- formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
66
- formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string;
67
- formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T, R>>, opts?: IntlMessageFormatOptions): R;
68
- $t(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string;
69
- $t(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T, R>>, opts?: IntlMessageFormatOptions): R;
70
- formatList(values: ReadonlyArray<string>, opts?: FormatListOptions): string;
71
- formatList(values: ReadonlyArray<string | T>, opts?: FormatListOptions): T | string | Array<string | T>;
72
- formatListToParts(values: ReadonlyArray<string | T>, opts?: FormatListOptions): Part[];
73
- formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts: FormatDisplayNameOptions): string | undefined;
74
- }
75
- export interface Formatters {
76
- getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): DateTimeFormat;
77
- getNumberFormat(locales?: string | string[], opts?: NumberFormatOptions): Intl.NumberFormat;
78
- getMessageFormat(...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
79
- getRelativeTimeFormat(...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
80
- getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
81
- getListFormat(...args: ConstructorParameters<typeof IntlListFormat>): IntlListFormat;
82
- getDisplayNames(...args: ConstructorParameters<typeof DisplayNames>): DisplayNames;
83
- }
84
- export interface IntlShape<T = string> extends ResolvedIntlConfig<T>, IntlFormatters {
85
- formatters: Formatters;
86
- }
87
- export interface IntlCache {
88
- dateTime: Record<string, DateTimeFormat>;
89
- number: Record<string, Intl.NumberFormat>;
90
- message: Record<string, IntlMessageFormat>;
91
- relativeTime: Record<string, Intl.RelativeTimeFormat>;
92
- pluralRules: Record<string, Intl.PluralRules>;
93
- list: Record<string, IntlListFormat>;
94
- displayNames: Record<string, DisplayNames>;
95
- }
96
- export interface MessageDescriptor {
97
- id?: MessageIds;
98
- description?: string | object;
99
- defaultMessage?: string | MessageFormatElement[];
100
- }
101
- export declare type IntlConfig<T = string> = Omit<ResolvedIntlConfig<T>, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
102
- export {};
103
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,OAAO,EACP,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,OAAO,IAAI,wBAAwB,EACpC,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAA;AACzD,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AACvE,OAAO,cAAc,EAAE,EACrB,qBAAqB,EACrB,IAAI,EACL,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAC,YAAY,EAAE,mBAAmB,EAAC,MAAM,6BAA6B,CAAA;AAC7E,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EAC1B,MAAM,SAAS,CAAA;AAChB,OAAO,EAAC,mBAAmB,EAAC,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAA;AAE9D,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,YAAY,CAAC;QACrB,UAAU,OAAO;SAAG;QACpB,UAAU,UAAU;SAAG;QACvB,UAAU,OAAO;SAAG;KACrB;CACF;AAED,aAAK,UAAU,GAAG,YAAY,CAAC,OAAO,SAAS;IAAC,GAAG,EAAE,MAAM,CAAA;CAAC,GACxD,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,GAC3B,MAAM,CAAA;AAEV,aAAK,MAAM,GAAG,YAAY,CAAC,UAAU,SAAS;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,GAC1D,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,GACjC,MAAM,CAAA;AAEV,oBAAY,SAAS,GAAG,CACtB,GAAG,EACC,uBAAuB,GACvB,kBAAkB,GAClB,gBAAgB,GAChB,kBAAkB,GAClB,yBAAyB,GACzB,WAAW,KACZ,IAAI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;IAC7B,cAAc,CAAC,EAAE,MAAM,GAAG,oBAAoB,EAAE,CAAA;CACjD;AAED,oBAAY,UAAU,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,CACvC,kBAAkB,CAAC,CAAC,CAAC,EACrB,MAAM,OAAO,mBAAmB,CACjC,GACC,OAAO,CAAC,OAAO,mBAAmB,CAAC,CAAA"}
package/lib/src/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import { IntlCache, CustomFormats, Formatters, OnErrorFn, ResolvedIntlConfig } from './types';
2
- import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
3
- export declare function filterProps<T extends Record<string, any>, K extends string>(props: T, allowlist: Array<K>, defaults?: Partial<T>): Pick<T, K>;
4
- export declare const DEFAULT_INTL_CONFIG: Pick<ResolvedIntlConfig<any>, 'fallbackOnEmptyString' | 'formats' | 'messages' | 'timeZone' | 'defaultLocale' | 'defaultFormats' | 'onError' | 'onWarn'>;
5
- export declare function createIntlCache(): IntlCache;
6
- /**
7
- * Create intl formatters and populate cache
8
- * @param cache explicit cache to prevent leaking memory
9
- */
10
- export declare function createFormatters(cache?: IntlCache): Formatters;
11
- export declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: OnErrorFn): NumberFormatOptions | Intl.DateTimeFormatOptions | Intl.RelativeTimeFormatOptions | undefined;
12
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,aAAa,EACb,UAAU,EACV,SAAS,EAET,kBAAkB,EACnB,MAAM,SAAS,CAAA;AAIhB,OAAO,EAAiB,mBAAmB,EAAC,MAAM,4BAA4B,CAAA;AAE9E,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,MAAM,EACzE,KAAK,EAAE,CAAC,EACR,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,EACnB,QAAQ,GAAE,OAAO,CAAC,CAAC,CAAM,GACxB,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAUZ;AAgBD,eAAO,MAAM,mBAAmB,EAAE,IAAI,CACpC,kBAAkB,CAAC,GAAG,CAAC,EACrB,uBAAuB,GACvB,SAAS,GACT,UAAU,GACV,UAAU,GACV,eAAe,GACf,gBAAgB,GAChB,SAAS,GACT,QAAQ,CAaX,CAAA;AAED,wBAAgB,eAAe,IAAI,SAAS,CAU3C;AAiBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,GAAE,SAA6B,GACnC,UAAU,CAsDZ;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,aAAa,EAC1D,OAAO,EAAE,aAAa,EACtB,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,GAEhB,mBAAmB,GACnB,IAAI,CAAC,qBAAqB,GAC1B,IAAI,CAAC,yBAAyB,GAC9B,SAAS,CAWZ"}
package/lib/src/utils.js DELETED
@@ -1,162 +0,0 @@
1
- import { __assign, __spreadArray } from "tslib";
2
- import { IntlMessageFormat } from 'intl-messageformat';
3
- import memoize, { strategies } from '@formatjs/fast-memoize';
4
- import { UnsupportedFormatterError } from './error';
5
- export function filterProps(props, allowlist, defaults) {
6
- if (defaults === void 0) { defaults = {}; }
7
- return allowlist.reduce(function (filtered, name) {
8
- if (name in props) {
9
- filtered[name] = props[name];
10
- }
11
- else if (name in defaults) {
12
- filtered[name] = defaults[name];
13
- }
14
- return filtered;
15
- }, {});
16
- }
17
- var defaultErrorHandler = function (error) {
18
- // @ts-ignore just so we don't need to declare dep on @types/node
19
- if (process.env.NODE_ENV !== 'production') {
20
- console.error(error);
21
- }
22
- };
23
- var defaultWarnHandler = function (warning) {
24
- // @ts-ignore just so we don't need to declare dep on @types/node
25
- if (process.env.NODE_ENV !== 'production') {
26
- console.warn(warning);
27
- }
28
- };
29
- export var DEFAULT_INTL_CONFIG = {
30
- formats: {},
31
- messages: {},
32
- timeZone: undefined,
33
- defaultLocale: 'en',
34
- defaultFormats: {},
35
- fallbackOnEmptyString: true,
36
- onError: defaultErrorHandler,
37
- onWarn: defaultWarnHandler,
38
- };
39
- export function createIntlCache() {
40
- return {
41
- dateTime: {},
42
- number: {},
43
- message: {},
44
- relativeTime: {},
45
- pluralRules: {},
46
- list: {},
47
- displayNames: {},
48
- };
49
- }
50
- function createFastMemoizeCache(store) {
51
- return {
52
- create: function () {
53
- return {
54
- get: function (key) {
55
- return store[key];
56
- },
57
- set: function (key, value) {
58
- store[key] = value;
59
- },
60
- };
61
- },
62
- };
63
- }
64
- /**
65
- * Create intl formatters and populate cache
66
- * @param cache explicit cache to prevent leaking memory
67
- */
68
- export function createFormatters(cache) {
69
- if (cache === void 0) { cache = createIntlCache(); }
70
- var RelativeTimeFormat = Intl.RelativeTimeFormat;
71
- var ListFormat = Intl.ListFormat;
72
- var DisplayNames = Intl.DisplayNames;
73
- var getDateTimeFormat = memoize(function () {
74
- var _a;
75
- var args = [];
76
- for (var _i = 0; _i < arguments.length; _i++) {
77
- args[_i] = arguments[_i];
78
- }
79
- return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
80
- }, {
81
- cache: createFastMemoizeCache(cache.dateTime),
82
- strategy: strategies.variadic,
83
- });
84
- var getNumberFormat = memoize(function () {
85
- var _a;
86
- var args = [];
87
- for (var _i = 0; _i < arguments.length; _i++) {
88
- args[_i] = arguments[_i];
89
- }
90
- return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
91
- }, {
92
- cache: createFastMemoizeCache(cache.number),
93
- strategy: strategies.variadic,
94
- });
95
- var getPluralRules = memoize(function () {
96
- var _a;
97
- var args = [];
98
- for (var _i = 0; _i < arguments.length; _i++) {
99
- args[_i] = arguments[_i];
100
- }
101
- return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args, false)))();
102
- }, {
103
- cache: createFastMemoizeCache(cache.pluralRules),
104
- strategy: strategies.variadic,
105
- });
106
- return {
107
- getDateTimeFormat: getDateTimeFormat,
108
- getNumberFormat: getNumberFormat,
109
- getMessageFormat: memoize(function (message, locales, overrideFormats, opts) {
110
- return new IntlMessageFormat(message, locales, overrideFormats, __assign({ formatters: {
111
- getNumberFormat: getNumberFormat,
112
- getDateTimeFormat: getDateTimeFormat,
113
- getPluralRules: getPluralRules,
114
- } }, (opts || {})));
115
- }, {
116
- cache: createFastMemoizeCache(cache.message),
117
- strategy: strategies.variadic,
118
- }),
119
- getRelativeTimeFormat: memoize(function () {
120
- var args = [];
121
- for (var _i = 0; _i < arguments.length; _i++) {
122
- args[_i] = arguments[_i];
123
- }
124
- return new (RelativeTimeFormat.bind.apply(RelativeTimeFormat, __spreadArray([void 0], args, false)))();
125
- }, {
126
- cache: createFastMemoizeCache(cache.relativeTime),
127
- strategy: strategies.variadic,
128
- }),
129
- getPluralRules: getPluralRules,
130
- getListFormat: memoize(function () {
131
- var args = [];
132
- for (var _i = 0; _i < arguments.length; _i++) {
133
- args[_i] = arguments[_i];
134
- }
135
- return new (ListFormat.bind.apply(ListFormat, __spreadArray([void 0], args, false)))();
136
- }, {
137
- cache: createFastMemoizeCache(cache.list),
138
- strategy: strategies.variadic,
139
- }),
140
- getDisplayNames: memoize(function () {
141
- var args = [];
142
- for (var _i = 0; _i < arguments.length; _i++) {
143
- args[_i] = arguments[_i];
144
- }
145
- return new (DisplayNames.bind.apply(DisplayNames, __spreadArray([void 0], args, false)))();
146
- }, {
147
- cache: createFastMemoizeCache(cache.displayNames),
148
- strategy: strategies.variadic,
149
- }),
150
- };
151
- }
152
- export function getNamedFormat(formats, type, name, onError) {
153
- var formatType = formats && formats[type];
154
- var format;
155
- if (formatType) {
156
- format = formatType[name];
157
- }
158
- if (format) {
159
- return format;
160
- }
161
- onError(new UnsupportedFormatterError("No ".concat(type, " format named: ").concat(name)));
162
- }
@@ -1,11 +0,0 @@
1
- import { IntlCache, IntlShape, IntlConfig } from './types';
2
- export interface CreateIntlFn<T = string, C extends IntlConfig<T> = IntlConfig<T>, S extends IntlShape<T> = IntlShape<T>> {
3
- (config: C, cache?: IntlCache): S;
4
- }
5
- /**
6
- * Create intl object
7
- * @param config intl config
8
- * @param cache cache for formatter instances to prevent memory leak
9
- */
10
- export declare function createIntl<T = string>(config: IntlConfig<T>, cache?: IntlCache): IntlShape<T>;
11
- //# sourceMappingURL=create-intl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-intl.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/create-intl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAqB,MAAM,SAAS,CAAA;AAkB5E,MAAM,WAAW,YAAY,CAC3B,CAAC,GAAG,MAAM,EACV,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EACvC,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAErC,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,CAAC,CAAA;CAClC;AAsBD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,MAAM,EACnC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,KAAK,CAAC,EAAE,SAAS,GAChB,SAAS,CAAC,CAAC,CAAC,CAsGd"}
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createIntl = void 0;
4
- var tslib_1 = require("tslib");
5
- var utils_1 = require("./utils");
6
- var error_1 = require("./error");
7
- var number_1 = require("./number");
8
- var relativeTime_1 = require("./relativeTime");
9
- var dateTime_1 = require("./dateTime");
10
- var plural_1 = require("./plural");
11
- var message_1 = require("./message");
12
- var list_1 = require("./list");
13
- var displayName_1 = require("./displayName");
14
- function messagesContainString(messages) {
15
- var firstMessage = messages ? messages[Object.keys(messages)[0]] : undefined;
16
- return typeof firstMessage === 'string';
17
- }
18
- function verifyConfigMessages(config) {
19
- if (config.onWarn &&
20
- config.defaultRichTextElements &&
21
- messagesContainString(config.messages || {})) {
22
- config.onWarn("[@formatjs/intl] \"defaultRichTextElements\" was specified but \"message\" was not pre-compiled. \nPlease consider using \"@formatjs/cli\" to pre-compile your messages for performance.\nFor more details see https://formatjs.io/docs/getting-started/message-distribution");
23
- }
24
- }
25
- /**
26
- * Create intl object
27
- * @param config intl config
28
- * @param cache cache for formatter instances to prevent memory leak
29
- */
30
- function createIntl(config, cache) {
31
- var formatters = (0, utils_1.createFormatters)(cache);
32
- var resolvedConfig = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, utils_1.DEFAULT_INTL_CONFIG), config);
33
- var locale = resolvedConfig.locale, defaultLocale = resolvedConfig.defaultLocale, onError = resolvedConfig.onError;
34
- if (!locale) {
35
- if (onError) {
36
- onError(new error_1.InvalidConfigError("\"locale\" was not configured, using \"".concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl/api#intlshape for more details")));
37
- }
38
- // Since there's no registered locale data for `locale`, this will
39
- // fallback to the `defaultLocale` to make sure things can render.
40
- // The `messages` are overridden to the `defaultProps` empty object
41
- // to maintain referential equality across re-renders. It's assumed
42
- // each <FormattedMessage> contains a `defaultMessage` prop.
43
- resolvedConfig.locale = resolvedConfig.defaultLocale || 'en';
44
- }
45
- else if (!Intl.NumberFormat.supportedLocalesOf(locale).length && onError) {
46
- onError(new error_1.MissingDataError("Missing locale data for locale: \"".concat(locale, "\" in Intl.NumberFormat. Using default locale: \"").concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl#runtime-requirements for more details")));
47
- }
48
- else if (!Intl.DateTimeFormat.supportedLocalesOf(locale).length &&
49
- onError) {
50
- onError(new error_1.MissingDataError("Missing locale data for locale: \"".concat(locale, "\" in Intl.DateTimeFormat. Using default locale: \"").concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl#runtime-requirements for more details")));
51
- }
52
- verifyConfigMessages(resolvedConfig);
53
- return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, resolvedConfig), { formatters: formatters, formatNumber: number_1.formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: number_1.formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: relativeTime_1.formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: dateTime_1.formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: dateTime_1.formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: dateTime_1.formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateTimeRange: dateTime_1.formatDateTimeRange.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: dateTime_1.formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: plural_1.formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: message_1.formatMessage.bind(null, resolvedConfig, formatters), $t: message_1.formatMessage.bind(null, resolvedConfig, formatters), formatList: list_1.formatList.bind(null, resolvedConfig, formatters.getListFormat), formatListToParts: list_1.formatListToParts.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: displayName_1.formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
54
- }
55
- exports.createIntl = createIntl;
package/src/dateTime.d.ts DELETED
@@ -1,38 +0,0 @@
1
- import { Formatters, IntlFormatters, CustomFormats, OnErrorFn } from './types';
2
- import { DateTimeFormat } from '@formatjs/ecma402-abstract';
3
- export declare function getFormatter({ locale, formats, onError, timeZone, }: {
4
- locale: string;
5
- timeZone?: string;
6
- formats: CustomFormats;
7
- onError: OnErrorFn;
8
- }, type: 'date' | 'time', getDateTimeFormat: Formatters['getDateTimeFormat'], options?: Parameters<IntlFormatters['formatDate']>[1]): DateTimeFormat;
9
- export declare function formatDate(config: {
10
- locale: string;
11
- timeZone?: string;
12
- formats: CustomFormats;
13
- onError: OnErrorFn;
14
- }, getDateTimeFormat: Formatters['getDateTimeFormat'], ...[value, options]: Parameters<IntlFormatters['formatDate']>): string;
15
- export declare function formatTime(config: {
16
- locale: string;
17
- timeZone?: string;
18
- formats: CustomFormats;
19
- onError: OnErrorFn;
20
- }, getDateTimeFormat: Formatters['getDateTimeFormat'], ...[value, options]: Parameters<IntlFormatters['formatTime']>): string;
21
- export declare function formatDateTimeRange(config: {
22
- locale: string;
23
- timeZone?: string;
24
- onError: OnErrorFn;
25
- }, getDateTimeFormat: Formatters['getDateTimeFormat'], ...[from, to, options]: Parameters<IntlFormatters['formatDateTimeRange']>): string;
26
- export declare function formatDateToParts(config: {
27
- locale: string;
28
- timeZone?: string;
29
- formats: CustomFormats;
30
- onError: OnErrorFn;
31
- }, getDateTimeFormat: Formatters['getDateTimeFormat'], ...[value, options]: Parameters<IntlFormatters['formatDate']>): Intl.DateTimeFormatPart[];
32
- export declare function formatTimeToParts(config: {
33
- locale: string;
34
- timeZone?: string;
35
- formats: CustomFormats;
36
- onError: OnErrorFn;
37
- }, getDateTimeFormat: Formatters['getDateTimeFormat'], ...[value, options]: Parameters<IntlFormatters['formatTimeToParts']>): Intl.DateTimeFormatPart[];
38
- //# sourceMappingURL=dateTime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dateTime.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/dateTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAI5E,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAA;AA0BzD,wBAAgB,YAAY,CAC1B,EACE,MAAM,EACN,OAAO,EACP,OAAO,EACP,QAAQ,GACT,EAAE;IACD,MAAM,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