parseNumberPattern() function
Parse an ICU NumberFormatter pattern string into a Skeleton structure.
Signature:
export declare function parseNumberPattern(src: string, currency?: string | null, onError?: (error: NumberFormatError) => void): Skeleton;
Parameters
Parameter | Type | Description |
---|---|---|
src | string | The pattern string |
currency | string | null | (Optional) If the pattern includes ¤ tokens, their skeleton representation requires a three-letter currency code. |
onError | (error: NumberFormatError) => void | (Optional) Called when the parser encounters a syntax error. The function will still return a Skeleton, but it will be incomplete and/or inaccurate. If not defined, the error will be thrown instead. |
Returns:
Remarks
Unlike the skeleton parser, the pattern parser is not able to return partial results on error, and will instead throw. Output padding is not supported.
Example
import { parseNumberPattern } from '@messageformat/number-skeleton'
parseNumberPattern('#,##0.00 ¤', 'EUR', console.error)
// {
// group: 'group-auto',
// precision: {
// style: 'precision-fraction',
// minFraction: 2,
// maxFraction: 2
// },
// unit: { style: 'currency', currency: 'EUR' }
// }