@formatjs/intl 2.3.2 → 2.4.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.
Files changed (104) hide show
  1. package/index.d.ts +17 -0
  2. package/index.d.ts.map +1 -0
  3. package/index.js +40 -0
  4. package/lib/index.d.ts +17 -0
  5. package/lib/index.d.ts.map +1 -0
  6. package/lib/index.js +17 -0
  7. package/lib/src/create-intl.d.ts +11 -0
  8. package/lib/src/create-intl.d.ts.map +1 -0
  9. package/lib/src/create-intl.js +55 -0
  10. package/lib/src/dateTime.d.ts +38 -0
  11. package/lib/src/dateTime.d.ts.map +1 -0
  12. package/lib/src/dateTime.js +117 -0
  13. package/lib/src/displayName.d.ts +6 -0
  14. package/lib/src/displayName.d.ts.map +1 -0
  15. package/lib/src/displayName.js +22 -0
  16. package/lib/src/error.d.ts +34 -0
  17. package/lib/src/error.d.ts.map +1 -0
  18. package/lib/src/error.js +88 -0
  19. package/lib/src/list.d.ts +11 -0
  20. package/lib/src/list.d.ts.map +1 -0
  21. package/lib/src/list.js +61 -0
  22. package/lib/src/message.d.ts +16 -0
  23. package/lib/src/message.d.ts.map +1 -0
  24. package/lib/src/message.js +103 -0
  25. package/lib/src/number.d.ts +17 -0
  26. package/lib/src/number.d.ts.map +1 -0
  27. package/lib/src/number.js +54 -0
  28. package/lib/src/plural.d.ts +7 -0
  29. package/lib/src/plural.d.ts.map +1 -0
  30. package/lib/src/plural.js +19 -0
  31. package/lib/src/relativeTime.d.ts +7 -0
  32. package/lib/src/relativeTime.d.ts.map +1 -0
  33. package/lib/src/relativeTime.js +29 -0
  34. package/lib/src/types.d.ts +103 -0
  35. package/lib/src/types.d.ts.map +1 -0
  36. package/lib/src/types.js +1 -0
  37. package/lib/src/utils.d.ts +12 -0
  38. package/lib/src/utils.d.ts.map +1 -0
  39. package/lib/src/utils.js +162 -0
  40. package/package.json +10 -10
  41. package/src/create-intl.d.ts +11 -0
  42. package/src/create-intl.d.ts.map +1 -0
  43. package/src/create-intl.js +59 -0
  44. package/src/dateTime.d.ts +38 -0
  45. package/src/dateTime.d.ts.map +1 -0
  46. package/src/dateTime.js +126 -0
  47. package/src/displayName.d.ts +6 -0
  48. package/src/displayName.d.ts.map +1 -0
  49. package/src/displayName.js +26 -0
  50. package/src/error.d.ts +34 -0
  51. package/src/error.d.ts.map +1 -0
  52. package/src/error.js +91 -0
  53. package/src/list.d.ts +11 -0
  54. package/src/list.d.ts.map +1 -0
  55. package/src/list.js +66 -0
  56. package/src/message.d.ts +16 -0
  57. package/src/message.d.ts.map +1 -0
  58. package/src/message.js +107 -0
  59. package/src/number.d.ts +17 -0
  60. package/src/number.d.ts.map +1 -0
  61. package/src/number.js +60 -0
  62. package/src/plural.d.ts +7 -0
  63. package/src/plural.d.ts.map +1 -0
  64. package/src/plural.js +23 -0
  65. package/src/relativeTime.d.ts +7 -0
  66. package/src/relativeTime.d.ts.map +1 -0
  67. package/src/relativeTime.js +33 -0
  68. package/src/types.d.ts +103 -0
  69. package/src/types.d.ts.map +1 -0
  70. package/src/types.js +2 -0
  71. package/src/utils.d.ts +12 -0
  72. package/src/utils.d.ts.map +1 -0
  73. package/src/utils.js +169 -0
  74. package/BUILD +0 -79
  75. package/CHANGELOG.md +0 -537
  76. package/index.ts +0 -38
  77. package/src/create-intl.ts +0 -159
  78. package/src/dateTime.ts +0 -204
  79. package/src/displayName.ts +0 -54
  80. package/src/error.ts +0 -106
  81. package/src/list.ts +0 -119
  82. package/src/message.ts +0 -246
  83. package/src/number.ts +0 -101
  84. package/src/plural.ts +0 -45
  85. package/src/relativeTime.ts +0 -74
  86. package/src/types.ts +0 -234
  87. package/src/utils.ts +0 -177
  88. package/tests/__snapshots__/formatDate.test.ts.snap +0 -13
  89. package/tests/__snapshots__/formatMessage.test.ts.snap +0 -45
  90. package/tests/__snapshots__/formatNumber.test.ts.snap +0 -13
  91. package/tests/__snapshots__/formatRelativeTime.test.ts.snap +0 -19
  92. package/tests/__snapshots__/formatTime.test.ts.snap +0 -13
  93. package/tests/create-intl.test.ts +0 -60
  94. package/tests/error.test.ts +0 -25
  95. package/tests/formatDate.test.ts +0 -167
  96. package/tests/formatDisplayNames.test.ts +0 -63
  97. package/tests/formatList.test.ts +0 -51
  98. package/tests/formatMessage.test.ts +0 -495
  99. package/tests/formatNumber.test.ts +0 -172
  100. package/tests/formatPlural.test.ts +0 -119
  101. package/tests/formatRelativeTime.test.ts +0 -145
  102. package/tests/formatTime.test.ts +0 -234
  103. package/tests/global.d.ts +0 -7
  104. package/tsconfig.json +0 -5
