@formatjs/intl
Advanced tools
Comparing version 2.2.1 to 2.2.3
@@ -8,2 +8,3 @@ import { MessageDescriptor } from './src/types'; | ||
export { formatMessage } from './src/message'; | ||
export type { FormatMessageFn } from './src/message'; | ||
export { formatDate, formatDateToParts, formatTime, formatTimeToParts, } from './src/dateTime'; | ||
@@ -10,0 +11,0 @@ export { formatDisplayName } from './src/displayName'; |
@@ -8,2 +8,3 @@ import { MessageDescriptor } from './src/types'; | ||
export { formatMessage } from './src/message'; | ||
export type { FormatMessageFn } from './src/message'; | ||
export { formatDate, formatDateToParts, formatTime, formatTimeToParts, } from './src/dateTime'; | ||
@@ -10,0 +11,0 @@ export { formatDisplayName } from './src/displayName'; |
@@ -19,3 +19,3 @@ import { __extends } from "tslib"; | ||
: undefined; | ||
_this = _super.call(this, "[@formatjs/intl Error ".concat(code, "] ").concat(message, " \n").concat(err ? "\n".concat(err.message, "\n").concat(err.stack) : '')) || this; | ||
_this = _super.call(this, "[@formatjs/intl Error ".concat(code, "] ").concat(message, "\n").concat(err ? "\n".concat(err.message, "\n").concat(err.stack) : '')) || this; | ||
_this.code = code; | ||
@@ -59,3 +59,3 @@ // @ts-ignore just so we don't need to declare dep on @types/node | ||
function IntlFormatError(message, locale, exception) { | ||
return _super.call(this, IntlErrorCode.FORMAT_ERROR, "".concat(message, " \nLocale: ").concat(locale, "\n"), exception) || this; | ||
return _super.call(this, IntlErrorCode.FORMAT_ERROR, "".concat(message, "\nLocale: ").concat(locale, "\n"), exception) || this; | ||
} | ||
@@ -68,3 +68,3 @@ return IntlFormatError; | ||
function MessageFormatError(message, locale, descriptor, exception) { | ||
var _this = _super.call(this, "".concat(message, " \nMessageID: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.id, "\nDefault Message: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.defaultMessage, "\nDescription: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.description, " \n"), locale, exception) || this; | ||
var _this = _super.call(this, "".concat(message, "\nMessageID: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.id, "\nDefault Message: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.defaultMessage, "\nDescription: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.description, "\n"), locale, exception) || this; | ||
_this.descriptor = descriptor; | ||
@@ -79,3 +79,9 @@ return _this; | ||
function MissingTranslationError(descriptor, locale) { | ||
var _this = _super.call(this, IntlErrorCode.MISSING_TRANSLATION, "Missing message: \"".concat(descriptor.id, "\" for locale \"").concat(locale, "\", using ").concat(descriptor.defaultMessage ? 'default message' : 'id', " as fallback.")) || this; | ||
var _this = _super.call(this, IntlErrorCode.MISSING_TRANSLATION, "Missing message: \"".concat(descriptor.id, "\" for locale \"").concat(locale, "\", using ").concat(descriptor.defaultMessage | ||
? "default message (".concat(typeof descriptor.defaultMessage === 'string' | ||
? descriptor.defaultMessage | ||
: descriptor.defaultMessage | ||
.map(function (e) { var _a; return (_a = e.value) !== null && _a !== void 0 ? _a : JSON.stringify(e); }) | ||
.join(), ")") | ||
: 'id', " as fallback.")) || this; | ||
_this.descriptor = descriptor; | ||
@@ -82,0 +88,0 @@ return _this; |
import { Formatters, MessageDescriptor, CustomFormats, OnErrorFn } from './types'; | ||
import { FormatXMLElementFn, PrimitiveType, Options } from 'intl-messageformat'; | ||
import { FormatXMLElementFn, PrimitiveType, Formatters as IntlMessageFormatFormatters, Options } from 'intl-messageformat'; | ||
import { MessageFormatElement } from '@formatjs/icu-messageformat-parser'; | ||
export declare function formatMessage(config: { | ||
export declare type FormatMessageFn<T> = ({ locale, formats, messages, defaultLocale, defaultFormats, fallbackOnEmptyString, onError, timeZone, defaultRichTextElements, }: { | ||
locale: string; | ||
@@ -11,4 +11,7 @@ timeZone?: string; | ||
defaultFormats: CustomFormats; | ||
defaultRichTextElements?: Record<string, FormatXMLElementFn<T>>; | ||
fallbackOnEmptyString?: boolean; | ||
onError: OnErrorFn; | ||
}, state: Formatters, messageDescriptor?: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: Options): string; | ||
}, state: IntlMessageFormatFormatters & Pick<Formatters, 'getMessageFormat'>, messageDescriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, opts?: Options) => T extends string ? string : Array<T | string> | string | T; | ||
export declare const formatMessage: FormatMessageFn<any>; | ||
//# sourceMappingURL=message.d.ts.map |
@@ -26,3 +26,3 @@ import { __assign } from "tslib"; | ||
} | ||
export function formatMessage(_a, state, messageDescriptor, values, opts) { | ||
export var formatMessage = function (_a, state, messageDescriptor, values, opts) { | ||
var locale = _a.locale, formats = _a.formats, messages = _a.messages, defaultLocale = _a.defaultLocale, defaultFormats = _a.defaultFormats, fallbackOnEmptyString = _a.fallbackOnEmptyString, onError = _a.onError, timeZone = _a.timeZone, defaultRichTextElements = _a.defaultRichTextElements; | ||
@@ -104,2 +104,2 @@ if (messageDescriptor === void 0) { messageDescriptor = { id: '' }; } | ||
return id; | ||
} | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { IntlMessageFormat, Formats, PrimitiveType, FormatXMLElementFn, FormatError, Options as IntlMessageFormatOptions } from 'intl-messageformat'; | ||
import { IntlMessageFormat, Formats, FormatXMLElementFn, FormatError, PrimitiveType, Options as IntlMessageFormatOptions } from 'intl-messageformat'; | ||
import { DateTimeFormat } from '@formatjs/ecma402-abstract'; | ||
@@ -3,0 +3,0 @@ import { MessageFormatElement } from '@formatjs/icu-messageformat-parser'; |
{ | ||
"name": "@formatjs/intl", | ||
"version": "2.2.1", | ||
"version": "2.2.3", | ||
"description": "Internationalize JS apps. This library provides an API to format dates, numbers, and strings, including pluralization and handling translations.", | ||
@@ -32,9 +32,9 @@ "keywords": [ | ||
"dependencies": { | ||
"@formatjs/ecma402-abstract": "1.11.4", | ||
"@formatjs/fast-memoize": "1.2.1", | ||
"@formatjs/icu-messageformat-parser": "2.1.0", | ||
"@formatjs/intl-displaynames": "5.4.3", | ||
"@formatjs/intl-listformat": "6.5.3", | ||
"intl-messageformat": "9.13.0", | ||
"tslib": "^2.1.0" | ||
"@formatjs/ecma402-abstract": "1.11.6", | ||
"@formatjs/fast-memoize": "1.2.3", | ||
"@formatjs/icu-messageformat-parser": "2.1.2", | ||
"@formatjs/intl-displaynames": "6.0.1", | ||
"@formatjs/intl-listformat": "7.0.1", | ||
"intl-messageformat": "10.0.1", | ||
"tslib": "2.4.0" | ||
}, | ||
@@ -41,0 +41,0 @@ "peerDependencies": { |
@@ -22,3 +22,3 @@ "use strict"; | ||
: undefined; | ||
_this = _super.call(this, "[@formatjs/intl Error ".concat(code, "] ").concat(message, " \n").concat(err ? "\n".concat(err.message, "\n").concat(err.stack) : '')) || this; | ||
_this = _super.call(this, "[@formatjs/intl Error ".concat(code, "] ").concat(message, "\n").concat(err ? "\n".concat(err.message, "\n").concat(err.stack) : '')) || this; | ||
_this.code = code; | ||
@@ -62,3 +62,3 @@ // @ts-ignore just so we don't need to declare dep on @types/node | ||
function IntlFormatError(message, locale, exception) { | ||
return _super.call(this, IntlErrorCode.FORMAT_ERROR, "".concat(message, " \nLocale: ").concat(locale, "\n"), exception) || this; | ||
return _super.call(this, IntlErrorCode.FORMAT_ERROR, "".concat(message, "\nLocale: ").concat(locale, "\n"), exception) || this; | ||
} | ||
@@ -71,3 +71,3 @@ return IntlFormatError; | ||
function MessageFormatError(message, locale, descriptor, exception) { | ||
var _this = _super.call(this, "".concat(message, " \nMessageID: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.id, "\nDefault Message: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.defaultMessage, "\nDescription: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.description, " \n"), locale, exception) || this; | ||
var _this = _super.call(this, "".concat(message, "\nMessageID: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.id, "\nDefault Message: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.defaultMessage, "\nDescription: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.description, "\n"), locale, exception) || this; | ||
_this.descriptor = descriptor; | ||
@@ -82,3 +82,9 @@ return _this; | ||
function MissingTranslationError(descriptor, locale) { | ||
var _this = _super.call(this, IntlErrorCode.MISSING_TRANSLATION, "Missing message: \"".concat(descriptor.id, "\" for locale \"").concat(locale, "\", using ").concat(descriptor.defaultMessage ? 'default message' : 'id', " as fallback.")) || this; | ||
var _this = _super.call(this, IntlErrorCode.MISSING_TRANSLATION, "Missing message: \"".concat(descriptor.id, "\" for locale \"").concat(locale, "\", using ").concat(descriptor.defaultMessage | ||
? "default message (".concat(typeof descriptor.defaultMessage === 'string' | ||
? descriptor.defaultMessage | ||
: descriptor.defaultMessage | ||
.map(function (e) { var _a; return (_a = e.value) !== null && _a !== void 0 ? _a : JSON.stringify(e); }) | ||
.join(), ")") | ||
: 'id', " as fallback.")) || this; | ||
_this.descriptor = descriptor; | ||
@@ -85,0 +91,0 @@ return _this; |
import { Formatters, MessageDescriptor, CustomFormats, OnErrorFn } from './types'; | ||
import { FormatXMLElementFn, PrimitiveType, Options } from 'intl-messageformat'; | ||
import { FormatXMLElementFn, PrimitiveType, Formatters as IntlMessageFormatFormatters, Options } from 'intl-messageformat'; | ||
import { MessageFormatElement } from '@formatjs/icu-messageformat-parser'; | ||
export declare function formatMessage(config: { | ||
export declare type FormatMessageFn<T> = ({ locale, formats, messages, defaultLocale, defaultFormats, fallbackOnEmptyString, onError, timeZone, defaultRichTextElements, }: { | ||
locale: string; | ||
@@ -11,4 +11,7 @@ timeZone?: string; | ||
defaultFormats: CustomFormats; | ||
defaultRichTextElements?: Record<string, FormatXMLElementFn<T>>; | ||
fallbackOnEmptyString?: boolean; | ||
onError: OnErrorFn; | ||
}, state: Formatters, messageDescriptor?: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: Options): string; | ||
}, state: IntlMessageFormatFormatters & Pick<Formatters, 'getMessageFormat'>, messageDescriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, opts?: Options) => T extends string ? string : Array<T | string> | string | T; | ||
export declare const formatMessage: FormatMessageFn<any>; | ||
//# sourceMappingURL=message.d.ts.map |
@@ -29,3 +29,3 @@ "use strict"; | ||
} | ||
function formatMessage(_a, state, messageDescriptor, values, opts) { | ||
var formatMessage = function (_a, state, messageDescriptor, values, opts) { | ||
var locale = _a.locale, formats = _a.formats, messages = _a.messages, defaultLocale = _a.defaultLocale, defaultFormats = _a.defaultFormats, fallbackOnEmptyString = _a.fallbackOnEmptyString, onError = _a.onError, timeZone = _a.timeZone, defaultRichTextElements = _a.defaultRichTextElements; | ||
@@ -107,3 +107,3 @@ if (messageDescriptor === void 0) { messageDescriptor = { id: '' }; } | ||
return id; | ||
} | ||
}; | ||
exports.formatMessage = formatMessage; |
@@ -1,2 +0,2 @@ | ||
import { IntlMessageFormat, Formats, PrimitiveType, FormatXMLElementFn, FormatError, Options as IntlMessageFormatOptions } from 'intl-messageformat'; | ||
import { IntlMessageFormat, Formats, FormatXMLElementFn, FormatError, PrimitiveType, Options as IntlMessageFormatOptions } from 'intl-messageformat'; | ||
import { DateTimeFormat } from '@formatjs/ecma402-abstract'; | ||
@@ -3,0 +3,0 @@ import { MessageFormatElement } from '@formatjs/icu-messageformat-parser'; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
139749
2084
+ Added@formatjs/ecma402-abstract@1.11.6(transitive)
+ Added@formatjs/fast-memoize@1.2.3(transitive)
+ Added@formatjs/icu-messageformat-parser@2.1.2(transitive)
+ Added@formatjs/icu-skeleton-parser@1.3.8(transitive)
+ Added@formatjs/intl-displaynames@6.0.1(transitive)
+ Added@formatjs/intl-listformat@7.0.1(transitive)
+ Added@formatjs/intl-localematcher@0.2.27(transitive)
+ Addedintl-messageformat@10.0.1(transitive)
+ Addedtslib@2.4.0(transitive)
- Removed@formatjs/ecma402-abstract@1.11.4(transitive)
- Removed@formatjs/fast-memoize@1.2.1(transitive)
- Removed@formatjs/icu-messageformat-parser@2.1.0(transitive)
- Removed@formatjs/icu-skeleton-parser@1.3.6(transitive)
- Removed@formatjs/intl-displaynames@5.4.3(transitive)
- Removed@formatjs/intl-listformat@6.5.3(transitive)
- Removed@formatjs/intl-localematcher@0.2.25(transitive)
- Removedintl-messageformat@9.13.0(transitive)
- Removedtslib@2.7.0(transitive)
Updated@formatjs/fast-memoize@1.2.3
Updatedintl-messageformat@10.0.1
Updatedtslib@2.4.0