parse-pattern.d.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { Skeleton } from './types/skeleton.js';
  2. import { NumberFormatError } from './errors.js';
  3. /**
  4. * Parse an {@link
  5. * http://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns |
  6. * ICU NumberFormatter pattern} string into a {@link Skeleton} structure.
  7. *
  8. * @public
  9. * @param src - The pattern string
  10. * @param currency - If the pattern includes ¤ tokens, their skeleton
  11. * representation requires a three-letter currency code.
  12. * @param onError - Called when the parser encounters a syntax error. The
  13. * function will still return a {@link Skeleton}, but it will be incomplete
  14. * and/or inaccurate. If not defined, the error will be thrown instead.
  15. *
  16. * @remarks
  17. * Unlike the skeleton parser, the pattern parser is not able to return partial
  18. * results on error, and will instead throw. Output padding is not supported.
  19. *
  20. * @example
  21. * ```js
  22. * import { parseNumberPattern } from '@messageformat/number-skeleton'
  23. *
  24. * parseNumberPattern('#,##0.00 ¤', 'EUR', console.error)
  25. * // {
  26. * // group: 'group-auto',
  27. * // precision: {
  28. * // style: 'precision-fraction',
  29. * // minFraction: 2,
  30. * // maxFraction: 2
  31. * // },
  32. * // unit: { style: 'currency', currency: 'EUR' }
  33. * // }
  34. * ```
  35. */
  36. export declare function parseNumberPattern(src: string, currency?: string | null, onError?: (error: NumberFormatError) => void): Skeleton;