package/src/number.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatNumberToParts = exports.formatNumber = exports.getFormatter = void 0;
4
+ var utils_1 = require("./utils");
5
+ var error_1 = require("./error");
6
+ var NUMBER_FORMAT_OPTIONS = [
7
+ 'style',
8
+ 'currency',
9
+ 'currencyDisplay',
10
+ 'unit',
11
+ 'unitDisplay',
12
+ 'useGrouping',
13
+ 'minimumIntegerDigits',
14
+ 'minimumFractionDigits',
15
+ 'maximumFractionDigits',
16
+ 'minimumSignificantDigits',
17
+ 'maximumSignificantDigits',
18
+ // ES2020 NumberFormat
19
+ 'compactDisplay',
20
+ 'currencyDisplay',
21
+ 'currencySign',
22
+ 'notation',
23
+ 'signDisplay',
24
+ 'unit',
25
+ 'unitDisplay',
26
+ 'numberingSystem',
27
+ ];
28
+ function getFormatter(_a, getNumberFormat, options) {
29
+ var locale = _a.locale, formats = _a.formats, onError = _a.onError;
30
+ if (options === void 0) { options = {}; }
31
+ var format = options.format;
32
+ var defaults = ((format &&
33
+ (0, utils_1.getNamedFormat)(formats, 'number', format, onError)) ||
34
+ {});
35
+ var filteredOptions = (0, utils_1.filterProps)(options, NUMBER_FORMAT_OPTIONS, defaults);
36
+ return getNumberFormat(locale, filteredOptions);
37
+ }
38
+ exports.getFormatter = getFormatter;
39
+ function formatNumber(config, getNumberFormat, value, options) {
40
+ if (options === void 0) { options = {}; }
41
+ try {
42
+ return getFormatter(config, getNumberFormat, options).format(value);
43
+ }
44
+ catch (e) {
45
+ config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting number.', e));
46
+ }
47
+ return String(value);
48
+ }
49
+ exports.formatNumber = formatNumber;
50
+ function formatNumberToParts(config, getNumberFormat, value, options) {
51
+ if (options === void 0) { options = {}; }
52
+ try {
53
+ return getFormatter(config, getNumberFormat, options).formatToParts(value);
54
+ }
55
+ catch (e) {
56
+ config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting number.', e));
57
+ }
58
+ return [];
59
+ }
60
+ exports.formatNumberToParts = formatNumberToParts;
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["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/src/plural.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatPlural = void 0;
4
+ var utils_1 = require("./utils");
5
+ var error_1 = require("./error");
6
+ var intl_messageformat_1 = require("intl-messageformat");
7
+ var PLURAL_FORMAT_OPTIONS = ['type'];
8
+ function formatPlural(_a, getPluralRules, value, options) {
9
+ var locale = _a.locale, onError = _a.onError;
10
+ if (options === void 0) { options = {}; }
11
+ if (!Intl.PluralRules) {
12
+ onError(new intl_messageformat_1.FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", intl_messageformat_1.ErrorCode.MISSING_INTL_API));
13
+ }
14
+ var filteredOptions = (0, utils_1.filterProps)(options, PLURAL_FORMAT_OPTIONS);
15
+ try {
16
+ return getPluralRules(locale, filteredOptions).select(value);
17
+ }
18
+ catch (e) {
19
+ onError(new error_1.IntlFormatError('Error formatting plural.', locale, e));
20
+ }
21
+ return 'other';
22
+ }
23
+ exports.formatPlural = formatPlural;
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relativeTime.d.ts","sourceRoot":"","sources":["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"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatRelativeTime = void 0;
4
+ var utils_1 = require("./utils");
5
+ var intl_messageformat_1 = require("intl-messageformat");
6
+ var error_1 = require("./error");
7
+ var RELATIVE_TIME_FORMAT_OPTIONS = ['numeric', 'style'];
8
+ function getFormatter(_a, getRelativeTimeFormat, options) {
9
+ var locale = _a.locale, formats = _a.formats, onError = _a.onError;
10
+ if (options === void 0) { options = {}; }
11
+ var format = options.format;
12
+ var defaults = (!!format && (0, utils_1.getNamedFormat)(formats, 'relative', format, onError)) || {};
13
+ var filteredOptions = (0, utils_1.filterProps)(options, RELATIVE_TIME_FORMAT_OPTIONS, defaults);
14
+ return getRelativeTimeFormat(locale, filteredOptions);
15
+ }
16
+ function formatRelativeTime(config, getRelativeTimeFormat, value, unit, options) {
17
+ if (options === void 0) { options = {}; }
18
+ if (!unit) {
19
+ unit = 'second';
20
+ }
21
+ var RelativeTimeFormat = Intl.RelativeTimeFormat;
22
+ if (!RelativeTimeFormat) {
23
+ config.onError(new intl_messageformat_1.FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n", intl_messageformat_1.ErrorCode.MISSING_INTL_API));
24
+ }
25
+ try {
26
+ return getFormatter(config, getRelativeTimeFormat, options).format(value, unit);
27
+ }
28
+ catch (e) {
29
+ config.onError(new error_1.IntlFormatError('Error formatting relative time.', config.locale, e));
30
+ }
31
+ return String(value);
32
+ }
33
+ exports.formatRelativeTime = formatRelativeTime;
package/src/types.d.ts ADDED
@@ -0,0 +1,103 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["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,EA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B,UAAU,EAAE,UAAU,CAAA;CACvB;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACxC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;IACzC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA;IAC1C,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAA;IACrD,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IAC7C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACpC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;CAC3C;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,CAAC,EAAE,UAAU,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;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/src/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/src/utils.d.ts ADDED
@@ -0,0 +1,12 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["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/src/utils.js ADDED
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNamedFormat = exports.createFormatters = exports.createIntlCache = exports.DEFAULT_INTL_CONFIG = exports.filterProps = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var intl_messageformat_1 = require("intl-messageformat");
6
+ var fast_memoize_1 = tslib_1.__importStar(require("@formatjs/fast-memoize"));
7
+ var error_1 = require("./error");
8
+ function filterProps(props, allowlist, defaults) {
9
+ if (defaults === void 0) { defaults = {}; }
10
+ return allowlist.reduce(function (filtered, name) {
11
+ if (name in props) {
12
+ filtered[name] = props[name];
13
+ }
14
+ else if (name in defaults) {
15
+ filtered[name] = defaults[name];
16
+ }
17
+ return filtered;
18
+ }, {});
19
+ }
20
+ exports.filterProps = filterProps;
21
+ var defaultErrorHandler = function (error) {
22
+ // @ts-ignore just so we don't need to declare dep on @types/node
23
+ if (process.env.NODE_ENV !== 'production') {
24
+ console.error(error);
25
+ }
26
+ };
27
+ var defaultWarnHandler = function (warning) {
28
+ // @ts-ignore just so we don't need to declare dep on @types/node
29
+ if (process.env.NODE_ENV !== 'production') {
30
+ console.warn(warning);
31
+ }
32
+ };
33
+ exports.DEFAULT_INTL_CONFIG = {
34
+ formats: {},
35
+ messages: {},
36
+ timeZone: undefined,
37
+ defaultLocale: 'en',
38
+ defaultFormats: {},
39
+ fallbackOnEmptyString: true,
40
+ onError: defaultErrorHandler,
41
+ onWarn: defaultWarnHandler,
42
+ };
43
+ function createIntlCache() {
44
+ return {
45
+ dateTime: {},
46
+ number: {},
47
+ message: {},
48
+ relativeTime: {},
49
+ pluralRules: {},
50
+ list: {},
51
+ displayNames: {},
52
+ };
53
+ }
54
+ exports.createIntlCache = createIntlCache;
55
+ function createFastMemoizeCache(store) {
56
+ return {
57
+ create: function () {
58
+ return {
59
+ get: function (key) {
60
+ return store[key];
61
+ },
62
+ set: function (key, value) {
63
+ store[key] = value;
64
+ },
65
+ };
66
+ },
67
+ };
68
+ }
69
+ /**
70
+ * Create intl formatters and populate cache
71
+ * @param cache explicit cache to prevent leaking memory
72
+ */
73
+ function createFormatters(cache) {
74
+ if (cache === void 0) { cache = createIntlCache(); }
75
+ var RelativeTimeFormat = Intl.RelativeTimeFormat;
76
+ var ListFormat = Intl.ListFormat;
77
+ var DisplayNames = Intl.DisplayNames;
78
+ var getDateTimeFormat = (0, fast_memoize_1.default)(function () {
79
+ var _a;
80
+ var args = [];
81
+ for (var _i = 0; _i < arguments.length; _i++) {
82
+ args[_i] = arguments[_i];
83
+ }
84
+ return new ((_a = Intl.DateTimeFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
85
+ }, {
86
+ cache: createFastMemoizeCache(cache.dateTime),
87
+ strategy: fast_memoize_1.strategies.variadic,
88
+ });
89
+ var getNumberFormat = (0, fast_memoize_1.default)(function () {
90
+ var _a;
91
+ var args = [];
92
+ for (var _i = 0; _i < arguments.length; _i++) {
93
+ args[_i] = arguments[_i];
94
+ }
95
+ return new ((_a = Intl.NumberFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
96
+ }, {
97
+ cache: createFastMemoizeCache(cache.number),
98
+ strategy: fast_memoize_1.strategies.variadic,
99
+ });
100
+ var getPluralRules = (0, fast_memoize_1.default)(function () {
101
+ var _a;
102
+ var args = [];
103
+ for (var _i = 0; _i < arguments.length; _i++) {
104
+ args[_i] = arguments[_i];
105
+ }
106
+ return new ((_a = Intl.PluralRules).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
107
+ }, {
108
+ cache: createFastMemoizeCache(cache.pluralRules),
109
+ strategy: fast_memoize_1.strategies.variadic,
110
+ });
111
+ return {
112
+ getDateTimeFormat: getDateTimeFormat,
113
+ getNumberFormat: getNumberFormat,
114
+ getMessageFormat: (0, fast_memoize_1.default)(function (message, locales, overrideFormats, opts) {
115
+ return new intl_messageformat_1.IntlMessageFormat(message, locales, overrideFormats, tslib_1.__assign({ formatters: {
116
+ getNumberFormat: getNumberFormat,
117
+ getDateTimeFormat: getDateTimeFormat,
118
+ getPluralRules: getPluralRules,
119
+ } }, (opts || {})));
120
+ }, {
121
+ cache: createFastMemoizeCache(cache.message),
122
+ strategy: fast_memoize_1.strategies.variadic,
123
+ }),
124
+ getRelativeTimeFormat: (0, fast_memoize_1.default)(function () {
125
+ var args = [];
126
+ for (var _i = 0; _i < arguments.length; _i++) {
127
+ args[_i] = arguments[_i];
128
+ }
129
+ return new (RelativeTimeFormat.bind.apply(RelativeTimeFormat, tslib_1.__spreadArray([void 0], args, false)))();
130
+ }, {
131
+ cache: createFastMemoizeCache(cache.relativeTime),
132
+ strategy: fast_memoize_1.strategies.variadic,
133
+ }),
134
+ getPluralRules: getPluralRules,
135
+ getListFormat: (0, fast_memoize_1.default)(function () {
136
+ var args = [];
137
+ for (var _i = 0; _i < arguments.length; _i++) {
138
+ args[_i] = arguments[_i];
139
+ }
140
+ return new (ListFormat.bind.apply(ListFormat, tslib_1.__spreadArray([void 0], args, false)))();
141
+ }, {
142
+ cache: createFastMemoizeCache(cache.list),
143
+ strategy: fast_memoize_1.strategies.variadic,
144
+ }),
145
+ getDisplayNames: (0, fast_memoize_1.default)(function () {
146
+ var args = [];
147
+ for (var _i = 0; _i < arguments.length; _i++) {
148
+ args[_i] = arguments[_i];
149
+ }
150
+ return new (DisplayNames.bind.apply(DisplayNames, tslib_1.__spreadArray([void 0], args, false)))();
151
+ }, {
152
+ cache: createFastMemoizeCache(cache.displayNames),
153
+ strategy: fast_memoize_1.strategies.variadic,
154
+ }),
155
+ };
156
+ }
157
+ exports.createFormatters = createFormatters;
158
+ function getNamedFormat(formats, type, name, onError) {
159
+ var formatType = formats && formats[type];
160
+ var format;
161
+ if (formatType) {
162
+ format = formatType[name];
163
+ }
164
+ if (format) {
165
+ return format;
166
+ }
167
+ onError(new error_1.UnsupportedFormatterError("No ".concat(type, " format named: ").concat(name)));
168
+ }
169
+ exports.getNamedFormat = getNamedFormat;
package/BUILD DELETED
@@ -1,79 +0,0 @@
1
- load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
2
- load("@aspect_rules_js//npm/private:npm_package.bzl", "npm_package")
3
- load("@npm//:defs.bzl", "npm_link_all_packages")
4
- load("//tools:index.bzl", "check_format", "package_json_test", "ts_compile")
5
- load("//tools:jest.bzl", "jest_test")
6
-
7
- npm_link_all_packages(name = "node_modules")
8
-
9
- PACKAGE_NAME = "intl"
10
-
11
- npm_package(
12
- name = PACKAGE_NAME,
13
- srcs = [
14
- "LICENSE.md",
15
- "README.md",
16
- "package.json",
17
- ":dist",
18
- ":dist-esm",
19
- ],
20
- package = "@formatjs/%s" % PACKAGE_NAME,
21
- visibility = ["//visibility:public"],
22
- )
23
-
24
- SRCS = glob(["src/**/*.ts*"]) + ["index.ts"]
25
-
26
- SRC_DEPS = [
27
- ":node_modules/@formatjs/ecma402-abstract",
28
- ":node_modules/@formatjs/fast-memoize",
29
- ":node_modules/@formatjs/icu-messageformat-parser",
30
- ":node_modules/@formatjs/intl-displaynames",
31
- ":node_modules/@formatjs/intl-listformat",
32
- ":node_modules/intl-messageformat",
33
- ]
34
-
35
- TESTS = glob([
36
- "tests/*.ts*",
37
- "tests/__snapshots__/*.snap",
38
- ])
39
-
40
- ts_compile(
41
- name = "dist",
42
- srcs = SRCS,
43
- package = "@formatjs/%s" % PACKAGE_NAME,
44
- skip_esm = False,
45
- deps = SRC_DEPS,
46
- )
47
-
48
- jest_test(
49
- name = "unit",
50
- srcs = SRCS + TESTS,
51
- deps = SRC_DEPS + [
52
- ":node_modules/@formatjs/intl-datetimeformat",
53
- ":node_modules/@formatjs/intl-numberformat",
54
- "//:node_modules/@types/node",
55
- ],
56
- )
57
-
58
- write_source_files(
59
- name = "tsconfig_json",
60
- files = {"tsconfig.json": "//tools:tsconfig.golden.json"},
61
- )
62
-
63
- check_format(
64
- name = "prettier",
65
- srcs = glob(
66
- [
67
- "**/*",
68
- ],
69
- exclude = [
70
- "CHANGELOG.md",
71
- "tests/__snapshots__/*",
72
- ],
73
- ),
74
- )
75
-
76
- package_json_test(
77
- name = "package_json_test",
78
- deps = SRC_DEPS,
79
- )