getNumberFormatOptions() function
Given an input ICU NumberFormatter skeleton, constructs a corresponding Intl.NumberFormat
options structure.
Signature:
export declare function getNumberFormatOptions(skeleton: Skeleton, onError: (stem: string, option?: string) => void): Intl.NumberFormatOptions;
Parameters
Parameter | Type | Description |
---|---|---|
skeleton | Skeleton | |
onError | (stem: string, option?: string) => void | Called if encountering unsupported (but valid) tokens, such as decimal-always or precision-increment/0.05 . |
Returns:
Intl.NumberFormatOptions
Example
import {
getNumberFormatOptions,
parseNumberSkeleton
} from '@messageformat/number-skeleton'
const src = 'currency/CAD unit-width-narrow'
const skeleton = parseNumberSkeleton(src, console.error)
// {
// unit: { style: 'currency', currency: 'CAD' },
// unitWidth: 'unit-width-narrow'
// }
getNumberFormatOptions(skeleton, console.error)
// {
// style: 'currency',
// currency: 'CAD',
// currencyDisplay: 'narrowSymbol',
// unitDisplay: 'narrow'
// }
const sk2 = parseNumberSkeleton('decimal-always')
// { decimal: 'decimal-always' }
getNumberFormatOptions(sk2, console.error)
// prints: ['decimal-always']
// {}