@formatjs/intl 2.2.5 → 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.
- package/BUILD +79 -0
- package/CHANGELOG.md +537 -0
- package/LICENSE.md +0 -0
- package/README.md +0 -0
- package/index.ts +38 -0
- package/package.json +12 -8
- package/src/create-intl.ts +159 -0
- package/src/dateTime.ts +204 -0
- package/src/displayName.ts +54 -0
- package/src/error.ts +106 -0
- package/src/list.ts +119 -0
- package/src/message.ts +246 -0
- package/src/number.ts +101 -0
- package/src/plural.ts +45 -0
- package/src/relativeTime.ts +74 -0
- package/src/types.ts +234 -0
- package/src/utils.ts +177 -0
- package/tests/__snapshots__/formatDate.test.ts.snap +13 -0
- package/tests/__snapshots__/formatMessage.test.ts.snap +45 -0
- package/tests/__snapshots__/formatNumber.test.ts.snap +13 -0
- package/tests/__snapshots__/formatRelativeTime.test.ts.snap +19 -0
- package/tests/__snapshots__/formatTime.test.ts.snap +13 -0
- package/tests/create-intl.test.ts +60 -0
- package/tests/error.test.ts +25 -0
- package/tests/formatDate.test.ts +167 -0
- package/tests/formatDisplayNames.test.ts +63 -0
- package/tests/formatList.test.ts +51 -0
- package/tests/formatMessage.test.ts +495 -0
- package/tests/formatNumber.test.ts +172 -0
- package/tests/formatPlural.test.ts +119 -0
- package/tests/formatRelativeTime.test.ts +145 -0
- package/tests/formatTime.test.ts +234 -0
- package/tests/global.d.ts +7 -0
- package/tsconfig.json +5 -0
- package/index.d.ts +0 -17
- package/index.d.ts.map +0 -1
- package/index.js +0 -40
- package/lib/index.d.ts +0 -17
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -17
- package/lib/src/create-intl.d.ts +0 -11
- package/lib/src/create-intl.d.ts.map +0 -1
- package/lib/src/create-intl.js +0 -51
- package/lib/src/dateTime.d.ts +0 -38
- package/lib/src/dateTime.d.ts.map +0 -1
- package/lib/src/dateTime.js +0 -117
- package/lib/src/displayName.d.ts +0 -6
- package/lib/src/displayName.d.ts.map +0 -1
- package/lib/src/displayName.js +0 -22
- package/lib/src/error.d.ts +0 -34
- package/lib/src/error.d.ts.map +0 -1
- package/lib/src/error.js +0 -88
- package/lib/src/list.d.ts +0 -11
- package/lib/src/list.d.ts.map +0 -1
- package/lib/src/list.js +0 -61
- package/lib/src/message.d.ts +0 -16
- package/lib/src/message.d.ts.map +0 -1
- package/lib/src/message.js +0 -103
- package/lib/src/number.d.ts +0 -17
- package/lib/src/number.d.ts.map +0 -1
- package/lib/src/number.js +0 -54
- package/lib/src/plural.d.ts +0 -7
- package/lib/src/plural.d.ts.map +0 -1
- package/lib/src/plural.js +0 -19
- package/lib/src/relativeTime.d.ts +0 -7
- package/lib/src/relativeTime.d.ts.map +0 -1
- package/lib/src/relativeTime.js +0 -29
- package/lib/src/types.d.ts +0 -101
- package/lib/src/types.d.ts.map +0 -1
- package/lib/src/types.js +0 -1
- package/lib/src/utils.d.ts +0 -12
- package/lib/src/utils.d.ts.map +0 -1
- package/lib/src/utils.js +0 -162
- package/src/create-intl.d.ts +0 -11
- package/src/create-intl.d.ts.map +0 -1
- package/src/create-intl.js +0 -55
- package/src/dateTime.d.ts +0 -38
- package/src/dateTime.d.ts.map +0 -1
- package/src/dateTime.js +0 -126
- package/src/displayName.d.ts +0 -6
- package/src/displayName.d.ts.map +0 -1
- package/src/displayName.js +0 -26
- package/src/error.d.ts +0 -34
- package/src/error.d.ts.map +0 -1
- package/src/error.js +0 -91
- package/src/list.d.ts +0 -11
- package/src/list.d.ts.map +0 -1
- package/src/list.js +0 -66
- package/src/message.d.ts +0 -16
- package/src/message.d.ts.map +0 -1
- package/src/message.js +0 -107
- package/src/number.d.ts +0 -17
- package/src/number.d.ts.map +0 -1
- package/src/number.js +0 -60
- package/src/plural.d.ts +0 -7
- package/src/plural.d.ts.map +0 -1
- package/src/plural.js +0 -23
- package/src/relativeTime.d.ts +0 -7
- package/src/relativeTime.d.ts.map +0 -1
- package/src/relativeTime.js +0 -33
- package/src/types.d.ts +0 -101
- package/src/types.d.ts.map +0 -1
- package/src/types.js +0 -2
- package/src/utils.d.ts +0 -12
- package/src/utils.d.ts.map +0 -1
- package/src/utils.js +0 -169
package/src/relativeTime.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,101 +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
|
-
}
|
|
16
|
-
}
|
|
17
|
-
declare type MessageIds = FormatjsIntl.Message extends {
|
|
18
|
-
ids: string;
|
|
19
|
-
} ? FormatjsIntl.Message['ids'] : string;
|
|
20
|
-
declare type Locale = FormatjsIntl.IntlConfig extends {
|
|
21
|
-
locale: string;
|
|
22
|
-
} ? FormatjsIntl.IntlConfig['locale'] : string;
|
|
23
|
-
export declare type OnErrorFn = (err: MissingTranslationError | MessageFormatError | MissingDataError | InvalidConfigError | UnsupportedFormatterError | FormatError) => void;
|
|
24
|
-
export declare type OnWarnFn = (warning: string) => void;
|
|
25
|
-
/**
|
|
26
|
-
* Config for intl object.
|
|
27
|
-
* Generic type T is the type of potential rich text element. For example:
|
|
28
|
-
* With React, T would be React.ReactNode
|
|
29
|
-
*/
|
|
30
|
-
export interface ResolvedIntlConfig<T = string> {
|
|
31
|
-
locale: Locale;
|
|
32
|
-
timeZone?: string;
|
|
33
|
-
fallbackOnEmptyString?: boolean;
|
|
34
|
-
formats: CustomFormats;
|
|
35
|
-
messages: Record<MessageIds, string> | Record<MessageIds, MessageFormatElement[]>;
|
|
36
|
-
defaultLocale: string;
|
|
37
|
-
defaultFormats: CustomFormats;
|
|
38
|
-
defaultRichTextElements?: Record<string, FormatXMLElementFn<T>>;
|
|
39
|
-
onError: OnErrorFn;
|
|
40
|
-
onWarn?: OnWarnFn;
|
|
41
|
-
}
|
|
42
|
-
export interface CustomFormats extends Partial<Formats> {
|
|
43
|
-
relative?: Record<string, Intl.RelativeTimeFormatOptions>;
|
|
44
|
-
}
|
|
45
|
-
export interface CustomFormatConfig {
|
|
46
|
-
format?: string;
|
|
47
|
-
}
|
|
48
|
-
export declare type FormatDateOptions = Omit<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
|
|
49
|
-
export declare type FormatNumberOptions = Omit<NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig;
|
|
50
|
-
export declare type FormatRelativeTimeOptions = Omit<Intl.RelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
|
|
51
|
-
export declare type FormatPluralOptions = Omit<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;
|
|
52
|
-
export declare type FormatListOptions = Omit<IntlListFormatOptions, 'localeMatcher'>;
|
|
53
|
-
export declare type FormatDisplayNameOptions = Omit<DisplayNamesOptions, 'localeMatcher'>;
|
|
54
|
-
export interface IntlFormatters<T = any, R = T> {
|
|
55
|
-
formatDateTimeRange(from: Parameters<DateTimeFormat['formatRange']>[0], to: Parameters<DateTimeFormat['formatRange']>[1], opts?: FormatDateOptions): string;
|
|
56
|
-
formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
57
|
-
formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
58
|
-
formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
|
|
59
|
-
formatTimeToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
|
|
60
|
-
formatRelativeTime(value: Parameters<Intl.RelativeTimeFormat['format']>[0], unit?: Parameters<Intl.RelativeTimeFormat['format']>[1], opts?: FormatRelativeTimeOptions): string;
|
|
61
|
-
formatNumber(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): string;
|
|
62
|
-
formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
|
|
63
|
-
formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
|
|
64
|
-
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string;
|
|
65
|
-
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T, R>>, opts?: IntlMessageFormatOptions): R;
|
|
66
|
-
$t(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string;
|
|
67
|
-
$t(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T, R>>, opts?: IntlMessageFormatOptions): R;
|
|
68
|
-
formatList(values: ReadonlyArray<string>, opts?: FormatListOptions): string;
|
|
69
|
-
formatList(values: ReadonlyArray<string | T>, opts?: FormatListOptions): T | string | Array<string | T>;
|
|
70
|
-
formatListToParts(values: ReadonlyArray<string | T>, opts?: FormatListOptions): Part[];
|
|
71
|
-
formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts: FormatDisplayNameOptions): string | undefined;
|
|
72
|
-
}
|
|
73
|
-
export interface Formatters {
|
|
74
|
-
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): DateTimeFormat;
|
|
75
|
-
getNumberFormat(locales?: string | string[], opts?: NumberFormatOptions): Intl.NumberFormat;
|
|
76
|
-
getMessageFormat(...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
|
|
77
|
-
getRelativeTimeFormat(...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
|
|
78
|
-
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
|
|
79
|
-
getListFormat(...args: ConstructorParameters<typeof IntlListFormat>): IntlListFormat;
|
|
80
|
-
getDisplayNames(...args: ConstructorParameters<typeof DisplayNames>): DisplayNames;
|
|
81
|
-
}
|
|
82
|
-
export interface IntlShape<T = string> extends ResolvedIntlConfig<T>, IntlFormatters {
|
|
83
|
-
formatters: Formatters;
|
|
84
|
-
}
|
|
85
|
-
export interface IntlCache {
|
|
86
|
-
dateTime: Record<string, DateTimeFormat>;
|
|
87
|
-
number: Record<string, Intl.NumberFormat>;
|
|
88
|
-
message: Record<string, IntlMessageFormat>;
|
|
89
|
-
relativeTime: Record<string, Intl.RelativeTimeFormat>;
|
|
90
|
-
pluralRules: Record<string, Intl.PluralRules>;
|
|
91
|
-
list: Record<string, IntlListFormat>;
|
|
92
|
-
displayNames: Record<string, DisplayNames>;
|
|
93
|
-
}
|
|
94
|
-
export interface MessageDescriptor {
|
|
95
|
-
id?: MessageIds;
|
|
96
|
-
description?: string | object;
|
|
97
|
-
defaultMessage?: string | MessageFormatElement[];
|
|
98
|
-
}
|
|
99
|
-
export declare type IntlConfig<T = string> = Omit<ResolvedIntlConfig<T>, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
|
|
100
|
-
export {};
|
|
101
|
-
//# sourceMappingURL=types.d.ts.map
|
package/src/types.d.ts.map
DELETED
|
@@ -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;KACxB;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,K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AAM,OAAO,mBAAmB,CACjC,GACC,OAAO,CAAC,OAAO,mBAAmB,CAAC,CAAA"}
|
package/src/types.js
DELETED
package/src/utils.d.ts
DELETED
|
@@ -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
|
package/src/utils.d.ts.map
DELETED
|
@@ -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/src/utils.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
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 = (0, 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, (0, 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, (0, 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, (0, 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, (0, 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, (0, 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, (0, 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, (0, 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;
|