@formatjs/intl 3.0.0 → 3.0.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.
@@ -47,9 +47,5 @@ export function createIntl(config, cache) {
47
47
  onError(new MissingDataError("Missing locale data for locale: \"".concat(locale, "\" in Intl.DateTimeFormat. Using default locale: \"").concat(defaultLocale, "\" as fallback. See https://formatjs.github.io/docs/react-intl#runtime-requirements for more details")));
48
48
  }
49
49
  verifyConfigMessages(resolvedConfig);
50
- return __assign(__assign({}, resolvedConfig), { formatters: formatters, formatNumber: formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateTimeRange: formatDateTimeRange.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: formatPlural.bind(null, resolvedConfig, formatters.getPluralRules),
51
- // @ts-expect-error TODO: will get to this later
52
- formatMessage: formatMessage.bind(null, resolvedConfig, formatters),
53
- // @ts-expect-error TODO: will get to this later
54
- $t: formatMessage.bind(null, resolvedConfig, formatters), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat), formatListToParts: formatListToParts.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
50
+ return __assign(__assign({}, resolvedConfig), { formatters: formatters, formatNumber: formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateTimeRange: formatDateTimeRange.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: formatMessage.bind(null, resolvedConfig, formatters), $t: formatMessage.bind(null, resolvedConfig, formatters), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat), formatListToParts: formatListToParts.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
55
51
  }
@@ -1,11 +1,10 @@
1
- import { Formatters, IntlFormatters, CustomFormats, OnErrorFn } from './types';
2
- import { DateTimeFormat } from '@formatjs/ecma402-abstract';
1
+ import { CustomFormats, Formatters, IntlFormatters, OnErrorFn } from './types';
3
2
  export declare function getFormatter({ locale, formats, onError, timeZone, }: {
4
3
  locale: string;
5
4
  timeZone?: string;
6
5
  formats: CustomFormats;
7
6
  onError: OnErrorFn;
8
- }, type: 'date' | 'time', getDateTimeFormat: Formatters['getDateTimeFormat'], options?: Parameters<IntlFormatters['formatDate']>[1]): DateTimeFormat;
7
+ }, type: 'date' | 'time', getDateTimeFormat: Formatters['getDateTimeFormat'], options?: Parameters<IntlFormatters['formatDate']>[1]): Intl.DateTimeFormat;
9
8
  export declare function formatDate(config: {
10
9
  locale: string;
11
10
  timeZone?: string;
@@ -1,6 +1,6 @@
1
1
  import { __assign } from "tslib";
2
- import { filterProps, getNamedFormat } from './utils';
3
2
  import { IntlFormatError } from './error';
3
+ import { filterProps, getNamedFormat } from './utils';
4
4
  var DATE_TIME_FORMAT_OPTIONS = [
5
5
  'formatMatcher',
6
6
  'timeZone',
@@ -1,8 +1,8 @@
1
1
  import { __assign } from "tslib";
2
- import { invariant } from '@formatjs/ecma402-abstract';
3
2
  import { TYPE } from '@formatjs/icu-messageformat-parser';
4
3
  import { IntlMessageFormat, } from 'intl-messageformat';
5
4
  import { MessageFormatError, MissingTranslationError } from './error';
5
+ import { invariant } from './utils';
6
6
  function setTimeZoneInOptions(opts, timeZone) {
7
7
  return Object.keys(opts).reduce(function (all, k) {
8
8
  all[k] = __assign({ timeZone: timeZone }, opts[k]);
package/lib/src/number.js CHANGED
@@ -21,9 +21,13 @@ var NUMBER_FORMAT_OPTIONS = [
21
21
  'unitDisplay',
22
22
  'numberingSystem',
23
23
  // ES2023 NumberFormat
24
+ // @ts-expect-error: TypeScript doesn't know about this yet
24
25
  'trailingZeroDisplay',
26
+ // @ts-expect-error: TypeScript doesn't know about this yet
25
27
  'roundingPriority',
28
+ // @ts-expect-error: TypeScript doesn't know about this yet
26
29
  'roundingIncrement',
30
+ // @ts-expect-error: TypeScript doesn't know about this yet
27
31
  'roundingMode',
28
32
  ];
29
33
  export function getFormatter(_a, getNumberFormat, options) {
@@ -1,6 +1,5 @@
1
1
  import { Formatters, IntlFormatters, OnErrorFn } from './types';
2
- import { LDMLPluralRule } from '@formatjs/ecma402-abstract';
3
2
  export declare function formatPlural({ locale, onError, }: {
4
3
  locale: string;
5
4
  onError: OnErrorFn;
6
- }, getPluralRules: Formatters['getPluralRules'], value: Parameters<IntlFormatters['formatPlural']>[0], options?: Parameters<IntlFormatters['formatPlural']>[1]): LDMLPluralRule;
5
+ }, getPluralRules: Formatters['getPluralRules'], value: Parameters<IntlFormatters['formatPlural']>[0], options?: Parameters<IntlFormatters['formatPlural']>[1]): Intl.LDMLPluralRule;
package/lib/src/plural.js CHANGED
@@ -1,6 +1,6 @@
1
- import { filterProps } from './utils';
2
- import { IntlFormatError } from './error';
3
1
  import { ErrorCode, FormatError } from 'intl-messageformat';
2
+ import { IntlFormatError } from './error';
3
+ import { filterProps } from './utils';
4
4
  var PLURAL_FORMAT_OPTIONS = ['type'];
5
5
  export function formatPlural(_a, getPluralRules, value, options) {
6
6
  var locale = _a.locale, onError = _a.onError;
@@ -1,4 +1,3 @@
1
- import { DateTimeFormat, NumberFormatOptions } from '@formatjs/ecma402-abstract';
2
1
  import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
3
2
  import { FormatError, Formats, FormatXMLElementFn, IntlMessageFormat, Options as IntlMessageFormatOptions, PrimitiveType } from 'intl-messageformat';
4
3
  import { InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, UnsupportedFormatterError } from './error';
@@ -49,7 +48,7 @@ export interface CustomFormatConfig<Source = string> {
49
48
  format?: Source extends keyof FormatjsIntl.Formats ? FormatjsIntl.Formats[Source] : string;
50
49
  }
51
50
  export type FormatDateOptions = Omit<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'date'>;
52
- export type FormatNumberOptions = Omit<NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig<'number'>;
51
+ export type FormatNumberOptions = Omit<Intl.NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig<'number'>;
53
52
  export type FormatRelativeTimeOptions = Omit<Intl.RelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'time'>;
54
53
  export type FormatPluralOptions = Omit<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;
55
54
  export type FormatListOptions = Omit<Intl.ListFormatOptions, 'localeMatcher'>;
@@ -59,7 +58,7 @@ export type FormatDisplayNameOptions = Omit<Intl.DisplayNamesOptions, 'localeMat
59
58
  * For example, with React, `TBase` should be `React.ReactNode`.
60
59
  */
61
60
  export interface IntlFormatters<TBase = unknown> {
62
- formatDateTimeRange(this: void, from: Parameters<DateTimeFormat['formatRange']>[0], to: Parameters<DateTimeFormat['formatRange']>[1], opts?: FormatDateOptions): string;
61
+ formatDateTimeRange(this: void, from: Parameters<Intl.DateTimeFormat['formatRange']>[0], to: Parameters<Intl.DateTimeFormat['formatRange']>[1], opts?: FormatDateOptions): string;
63
62
  formatDate(this: void, value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
64
63
  formatTime(this: void, value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
65
64
  formatDateToParts(this: void, value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
@@ -78,8 +77,8 @@ export interface IntlFormatters<TBase = unknown> {
78
77
  formatDisplayName(this: void, value: Parameters<Intl.DisplayNames['of']>[0], opts: FormatDisplayNameOptions): string | undefined;
79
78
  }
80
79
  export interface Formatters {
81
- getDateTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.DateTimeFormat>): DateTimeFormat;
82
- getNumberFormat(this: void, locales?: string | string[], opts?: NumberFormatOptions): Intl.NumberFormat;
80
+ getDateTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
81
+ getNumberFormat(this: void, locales?: string | string[], opts?: Intl.NumberFormatOptions): Intl.NumberFormat;
83
82
  getMessageFormat(this: void, ...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
84
83
  getRelativeTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
85
84
  getPluralRules(this: void, ...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
@@ -90,7 +89,7 @@ export interface IntlShape<T = string> extends ResolvedIntlConfig<T>, IntlFormat
90
89
  formatters: Formatters;
91
90
  }
92
91
  export interface IntlCache {
93
- dateTime: Record<string, DateTimeFormat>;
92
+ dateTime: Record<string, Intl.DateTimeFormat>;
94
93
  number: Record<string, Intl.NumberFormat>;
95
94
  message: Record<string, IntlMessageFormat>;
96
95
  relativeTime: Record<string, Intl.RelativeTimeFormat>;
@@ -1,5 +1,5 @@
1
- import { IntlCache, CustomFormats, Formatters, OnErrorFn, ResolvedIntlConfig } from './types';
2
- import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
1
+ import { CustomFormats, Formatters, IntlCache, OnErrorFn, ResolvedIntlConfig } from './types';
2
+ export declare function invariant(condition: boolean, message: string, Err?: any): asserts condition;
3
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
4
  export declare const DEFAULT_INTL_CONFIG: Pick<ResolvedIntlConfig<any>, 'fallbackOnEmptyString' | 'formats' | 'messages' | 'timeZone' | 'defaultLocale' | 'defaultFormats' | 'onError' | 'onWarn'>;
5
5
  export declare function createIntlCache(): IntlCache;
@@ -8,4 +8,4 @@ export declare function createIntlCache(): IntlCache;
8
8
  * @param cache explicit cache to prevent leaking memory
9
9
  */
10
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;
11
+ export declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: OnErrorFn): Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | Intl.RelativeTimeFormatOptions | undefined;
package/lib/src/utils.js CHANGED
@@ -1,7 +1,13 @@
1
1
  import { __assign, __spreadArray } from "tslib";
2
- import { IntlMessageFormat } from 'intl-messageformat';
3
2
  import { memoize, strategies } from '@formatjs/fast-memoize';
3
+ import { IntlMessageFormat } from 'intl-messageformat';
4
4
  import { UnsupportedFormatterError } from './error';
5
+ export function invariant(condition, message, Err) {
6
+ if (Err === void 0) { Err = Error; }
7
+ if (!condition) {
8
+ throw new Err(message);
9
+ }
10
+ }
5
11
  export function filterProps(props, allowlist, defaults) {
6
12
  if (defaults === void 0) { defaults = {}; }
7
13
  return allowlist.reduce(function (filtered, name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Internationalize JS apps. This library provides an API to format dates, numbers, and strings, including pluralization and handling translations.",
5
5
  "keywords": [
6
6
  "intl",
@@ -30,10 +30,9 @@
30
30
  "sideEffects": false,
31
31
  "dependencies": {
32
32
  "tslib": "2",
33
- "@formatjs/ecma402-abstract": "2.2.4",
34
- "@formatjs/fast-memoize": "2.2.3",
35
33
  "intl-messageformat": "10.7.7",
36
- "@formatjs/icu-messageformat-parser": "2.9.4"
34
+ "@formatjs/icu-messageformat-parser": "2.9.4",
35
+ "@formatjs/fast-memoize": "2.2.3"
37
36
  },
38
37
  "peerDependencies": {
39
38
  "typescript": "5"
@@ -50,9 +50,5 @@ function createIntl(config, cache) {
50
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.github.io/docs/react-intl#runtime-requirements for more details")));
51
51
  }
52
52
  verifyConfigMessages(resolvedConfig);
53
- return tslib_1.__assign(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),
54
- // @ts-expect-error TODO: will get to this later
55
- formatMessage: message_1.formatMessage.bind(null, resolvedConfig, formatters),
56
- // @ts-expect-error TODO: will get to this later
57
- $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) });
53
+ return tslib_1.__assign(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) });
58
54
  }
package/src/dateTime.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- import { Formatters, IntlFormatters, CustomFormats, OnErrorFn } from './types';
2
- import { DateTimeFormat } from '@formatjs/ecma402-abstract';
1
+ import { CustomFormats, Formatters, IntlFormatters, OnErrorFn } from './types';
3
2
  export declare function getFormatter({ locale, formats, onError, timeZone, }: {
4
3
  locale: string;
5
4
  timeZone?: string;
6
5
  formats: CustomFormats;
7
6
  onError: OnErrorFn;
8
- }, type: 'date' | 'time', getDateTimeFormat: Formatters['getDateTimeFormat'], options?: Parameters<IntlFormatters['formatDate']>[1]): DateTimeFormat;
7
+ }, type: 'date' | 'time', getDateTimeFormat: Formatters['getDateTimeFormat'], options?: Parameters<IntlFormatters['formatDate']>[1]): Intl.DateTimeFormat;
9
8
  export declare function formatDate(config: {
10
9
  locale: string;
11
10
  timeZone?: string;
package/src/dateTime.js CHANGED
@@ -7,8 +7,8 @@ exports.formatDateTimeRange = formatDateTimeRange;
7
7
  exports.formatDateToParts = formatDateToParts;
8
8
  exports.formatTimeToParts = formatTimeToParts;
9
9
  var tslib_1 = require("tslib");
10
- var utils_1 = require("./utils");
11
10
  var error_1 = require("./error");
11
+ var utils_1 = require("./utils");
12
12
  var DATE_TIME_FORMAT_OPTIONS = [
13
13
  'formatMatcher',
14
14
  'timeZone',
package/src/message.js CHANGED
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatMessage = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
6
5
  var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
7
6
  var intl_messageformat_1 = require("intl-messageformat");
8
7
  var error_1 = require("./error");
8
+ var utils_1 = require("./utils");
9
9
  function setTimeZoneInOptions(opts, timeZone) {
10
10
  return Object.keys(opts).reduce(function (all, k) {
11
11
  all[k] = tslib_1.__assign({ timeZone: timeZone }, opts[k]);
@@ -31,7 +31,7 @@ var formatMessage = function (_a, state, messageDescriptor, values, opts) {
31
31
  if (messageDescriptor === void 0) { messageDescriptor = { id: '' }; }
32
32
  var msgId = messageDescriptor.id, defaultMessage = messageDescriptor.defaultMessage;
33
33
  // `id` is a required field of a Message Descriptor.
34
- (0, ecma402_abstract_1.invariant)(!!msgId, "[@formatjs/intl] An `id` must be provided to format a message. You can either:\n1. Configure your build toolchain with [babel-plugin-formatjs](https://formatjs.github.io/docs/tooling/babel-plugin)\nor [@formatjs/ts-transformer](https://formatjs.github.io/docs/tooling/ts-transformer) OR\n2. Configure your `eslint` config to include [eslint-plugin-formatjs](https://formatjs.github.io/docs/tooling/linter#enforce-id)\nto autofix this issue");
34
+ (0, utils_1.invariant)(!!msgId, "[@formatjs/intl] An `id` must be provided to format a message. You can either:\n1. Configure your build toolchain with [babel-plugin-formatjs](https://formatjs.github.io/docs/tooling/babel-plugin)\nor [@formatjs/ts-transformer](https://formatjs.github.io/docs/tooling/ts-transformer) OR\n2. Configure your `eslint` config to include [eslint-plugin-formatjs](https://formatjs.github.io/docs/tooling/linter#enforce-id)\nto autofix this issue");
35
35
  var id = String(msgId);
36
36
  var message =
37
37
  // In case messages is Object.create(null)
package/src/number.js CHANGED
@@ -26,9 +26,13 @@ var NUMBER_FORMAT_OPTIONS = [
26
26
  'unitDisplay',
27
27
  'numberingSystem',
28
28
  // ES2023 NumberFormat
29
+ // @ts-expect-error: TypeScript doesn't know about this yet
29
30
  'trailingZeroDisplay',
31
+ // @ts-expect-error: TypeScript doesn't know about this yet
30
32
  'roundingPriority',
33
+ // @ts-expect-error: TypeScript doesn't know about this yet
31
34
  'roundingIncrement',
35
+ // @ts-expect-error: TypeScript doesn't know about this yet
32
36
  'roundingMode',
33
37
  ];
34
38
  function getFormatter(_a, getNumberFormat, options) {
package/src/plural.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Formatters, IntlFormatters, OnErrorFn } from './types';
2
- import { LDMLPluralRule } from '@formatjs/ecma402-abstract';
3
2
  export declare function formatPlural({ locale, onError, }: {
4
3
  locale: string;
5
4
  onError: OnErrorFn;
6
- }, getPluralRules: Formatters['getPluralRules'], value: Parameters<IntlFormatters['formatPlural']>[0], options?: Parameters<IntlFormatters['formatPlural']>[1]): LDMLPluralRule;
5
+ }, getPluralRules: Formatters['getPluralRules'], value: Parameters<IntlFormatters['formatPlural']>[0], options?: Parameters<IntlFormatters['formatPlural']>[1]): Intl.LDMLPluralRule;
package/src/plural.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatPlural = formatPlural;
4
- var utils_1 = require("./utils");
5
- var error_1 = require("./error");
6
4
  var intl_messageformat_1 = require("intl-messageformat");
5
+ var error_1 = require("./error");
6
+ var utils_1 = require("./utils");
7
7
  var PLURAL_FORMAT_OPTIONS = ['type'];
8
8
  function formatPlural(_a, getPluralRules, value, options) {
9
9
  var locale = _a.locale, onError = _a.onError;
package/src/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { DateTimeFormat, NumberFormatOptions } from '@formatjs/ecma402-abstract';
2
1
  import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
3
2
  import { FormatError, Formats, FormatXMLElementFn, IntlMessageFormat, Options as IntlMessageFormatOptions, PrimitiveType } from 'intl-messageformat';
4
3
  import { InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, UnsupportedFormatterError } from './error';
@@ -49,7 +48,7 @@ export interface CustomFormatConfig<Source = string> {
49
48
  format?: Source extends keyof FormatjsIntl.Formats ? FormatjsIntl.Formats[Source] : string;
50
49
  }
51
50
  export type FormatDateOptions = Omit<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'date'>;
52
- export type FormatNumberOptions = Omit<NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig<'number'>;
51
+ export type FormatNumberOptions = Omit<Intl.NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig<'number'>;
53
52
  export type FormatRelativeTimeOptions = Omit<Intl.RelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'time'>;
54
53
  export type FormatPluralOptions = Omit<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;
55
54
  export type FormatListOptions = Omit<Intl.ListFormatOptions, 'localeMatcher'>;
@@ -59,7 +58,7 @@ export type FormatDisplayNameOptions = Omit<Intl.DisplayNamesOptions, 'localeMat
59
58
  * For example, with React, `TBase` should be `React.ReactNode`.
60
59
  */
61
60
  export interface IntlFormatters<TBase = unknown> {
62
- formatDateTimeRange(this: void, from: Parameters<DateTimeFormat['formatRange']>[0], to: Parameters<DateTimeFormat['formatRange']>[1], opts?: FormatDateOptions): string;
61
+ formatDateTimeRange(this: void, from: Parameters<Intl.DateTimeFormat['formatRange']>[0], to: Parameters<Intl.DateTimeFormat['formatRange']>[1], opts?: FormatDateOptions): string;
63
62
  formatDate(this: void, value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
64
63
  formatTime(this: void, value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
65
64
  formatDateToParts(this: void, value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
@@ -78,8 +77,8 @@ export interface IntlFormatters<TBase = unknown> {
78
77
  formatDisplayName(this: void, value: Parameters<Intl.DisplayNames['of']>[0], opts: FormatDisplayNameOptions): string | undefined;
79
78
  }
80
79
  export interface Formatters {
81
- getDateTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.DateTimeFormat>): DateTimeFormat;
82
- getNumberFormat(this: void, locales?: string | string[], opts?: NumberFormatOptions): Intl.NumberFormat;
80
+ getDateTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
81
+ getNumberFormat(this: void, locales?: string | string[], opts?: Intl.NumberFormatOptions): Intl.NumberFormat;
83
82
  getMessageFormat(this: void, ...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
84
83
  getRelativeTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
85
84
  getPluralRules(this: void, ...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
@@ -90,7 +89,7 @@ export interface IntlShape<T = string> extends ResolvedIntlConfig<T>, IntlFormat
90
89
  formatters: Formatters;
91
90
  }
92
91
  export interface IntlCache {
93
- dateTime: Record<string, DateTimeFormat>;
92
+ dateTime: Record<string, Intl.DateTimeFormat>;
94
93
  number: Record<string, Intl.NumberFormat>;
95
94
  message: Record<string, IntlMessageFormat>;
96
95
  relativeTime: Record<string, Intl.RelativeTimeFormat>;
package/src/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { IntlCache, CustomFormats, Formatters, OnErrorFn, ResolvedIntlConfig } from './types';
2
- import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
1
+ import { CustomFormats, Formatters, IntlCache, OnErrorFn, ResolvedIntlConfig } from './types';
2
+ export declare function invariant(condition: boolean, message: string, Err?: any): asserts condition;
3
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
4
  export declare const DEFAULT_INTL_CONFIG: Pick<ResolvedIntlConfig<any>, 'fallbackOnEmptyString' | 'formats' | 'messages' | 'timeZone' | 'defaultLocale' | 'defaultFormats' | 'onError' | 'onWarn'>;
5
5
  export declare function createIntlCache(): IntlCache;
@@ -8,4 +8,4 @@ export declare function createIntlCache(): IntlCache;
8
8
  * @param cache explicit cache to prevent leaking memory
9
9
  */
10
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;
11
+ export declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: OnErrorFn): Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | Intl.RelativeTimeFormatOptions | undefined;
package/src/utils.js CHANGED
@@ -1,14 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_INTL_CONFIG = void 0;
4
+ exports.invariant = invariant;
4
5
  exports.filterProps = filterProps;
5
6
  exports.createIntlCache = createIntlCache;
6
7
  exports.createFormatters = createFormatters;
7
8
  exports.getNamedFormat = getNamedFormat;
8
9
  var tslib_1 = require("tslib");
9
- var intl_messageformat_1 = require("intl-messageformat");
10
10
  var fast_memoize_1 = require("@formatjs/fast-memoize");
11
+ var intl_messageformat_1 = require("intl-messageformat");
11
12
  var error_1 = require("./error");
13
+ function invariant(condition, message, Err) {
14
+ if (Err === void 0) { Err = Error; }
15
+ if (!condition) {
16
+ throw new Err(message);
17
+ }
18
+ }
12
19
  function filterProps(props, allowlist, defaults) {
13
20
  if (defaults === void 0) { defaults = {}; }
14
21
  return allowlist.reduce(function (filtered, name) {