intl-messageformat
- Version 10.7.14
- Published
- 223 kB
- 4 dependencies
- BSD-3-Clause license
Install
npm i intl-messageformat
yarn add intl-messageformat
pnpm add intl-messageformat
Overview
Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.
Index
Functions
Classes
Interfaces
Enums
Type Aliases
Functions
function formatToParts
formatToParts: <T>( els: MessageFormatElement[], locales: string | string[], formatters: Formatters, formats: Formats, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, currentPluralValue?: number, originalMessage?: string) => MessageFormatPart<T>[];
function isFormatXMLElementFn
isFormatXMLElementFn: <T>( el: PrimitiveType | T | FormatXMLElementFn<T>) => el is FormatXMLElementFn<T, string | T | (string | T)[]>;
Classes
class FormatError
class FormatError extends Error {}
constructor
constructor(msg: string, code: ErrorCode, originalMessage?: string);
property code
readonly code: ErrorCode;
property originalMessage
readonly originalMessage: string;
Original message we're trying to format
undefined
if we're only dealing w/ AST{(string | undefined)} FormatError
method toString
toString: () => string;
class IntlMessageFormat
class IntlMessageFormat {}
constructor
constructor( message: string | MessageFormatElement[], locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
property defaultLocale
static readonly defaultLocale: string;
property format
format: <T = void>( values?: Record< string, T | PrimitiveType | FormatXMLElementFn<T, string | T | (string | T)[]> >) => string | T | (string | T)[];
property formats
static formats: Formats;
property formatToParts
formatToParts: <T>( values?: Record< string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]> >) => MessageFormatPart<T>[];
property getAst
getAst: () => MessageFormatElement[];
property resolvedOptions
resolvedOptions: () => { locale: string };
property resolveLocale
static resolveLocale: (locales: string | string[]) => Intl.Locale | undefined;
class InvalidValueError
class InvalidValueError extends FormatError {}
constructor
constructor( variableId: string, value: any, options: string[], originalMessage?: string);
class InvalidValueTypeError
class InvalidValueTypeError extends FormatError {}
constructor
constructor(value: any, type: string, originalMessage?: string);
class MissingValueError
class MissingValueError extends FormatError {}
constructor
constructor(variableId: string, originalMessage?: string);
Interfaces
interface Formats
interface Formats {}
interface FormatterCache
interface FormatterCache {}
property dateTime
dateTime: Record<string, Intl.DateTimeFormat>;
property number
number: Record<string, NumberFormatOptions>;
property pluralRules
pluralRules: Record<string, Intl.PluralRules>;
interface Formatters
interface Formatters {}
method getDateTimeFormat
getDateTimeFormat: ( locales?: string | string[], options?: Intl.DateTimeFormatOptions) => Intl.DateTimeFormat;
method getNumberFormat
getNumberFormat: ( locals?: string | string[], opts?: NumberFormatOptions) => Intl.NumberFormat;
method getPluralRules
getPluralRules: ( locales?: string | string[], options?: Intl.PluralRulesOptions) => Intl.PluralRules;
interface LiteralPart
interface LiteralPart {}
interface ObjectPart
interface ObjectPart<T = any> {}
interface Options
interface Options extends Omit<ParserOptions, 'locale'> {}
property formatters
formatters?: Formatters;
Enums
enum ErrorCode
enum ErrorCode { MISSING_VALUE = 'MISSING_VALUE', INVALID_VALUE = 'INVALID_VALUE', MISSING_INTL_API = 'MISSING_INTL_API',}
member INVALID_VALUE
INVALID_VALUE = 'INVALID_VALUE'
member MISSING_INTL_API
MISSING_INTL_API = 'MISSING_INTL_API'
member MISSING_VALUE
MISSING_VALUE = 'MISSING_VALUE'
Type Aliases
type FormatXMLElementFn
type FormatXMLElementFn<T, R = string | T | (string | T)[]> = ( parts: Array<string | T>) => R;
type MessageFormatPart
type MessageFormatPart<T> = LiteralPart | ObjectPart<T>;
type PrimitiveType
type PrimitiveType = string | number | boolean | null | undefined | Date;
Package Files (4)
Dependencies (4)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/intl-messageformat
.
- Markdown[](https://www.jsdocs.io/package/intl-messageformat)
- HTML<a href="https://www.jsdocs.io/package/intl-messageformat"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2775 ms. - Missing or incorrect documentation? Open an issue for this package.