🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@formatjs/intl

Package Overview
Dependencies
Maintainers
3
Versions
165
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

to
1.11.0

4

lib/src/create-intl.js

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

import { formatMessage } from './message';
import { formatList } from './list';
import { formatList, formatListToParts } from './list';
import { formatDisplayName } from './displayName';

@@ -50,3 +50,3 @@ function messagesContainString(messages) {

verifyConfigMessages(resolvedConfig);
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), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
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), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat), formatListToParts: formatListToParts.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
}
import { Formatters, IntlFormatters, OnErrorFn } from './types';
export declare function formatList({ locale, onError, }: {
import type { Part } from '@formatjs/intl-listformat';
export declare function formatList(opts: {
locale: string;
onError: OnErrorFn;
}, getListFormat: Formatters['getListFormat'], values: Array<string>, options: Parameters<IntlFormatters['formatList']>[1]): string;
export declare function formatListToParts<T>(opts: {
locale: string;
onError: OnErrorFn;
}, getListFormat: Formatters['getListFormat'], values: Array<string>, options: Parameters<IntlFormatters['formatList']>[1]): Part[];
//# sourceMappingURL=list.d.ts.map

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

import { __assign } from "tslib";
import { filterProps } from './utils';

@@ -13,3 +14,20 @@ import { FormatError, ErrorCode } from 'intl-messageformat';

}
export function formatList(_a, getListFormat, values, options) {
export function formatList(opts, getListFormat, values, options) {
if (options === void 0) { options = {}; }
var results = formatListToParts(opts, getListFormat, values, options).reduce(function (all, el) {
var val = el.value;
if (typeof val !== 'string') {
all.push(val);
}
else if (typeof all[all.length - 1] === 'string') {
all[all.length - 1] += val;
}
else {
all.push(val);
}
return all;
}, []);
return results.length === 1 ? results[0] : results;
}
export function formatListToParts(_a, getListFormat, values, options) {
var locale = _a.locale, onError = _a.onError;

@@ -32,19 +50,9 @@ if (options === void 0) { options = {}; }

});
if (!Object.keys(richValues_1).length) {
return getListFormat(locale, filteredOptions).format(serializedValues);
}
var parts = getListFormat(locale, filteredOptions).formatToParts(serializedValues);
return parts.reduce(function (all, el) {
var val = el.value;
if (richValues_1[val]) {
all.push(richValues_1[val]);
}
else if (typeof all[all.length - 1] === 'string') {
all[all.length - 1] += val;
}
else {
all.push(val);
}
return all;
}, []);
return getListFormat(locale, filteredOptions)
.formatToParts(serializedValues)
.map(function (part) {
return part.type === 'literal'
? part
: __assign(__assign({}, part), { value: richValues_1[part.value] || part.value });
});
}

@@ -51,0 +59,0 @@ catch (e) {

import { IntlMessageFormat, Formats, PrimitiveType, FormatXMLElementFn, FormatError, Options as IntlMessageFormatOptions } from 'intl-messageformat';
import { DateTimeFormat } from '@formatjs/ecma402-abstract';
import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
import IntlListFormat, { IntlListFormatOptions } from '@formatjs/intl-listformat';
import IntlListFormat, { IntlListFormatOptions, Part } from '@formatjs/intl-listformat';
import { DisplayNames, DisplayNamesOptions } from '@formatjs/intl-displaynames';

@@ -51,2 +51,3 @@ import { MissingTranslationError, MessageFormatError, MissingDataError, InvalidConfigError, UnsupportedFormatterError } from './error';

formatList(values: Array<string | T>, opts?: FormatListOptions): T | string | Array<string | T>;
formatListToParts(values: Array<string | T>, opts?: FormatListOptions): Part[];
formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts: FormatDisplayNameOptions): string | undefined;

@@ -53,0 +54,0 @@ }

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

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

