Link Search Menu Expand Document

parseNumberPattern() function

Parse an ICU NumberFormatter pattern string into a Skeleton structure.


export declare function parseNumberPattern(src: string, currency?: string | null, onError?: (error: NumberFormatError) => void): Skeleton;


Parameter Type Description
src string The pattern string
currency string | null If the pattern includes ¤ tokens, their skeleton representation requires a three-letter currency code.
onError (error: NumberFormatError) => void 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.




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.


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' }
// }