Locale.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @category Types
  3. * @summary A locale object.
  4. *
  5. * @description
  6. * A locale object.
  7. *
  8. * If you don't specify a locale in options, default locale is `en-US`.
  9. *
  10. * @typedef {Object} Locale
  11. *
  12. * @property {string} [code] - the locale code (ISO 639-1 + optional country code)
  13. * @property {Function} [formatDistance] - the function that takes a token
  14. * passed by `formatDistance` or `formatDistanceStrict` and payload,
  15. * and returns localized distance in words.
  16. * Required by `formatDistance` and `formatDistanceStrict`
  17. *
  18. * @property {Function} [formatRelative] - the function that takes a token
  19. * passed by `formatRelative` and two dates and returns the localized relative date format.
  20. * Required by `formatRelative`
  21. *
  22. * @property {Object} [localize] - the object with functions used to localize various values.
  23. * Required by `format` and `formatRelative`
  24. * @property {Function} localize.ordinalNumber - the function that localizes an ordinal number
  25. * @property {Function} localize.era - the function that takes 0 or 1 and returns localized era
  26. * @property {Function} localize.quarter - the function that localizes a quarter
  27. * @property {Function} localize.month - the function that localizes a month
  28. * @property {Function} localize.day - the function that localizes a day of the week
  29. * @property {Function} localize.dayPeriod - the function that takes one of the strings
  30. * 'am', 'pm', 'midnight', 'noon', 'morning', 'afternoon', 'evening' or 'night'
  31. * and returns localized time of the day
  32. *
  33. * @property {Object} [formatLong] - the object with functions that return localized formats
  34. * @property {Function} formatLong.date - the function that returns a localized long date format
  35. * @property {Function} formatLong.time - the function that returns a localized long time format
  36. * @property {Function} formatLong.dateTime - the function that returns a localized format of date and time combined
  37. *
  38. * @property {Object} [match] — the object with functions used to match and parse various localized values.
  39. * Required by `parse`
  40. * @property {Function} match.ordinalNumber - the function that parses a localized ordinal number
  41. * @property {Function} match.era - the function that parses a localized era
  42. * @property {Function} match.quarter - the function that parses a localized quarter
  43. * @property {Function} match.month - the function that parses a localized month
  44. * @property {Function} match.day - the function that parses a localized day of the week
  45. * @property {Function} match.dayPeriod - the function that parses a localized time of the day
  46. *
  47. * @property {Object} [options] - an object with locale options.
  48. * @property {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday).
  49. * Used by `differenceInCalendarWeeks`, `endOfWeek`, `format`, `getWeek`, `getWeekOfMonth`,
  50. * `getWeeksInMonth`, `isSameWeek`, `isSameWeek`, `lastDayOfWeek`, `parse`, `setDay`,
  51. * `setWeek`, `startOfWeek` and `startOfWeekYear`
  52. * @property {1|2|3|4|5|6|7} [options.firstWeekContainsDate=1] - the day of January,
  53. * which is always in the first week of the year.
  54. * Used by `format`, `getWeek`, `getWeekYear`, `parse`, `setWeek`, `setWeekYear` and `startOfWeekYear`.
  55. *
  56. * @throws {RangeError} `locale` must contain `localize` property. Thrown by `format` and `formatRelative`
  57. * @throws {RangeError} `locale` must contain `formatLong` property. Thrown by `format` and `formatRelative`
  58. * @throws {RangeError} `locale` must contain `formatRelative` property. Thrown by `formatRelative`
  59. * @throws {RangeError} `locale` must contain `formatDistance` property. Thrown by `formatDistance` and `formatDistanceStrict`
  60. * @throws {RangeError} `locale` must contain `match` property. Thrown by `parse`
  61. */
  62. var Locale = {}
  63. module.exports = Locale