"dependencies": {
"@formatjs/ecma402-abstract": "1.8.0",
"@formatjs/ecma402-abstract": "1.9.0",
"@formatjs/fast-memoize": "1.1.1",
"@formatjs/icu-messageformat-parser": "2.0.2",
"@formatjs/intl-displaynames": "5.1.0",
"@formatjs/intl-listformat": "6.1.0",
"intl-messageformat": "9.6.14",
"@formatjs/icu-messageformat-parser": "2.0.3",
"@formatjs/intl-displaynames": "5.1.1",
"@formatjs/intl-listformat": "6.2.0",
"intl-messageformat": "9.6.15",
"tslib": "^2.1.0"

@@ -40,0 +40,0 @@ },

@@ -52,4 +52,4 @@ "use strict";

verifyConfigMessages(resolvedConfig);
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), formatList: list_1.formatList.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: displayName_1.formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
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), 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) });
}
exports.createIntl = createIntl;
import { Formatters, IntlFormatters, OnErrorFn } from './types';
export declare function formatList({ locale, onError, }: {
import type { Part } from '@formatjs/intl-listformat';
export declare function formatList(opts: {
locale: string;
onError: OnErrorFn;
}, getListFormat: Formatters['getListFormat'], values: Array<string>, options: Parameters<IntlFormatters['formatList']>[1]): string;
export declare function formatListToParts<T>(opts: {
locale: string;
onError: OnErrorFn;
}, getListFormat: Formatters['getListFormat'], values: Array<string>, options: Parameters<IntlFormatters['formatList']>[1]): Part[];
//# sourceMappingURL=list.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatList = void 0;
exports.formatListToParts = exports.formatList = void 0;
var tslib_1 = require("tslib");
var utils_1 = require("./utils");

@@ -16,3 +17,21 @@ var intl_messageformat_1 = require("intl-messageformat");

}
function formatList(_a, getListFormat, values, options) {
function formatList(opts, getListFormat, values, options) {
if (options === void 0) { options = {}; }
var results = formatListToParts(opts, getListFormat, values, options).reduce(function (all, el) {
var val = el.value;
if (typeof val !== 'string') {
all.push(val);
}
else if (typeof all[all.length - 1] === 'string') {
all[all.length - 1] += val;
}
else {
all.push(val);
}
return all;
}, []);
return results.length === 1 ? results[0] : results;
}
exports.formatList = formatList;
function formatListToParts(_a, getListFormat, values, options) {
var locale = _a.locale, onError = _a.onError;

@@ -35,19 +54,9 @@ if (options === void 0) { options = {}; }

});
if (!Object.keys(richValues_1).length) {
return getListFormat(locale, filteredOptions).format(serializedValues);
}
var parts = getListFormat(locale, filteredOptions).formatToParts(serializedValues);
return parts.reduce(function (all, el) {
var val = el.value;
if (richValues_1[val]) {
all.push(richValues_1[val]);
}
else if (typeof all[all.length - 1] === 'string') {
all[all.length - 1] += val;
}
else {
all.push(val);
}
return all;
}, []);
return getListFormat(locale, filteredOptions)
.formatToParts(serializedValues)
.map(function (part) {
return part.type === 'literal'
? part
: tslib_1.__assign(tslib_1.__assign({}, part), { value: richValues_1[part.value] || part.value });
});
}

@@ -60,2 +69,2 @@ catch (e) {

}
exports.formatList = formatList;
exports.formatListToParts = formatListToParts;
import { IntlMessageFormat, Formats, PrimitiveType, FormatXMLElementFn, FormatError, Options as IntlMessageFormatOptions } from 'intl-messageformat';
import { DateTimeFormat } from '@formatjs/ecma402-abstract';
import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
import IntlListFormat, { IntlListFormatOptions } from '@formatjs/intl-listformat';
import IntlListFormat, { IntlListFormatOptions, Part } from '@formatjs/intl-listformat';
import { DisplayNames, DisplayNamesOptions } from '@formatjs/intl-displaynames';

@@ -51,2 +51,3 @@ import { MissingTranslationError, MessageFormatError, MissingDataError, InvalidConfigError, UnsupportedFormatterError } from './error';

formatList(values: Array<string | T>, opts?: FormatListOptions): T | string | Array<string | T>;
formatListToParts(values: Array<string | T>, opts?: FormatListOptions): Part[];
formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts: FormatDisplayNameOptions): string | undefined;

@@ -53,0 +54,0 @@ }

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