Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@formatjs/intl

Package Overview
Dependencies
Maintainers
3
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formatjs/intl - npm Package Compare versions

Comparing version 1.7.1 to 1.8.0

3

index.d.ts

@@ -14,3 +14,4 @@ import { MessageDescriptor } from './src/types';

export { formatNumber, formatNumberToParts } from './src/number';
export { createIntl, CreateIntlFn } from './src/create-intl';
export { createIntl } from './src/create-intl';
export type { CreateIntlFn } from './src/create-intl';
//# sourceMappingURL=index.d.ts.map

@@ -14,3 +14,4 @@ import { MessageDescriptor } from './src/types';

export { formatNumber, formatNumberToParts } from './src/number';
export { createIntl, CreateIntlFn } from './src/create-intl';
export { createIntl } from './src/create-intl';
export type { CreateIntlFn } from './src/create-intl';
//# sourceMappingURL=index.d.ts.map

@@ -21,3 +21,2 @@ import { __assign } from "tslib";

'timeStyle',
'fractionalSecondDigits',
'calendar',

@@ -32,3 +31,5 @@ // 'dayPeriod',

var defaults = __assign(__assign({}, (timeZone && { timeZone: timeZone })), (format && getNamedFormat(formats, type, format, onError)));
var filteredOptions = filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults);
var filteredOptions = filterProps(options, DATE_TIME_FORMAT_OPTIONS,
// @ts-expect-error es2020 has a lot stuff from es2021 bleed in
defaults);
if (type === 'time' &&

@@ -35,0 +36,0 @@ !filteredOptions.hour &&

import { filterProps } from './utils';
import { FormatError } from 'intl-messageformat';
import { FormatError, ErrorCode } from 'intl-messageformat';
import { IntlErrorCode, IntlError } from './error';

@@ -14,3 +14,3 @@ var DISPLAY_NAMES_OPTONS = [

if (!DisplayNames) {
onError(new FormatError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
onError(new FormatError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n", ErrorCode.MISSING_INTL_API));
}

@@ -17,0 +17,0 @@ var filteredOptions = filterProps(options, DISPLAY_NAMES_OPTONS);

import { filterProps } from './utils';
import { FormatError } from 'intl-messageformat';
import { FormatError, ErrorCode } from 'intl-messageformat';
import { IntlError, IntlErrorCode } from './error';

@@ -18,3 +18,3 @@ var LIST_FORMAT_OPTIONS = [

if (!ListFormat) {
onError(new FormatError("Intl.ListFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-listformat\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
onError(new FormatError("Intl.ListFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-listformat\"\n", ErrorCode.MISSING_INTL_API));
}

@@ -21,0 +21,0 @@ var filteredOptions = filterProps(options, LIST_FORMAT_OPTIONS);

import { filterProps } from './utils';
import { MessageFormatError } from './error';
import { FormatError } from 'intl-messageformat';
import { ErrorCode, FormatError } from 'intl-messageformat';
var PLURAL_FORMAT_OPTIONS = [

@@ -12,3 +12,3 @@ 'localeMatcher',

if (!Intl.PluralRules) {
onError(new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
onError(new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", ErrorCode.MISSING_INTL_API));
}

@@ -15,0 +15,0 @@ var filteredOptions = filterProps(options, PLURAL_FORMAT_OPTIONS);

import { getNamedFormat, filterProps } from './utils';
import { FormatError } from 'intl-messageformat';
import { FormatError, ErrorCode } from 'intl-messageformat';
import { MessageFormatError } from './error';

@@ -20,3 +20,3 @@ var RELATIVE_TIME_FORMAT_OPTIONS = ['numeric', 'style'];

if (!RelativeTimeFormat) {
config.onError(new FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
config.onError(new FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n", ErrorCode.MISSING_INTL_API));
}

@@ -23,0 +23,0 @@ try {

import { IntlMessageFormat, Formats, PrimitiveType, FormatXMLElementFn, FormatError, Options as IntlMessageFormatOptions } from 'intl-messageformat';
import IntlRelativeTimeFormat from '@formatjs/intl-relativetimeformat';
import { DateTimeFormat } from '@formatjs/ecma402-abstract';

@@ -9,3 +8,3 @@ import { MessageFormatElement } from 'intl-messageformat-parser';

import { DEFAULT_INTL_CONFIG } from './utils';
import { IntlRelativeTimeFormatOptions, DateTimeFormatOptions, NumberFormatOptions } from '@formatjs/ecma402-abstract';
import { DateTimeFormatOptions, NumberFormatOptions } from '@formatjs/ecma402-abstract';
export declare type OnErrorFn = (err: MissingTranslationError | MessageFormatError | MissingDataError | InvalidConfigError | UnsupportedFormatterError | FormatError) => void;

@@ -28,3 +27,3 @@ /**

export interface CustomFormats extends Partial<Formats> {
relative?: Record<string, IntlRelativeTimeFormatOptions>;
relative?: Record<string, Intl.RelativeTimeFormatOptions>;
}

@@ -36,3 +35,3 @@ export interface CustomFormatConfig {

export declare type FormatNumberOptions = Exclude<NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig;
export declare type FormatRelativeTimeOptions = Exclude<IntlRelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
export declare type FormatRelativeTimeOptions = Exclude<Intl.RelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
export declare type FormatPluralOptions = Exclude<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;

@@ -47,3 +46,3 @@ export declare type FormatListOptions = Exclude<IntlListFormatOptions, 'localeMatcher'>;

formatTimeToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
formatRelativeTime(value: Parameters<IntlRelativeTimeFormat['format']>[0], unit?: Parameters<IntlRelativeTimeFormat['format']>[1], opts?: FormatRelativeTimeOptions): string;
formatRelativeTime(value: Parameters<Intl.RelativeTimeFormat['format']>[0], unit?: Parameters<Intl.RelativeTimeFormat['format']>[1], opts?: FormatRelativeTimeOptions): string;
formatNumber(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): string;

@@ -62,3 +61,3 @@ formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];

getMessageFormat(...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
getRelativeTimeFormat(...args: ConstructorParameters<typeof IntlRelativeTimeFormat>): IntlRelativeTimeFormat;
getRelativeTimeFormat(...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;

@@ -75,3 +74,3 @@ getListFormat(...args: ConstructorParameters<typeof IntlListFormat>): IntlListFormat;

message: Record<string, IntlMessageFormat>;
relativeTime: Record<string, IntlRelativeTimeFormat>;
relativeTime: Record<string, Intl.RelativeTimeFormat>;
pluralRules: Record<string, Intl.PluralRules>;

@@ -78,0 +77,0 @@ list: Record<string, IntlListFormat>;

import { IntlConfig, IntlCache, CustomFormats, Formatters, OnErrorFn } from './types';
import { IntlRelativeTimeFormatOptions } from '@formatjs/ecma402-abstract';
export declare function filterProps<T extends Record<string, any>, K extends string>(props: T, whitelist: Array<K>, defaults?: Partial<T>): Pick<T, K>;

@@ -11,3 +10,3 @@ export declare const DEFAULT_INTL_CONFIG: Pick<IntlConfig<any>, 'formats' | 'messages' | 'timeZone' | 'defaultLocale' | 'defaultFormats' | 'onError'>;

export declare function createFormatters(cache?: IntlCache): Formatters;
export declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: OnErrorFn): Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | IntlRelativeTimeFormatOptions | undefined;
export declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: OnErrorFn): Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | Intl.RelativeTimeFormatOptions | undefined;
//# sourceMappingURL=utils.d.ts.map

@@ -1,2 +0,2 @@

import { __assign, __spreadArrays } from "tslib";
import { __assign, __spreadArray } from "tslib";
import { IntlMessageFormat } from 'intl-messageformat';

@@ -76,3 +76,3 @@ import * as memoize from 'fast-memoize';

}
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArrays([void 0], args)))();
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args)))();
}, {

@@ -88,3 +88,3 @@ cache: createFastMemoizeCache(cache.dateTime),

}
return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArrays([void 0], args)))();
return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args)))();
}, {

@@ -100,3 +100,3 @@ cache: createFastMemoizeCache(cache.number),

}
return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArrays([void 0], args)))();
return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args)))();
}, {

@@ -124,3 +124,3 @@ cache: createFastMemoizeCache(cache.pluralRules),

}
return new (RelativeTimeFormat.bind.apply(RelativeTimeFormat, __spreadArrays([void 0], args)))();
return new (RelativeTimeFormat.bind.apply(RelativeTimeFormat, __spreadArray([void 0], args)))();
}, {

@@ -136,3 +136,3 @@ cache: createFastMemoizeCache(cache.relativeTime),

}
return new (ListFormat.bind.apply(ListFormat, __spreadArrays([void 0], args)))();
return new (ListFormat.bind.apply(ListFormat, __spreadArray([void 0], args)))();
}, {

@@ -147,3 +147,3 @@ cache: createFastMemoizeCache(cache.list),

}
return new (DisplayNames.bind.apply(DisplayNames, __spreadArrays([void 0], args)))();
return new (DisplayNames.bind.apply(DisplayNames, __spreadArray([void 0], args)))();
}, {

@@ -150,0 +150,0 @@ cache: createFastMemoizeCache(cache.displayNames),

{
"name": "@formatjs/intl",
"version": "1.7.1",
"version": "1.8.0",
"description": "Internationalize JS apps. This library provides an API to format dates, numbers, and strings, including pluralization and handling translations.",

@@ -32,12 +32,12 @@ "keywords": [

"dependencies": {
"@formatjs/ecma402-abstract": "1.5.4",
"@formatjs/intl-datetimeformat": "3.2.9",
"@formatjs/intl-displaynames": "4.0.7",
"@formatjs/intl-listformat": "5.0.7",
"@formatjs/intl-relativetimeformat": "8.0.6",
"@formatjs/ecma402-abstract": "1.6.0",
"@formatjs/intl-datetimeformat": "3.2.10",
"@formatjs/intl-displaynames": "4.0.8",
"@formatjs/intl-listformat": "5.0.8",
"@formatjs/intl-relativetimeformat": "8.1.0",
"fast-memoize": "^2.5.2",
"intl-messageformat": "9.4.9",
"intl-messageformat-parser": "6.3.4",
"intl-messageformat": "9.5.0",
"intl-messageformat-parser": "6.4.0",
"tslib": "^2.0.1"
}
}

@@ -24,3 +24,2 @@ "use strict";

'timeStyle',
'fractionalSecondDigits',
'calendar',

@@ -35,3 +34,5 @@ // 'dayPeriod',

var defaults = tslib_1.__assign(tslib_1.__assign({}, (timeZone && { timeZone: timeZone })), (format && utils_1.getNamedFormat(formats, type, format, onError)));
var filteredOptions = utils_1.filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults);
var filteredOptions = utils_1.filterProps(options, DATE_TIME_FORMAT_OPTIONS,
// @ts-expect-error es2020 has a lot stuff from es2021 bleed in
defaults);
if (type === 'time' &&

@@ -38,0 +39,0 @@ !filteredOptions.hour &&

@@ -17,3 +17,3 @@ "use strict";

if (!DisplayNames) {
onError(new intl_messageformat_1.FormatError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
onError(new intl_messageformat_1.FormatError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n", intl_messageformat_1.ErrorCode.MISSING_INTL_API));
}

@@ -20,0 +20,0 @@ var filteredOptions = utils_1.filterProps(options, DISPLAY_NAMES_OPTONS);

@@ -21,3 +21,3 @@ "use strict";

if (!ListFormat) {
onError(new intl_messageformat_1.FormatError("Intl.ListFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-listformat\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
onError(new intl_messageformat_1.FormatError("Intl.ListFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-listformat\"\n", intl_messageformat_1.ErrorCode.MISSING_INTL_API));
}

@@ -24,0 +24,0 @@ var filteredOptions = utils_1.filterProps(options, LIST_FORMAT_OPTIONS);

@@ -15,3 +15,3 @@ "use strict";

if (!Intl.PluralRules) {
onError(new intl_messageformat_1.FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
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));
}

@@ -18,0 +18,0 @@ var filteredOptions = utils_1.filterProps(options, PLURAL_FORMAT_OPTIONS);

@@ -23,3 +23,3 @@ "use strict";

if (!RelativeTimeFormat) {
config.onError(new intl_messageformat_1.FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
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));
}

@@ -26,0 +26,0 @@ try {

import { IntlMessageFormat, Formats, PrimitiveType, FormatXMLElementFn, FormatError, Options as IntlMessageFormatOptions } from 'intl-messageformat';
import IntlRelativeTimeFormat from '@formatjs/intl-relativetimeformat';
import { DateTimeFormat } from '@formatjs/ecma402-abstract';

@@ -9,3 +8,3 @@ import { MessageFormatElement } from 'intl-messageformat-parser';

import { DEFAULT_INTL_CONFIG } from './utils';
import { IntlRelativeTimeFormatOptions, DateTimeFormatOptions, NumberFormatOptions } from '@formatjs/ecma402-abstract';
import { DateTimeFormatOptions, NumberFormatOptions } from '@formatjs/ecma402-abstract';
export declare type OnErrorFn = (err: MissingTranslationError | MessageFormatError | MissingDataError | InvalidConfigError | UnsupportedFormatterError | FormatError) => void;

@@ -28,3 +27,3 @@ /**

export interface CustomFormats extends Partial<Formats> {
relative?: Record<string, IntlRelativeTimeFormatOptions>;
relative?: Record<string, Intl.RelativeTimeFormatOptions>;
}

@@ -36,3 +35,3 @@ export interface CustomFormatConfig {

export declare type FormatNumberOptions = Exclude<NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig;
export declare type FormatRelativeTimeOptions = Exclude<IntlRelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
export declare type FormatRelativeTimeOptions = Exclude<Intl.RelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
export declare type FormatPluralOptions = Exclude<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;

@@ -47,3 +46,3 @@ export declare type FormatListOptions = Exclude<IntlListFormatOptions, 'localeMatcher'>;

formatTimeToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
formatRelativeTime(value: Parameters<IntlRelativeTimeFormat['format']>[0], unit?: Parameters<IntlRelativeTimeFormat['format']>[1], opts?: FormatRelativeTimeOptions): string;
formatRelativeTime(value: Parameters<Intl.RelativeTimeFormat['format']>[0], unit?: Parameters<Intl.RelativeTimeFormat['format']>[1], opts?: FormatRelativeTimeOptions): string;
formatNumber(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): string;

@@ -62,3 +61,3 @@ formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];

getMessageFormat(...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
getRelativeTimeFormat(...args: ConstructorParameters<typeof IntlRelativeTimeFormat>): IntlRelativeTimeFormat;
getRelativeTimeFormat(...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;

@@ -75,3 +74,3 @@ getListFormat(...args: ConstructorParameters<typeof IntlListFormat>): IntlListFormat;

message: Record<string, IntlMessageFormat>;
relativeTime: Record<string, IntlRelativeTimeFormat>;
relativeTime: Record<string, Intl.RelativeTimeFormat>;
pluralRules: Record<string, Intl.PluralRules>;

@@ -78,0 +77,0 @@ list: Record<string, IntlListFormat>;

import { IntlConfig, IntlCache, CustomFormats, Formatters, OnErrorFn } from './types';
import { IntlRelativeTimeFormatOptions } from '@formatjs/ecma402-abstract';
export declare function filterProps<T extends Record<string, any>, K extends string>(props: T, whitelist: Array<K>, defaults?: Partial<T>): Pick<T, K>;

@@ -11,3 +10,3 @@ export declare const DEFAULT_INTL_CONFIG: Pick<IntlConfig<any>, 'formats' | 'messages' | 'timeZone' | 'defaultLocale' | 'defaultFormats' | 'onError'>;

export declare function createFormatters(cache?: IntlCache): Formatters;
export declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: OnErrorFn): Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | IntlRelativeTimeFormatOptions | undefined;
export declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: OnErrorFn): Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | Intl.RelativeTimeFormatOptions | undefined;
//# sourceMappingURL=utils.d.ts.map

@@ -81,3 +81,3 @@ "use strict";

}
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, tslib_1.__spreadArrays([void 0], args)))();
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
}, {

@@ -93,3 +93,3 @@ cache: createFastMemoizeCache(cache.dateTime),

}
return new ((_a = Intl.NumberFormat).bind.apply(_a, tslib_1.__spreadArrays([void 0], args)))();
return new ((_a = Intl.NumberFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
}, {

@@ -105,3 +105,3 @@ cache: createFastMemoizeCache(cache.number),

}
return new ((_a = Intl.PluralRules).bind.apply(_a, tslib_1.__spreadArrays([void 0], args)))();
return new ((_a = Intl.PluralRules).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
}, {

@@ -129,3 +129,3 @@ cache: createFastMemoizeCache(cache.pluralRules),

}
return new (RelativeTimeFormat.bind.apply(RelativeTimeFormat, tslib_1.__spreadArrays([void 0], args)))();
return new (RelativeTimeFormat.bind.apply(RelativeTimeFormat, tslib_1.__spreadArray([void 0], args)))();
}, {

@@ -141,3 +141,3 @@ cache: createFastMemoizeCache(cache.relativeTime),

}
return new (ListFormat.bind.apply(ListFormat, tslib_1.__spreadArrays([void 0], args)))();
return new (ListFormat.bind.apply(ListFormat, tslib_1.__spreadArray([void 0], args)))();
}, {

@@ -152,3 +152,3 @@ cache: createFastMemoizeCache(cache.list),

}
return new (DisplayNames.bind.apply(DisplayNames, tslib_1.__spreadArrays([void 0], args)))();
return new (DisplayNames.bind.apply(DisplayNames, tslib_1.__spreadArray([void 0], args)))();
}, {

@@ -155,0 +155,0 @@ cache: createFastMemoizeCache(cache.displayNames),

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc