lightFormat.d.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { lightFormatters } from "./_lib/format/lightFormatters.js";
  2. import type { DateArg } from "./types.js";
  3. export { lightFormatters };
  4. /**
  5. * @name lightFormat
  6. * @category Common Helpers
  7. * @summary Format the date.
  8. *
  9. * @description
  10. * Return the formatted date string in the given format. Unlike `format`,
  11. * `lightFormat` doesn't use locales and outputs date using the most popular tokens.
  12. *
  13. * > ⚠️ Please note that the `lightFormat` tokens differ from Moment.js and other libraries.
  14. * > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
  15. *
  16. * The characters wrapped between two single quotes characters (') are escaped.
  17. * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
  18. *
  19. * Format of the string is based on Unicode Technical Standard #35:
  20. * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
  21. *
  22. * Accepted patterns:
  23. * | Unit | Pattern | Result examples |
  24. * |---------------------------------|---------|-----------------------------------|
  25. * | AM, PM | a..aaa | AM, PM |
  26. * | | aaaa | a.m., p.m. |
  27. * | | aaaaa | a, p |
  28. * | Calendar year | y | 44, 1, 1900, 2017 |
  29. * | | yy | 44, 01, 00, 17 |
  30. * | | yyy | 044, 001, 000, 017 |
  31. * | | yyyy | 0044, 0001, 1900, 2017 |
  32. * | Month (formatting) | M | 1, 2, ..., 12 |
  33. * | | MM | 01, 02, ..., 12 |
  34. * | Day of month | d | 1, 2, ..., 31 |
  35. * | | dd | 01, 02, ..., 31 |
  36. * | Hour [1-12] | h | 1, 2, ..., 11, 12 |
  37. * | | hh | 01, 02, ..., 11, 12 |
  38. * | Hour [0-23] | H | 0, 1, 2, ..., 23 |
  39. * | | HH | 00, 01, 02, ..., 23 |
  40. * | Minute | m | 0, 1, ..., 59 |
  41. * | | mm | 00, 01, ..., 59 |
  42. * | Second | s | 0, 1, ..., 59 |
  43. * | | ss | 00, 01, ..., 59 |
  44. * | Fraction of second | S | 0, 1, ..., 9 |
  45. * | | SS | 00, 01, ..., 99 |
  46. * | | SSS | 000, 001, ..., 999 |
  47. * | | SSSS | ... |
  48. *
  49. * @param date - The original date
  50. * @param format - The string of tokens
  51. *
  52. * @returns The formatted date string
  53. *
  54. * @throws `Invalid time value` if the date is invalid
  55. * @throws format string contains an unescaped latin alphabet character
  56. *
  57. * @example
  58. * const result = lightFormat(new Date(2014, 1, 11), 'yyyy-MM-dd')
  59. * //=> '2014-02-11'
  60. */
  61. export declare function lightFormat(
  62. date: DateArg<Date> & {},
  63. formatStr: string,
  64. ): string;