options.d.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { UnsupportedError } from '../errors.js';
  2. import { Skeleton } from '../types/skeleton.js';
  3. /**
  4. * Extends `Intl.NumberFormat` options to include some features brought by the
  5. * {@link https://github.com/tc39/proposal-intl-numberformat-v3 | ECMA-402
  6. * Proposal: Intl.NumberFormat V3}
  7. *
  8. * @internal
  9. */
  10. export interface NumberFormatOptions extends Intl.NumberFormatOptions {
  11. trailingZeroDisplay?: 'auto' | 'stripIfInteger';
  12. }
  13. /**
  14. * Given an input ICU NumberFormatter skeleton, does its best to construct a
  15. * corresponding `Intl.NumberFormat` options structure.
  16. *
  17. * @remarks
  18. * Some features depend on `Intl.NumberFormat` features defined in ES2020.
  19. *
  20. * @internal
  21. * @param onUnsupported - If defined, called when encountering unsupported (but
  22. * valid) tokens, such as `decimal-always` or `permille`. The error `source`
  23. * may specify the source of an unsupported option.
  24. *
  25. * @example
  26. * ```js
  27. * import {
  28. * getNumberFormatOptions,
  29. * parseNumberSkeleton
  30. * } from '@messageformat/number-skeleton'
  31. *
  32. * const src = 'currency/CAD unit-width-narrow'
  33. * const skeleton = parseNumberSkeleton(src, console.error)
  34. * // {
  35. * // unit: { style: 'currency', currency: 'CAD' },
  36. * // unitWidth: 'unit-width-narrow'
  37. * // }
  38. *
  39. * getNumberFormatOptions(skeleton, console.error)
  40. * // {
  41. * // style: 'currency',
  42. * // currency: 'CAD',
  43. * // currencyDisplay: 'narrowSymbol',
  44. * // unitDisplay: 'narrow'
  45. * // }
  46. *
  47. * const sk2 = parseNumberSkeleton('group-min2')
  48. * // { group: 'group-min2' }
  49. *
  50. * getNumberFormatOptions(sk2, console.error)
  51. * // Error: The stem group-min2 is not supported
  52. * // at UnsupportedError.NumberFormatError ... {
  53. * // code: 'UNSUPPORTED',
  54. * // stem: 'group-min2'
  55. * // }
  56. * // {}
  57. * ```
  58. */
  59. export declare function getNumberFormatOptions(skeleton: Skeleton, onUnsupported?: (err: UnsupportedError) => void): NumberFormatOptions;