tokens.d.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. export declare type DateField = 'era' | 'year' | 'quarter' | 'month' | 'week' | 'day' | 'weekday' | 'period' | 'hour' | 'min' | 'sec' | 'sec-frac' | 'ms' | 'tz';
  2. export declare const fields: {
  3. [symbol: string]: {
  4. field: DateField;
  5. desc: string;
  6. };
  7. };
  8. /**
  9. * An object representation of a parsed date skeleton token
  10. *
  11. * @public
  12. */
  13. export declare type DateToken = {
  14. char: string;
  15. error?: Error;
  16. field?: DateField;
  17. desc?: string;
  18. str?: string;
  19. width: number;
  20. };
  21. /**
  22. * Parse an {@link http://userguide.icu-project.org/formatparse/datetime | ICU
  23. * DateFormat skeleton} string into a {@link DateToken} array.
  24. *
  25. * @remarks
  26. * Errors will not be thrown, but if encountered are included as the relevant
  27. * token's `error` value.
  28. *
  29. * @public
  30. * @param src - The skeleton string
  31. *
  32. * @example
  33. * ```js
  34. * import { parseDateTokens } from '@messageformat/date-skeleton'
  35. *
  36. * parseDateTokens('GrMMMdd', console.error)
  37. * // [
  38. * // { char: 'G', field: 'era', desc: 'Era', width: 1 },
  39. * // { char: 'r', field: 'year', desc: 'Related Gregorian year', width: 1 },
  40. * // { char: 'M', field: 'month', desc: 'Month in year', width: 3 },
  41. * // { char: 'd', field: 'day', desc: 'Day in month', width: 2 }
  42. * // ]
  43. * ```
  44. */
  45. export declare function parseDateTokens(src: string): DateToken[];