@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/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
|
-
}
|
package/lib/src/plural.d.ts
DELETED
|
@@ -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
|
package/lib/src/plural.d.ts.map
DELETED
|
@@ -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"}
|
package/lib/src/relativeTime.js
DELETED
|
@@ -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
|
-
}
|
package/lib/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/lib/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,G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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/lib/src/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/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/lib/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/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
|
-
}
|
package/src/create-intl.d.ts
DELETED
|
@@ -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
|
package/src/create-intl.d.ts.map
DELETED
|
@@ -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"}
|
package/src/create-intl.js
DELETED
|
@@ -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
|
package/src/dateTime.d.ts.map
DELETED
|
@@ -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,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,iBAAiB,EAAE,UAAU,CAAC,mBAAmB,CAAC,EAClD,OAAO,GAAE,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAM,GACxD,cAAc,CA0BhB;AAED,wBAAgB,UAAU,CACxB,MAAM,EAAE;IACN,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,iBAAiB,EAAE,UAAU,CAAC,mBAAmB,CAAC,EAClD,GAAG,CAAC,KAAK,EAAE,OAAY,CAAC,EAAE,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,GACjE,MAAM,CAWR;AAED,wBAAgB,UAAU,CACxB,MAAM,EAAE;IACN,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,iBAAiB,EAAE,UAAU,CAAC,mBAAmB,CAAC,EAClD,GAAG,CAAC,KAAK,EAAE,O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