index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. export default (function (o, c, dayjs) {
  2. // locale needed later
  3. var proto = c.prototype;
  4. var getLocalePart = function getLocalePart(part) {
  5. return part && (part.indexOf ? part : part.s);
  6. };
  7. var getShort = function getShort(ins, target, full, num, localeOrder) {
  8. var locale = ins.name ? ins : ins.$locale();
  9. var targetLocale = getLocalePart(locale[target]);
  10. var fullLocale = getLocalePart(locale[full]);
  11. var result = targetLocale || fullLocale.map(function (f) {
  12. return f.substr(0, num);
  13. });
  14. if (!localeOrder) return result;
  15. var weekStart = locale.weekStart;
  16. return result.map(function (_, index) {
  17. return result[(index + (weekStart || 0)) % 7];
  18. });
  19. };
  20. var getDayjsLocaleObject = function getDayjsLocaleObject() {
  21. return dayjs.Ls[dayjs.locale()];
  22. };
  23. var localeData = function localeData() {
  24. var _this = this;
  25. return {
  26. months: function months(instance) {
  27. return instance ? instance.format('MMMM') : getShort(_this, 'months');
  28. },
  29. monthsShort: function monthsShort(instance) {
  30. return instance ? instance.format('MMM') : getShort(_this, 'monthsShort', 'months', 3);
  31. },
  32. firstDayOfWeek: function firstDayOfWeek() {
  33. return _this.$locale().weekStart || 0;
  34. },
  35. weekdays: function weekdays(instance) {
  36. return instance ? instance.format('dddd') : getShort(_this, 'weekdays');
  37. },
  38. weekdaysMin: function weekdaysMin(instance) {
  39. return instance ? instance.format('dd') : getShort(_this, 'weekdaysMin', 'weekdays', 2);
  40. },
  41. weekdaysShort: function weekdaysShort(instance) {
  42. return instance ? instance.format('ddd') : getShort(_this, 'weekdaysShort', 'weekdays', 3);
  43. },
  44. longDateFormat: function longDateFormat(format) {
  45. return _this.$locale().formats[format];
  46. }
  47. };
  48. };
  49. proto.localeData = function () {
  50. return localeData.bind(this)();
  51. };
  52. dayjs.localeData = function () {
  53. var localeObject = getDayjsLocaleObject();
  54. return {
  55. firstDayOfWeek: function firstDayOfWeek() {
  56. return localeObject.weekStart || 0;
  57. },
  58. weekdays: function weekdays() {
  59. return dayjs.weekdays();
  60. },
  61. weekdaysShort: function weekdaysShort() {
  62. return dayjs.weekdaysShort();
  63. },
  64. weekdaysMin: function weekdaysMin() {
  65. return dayjs.weekdaysMin();
  66. },
  67. months: function months() {
  68. return dayjs.months();
  69. },
  70. monthsShort: function monthsShort() {
  71. return dayjs.monthsShort();
  72. }
  73. };
  74. };
  75. dayjs.months = function () {
  76. return getShort(getDayjsLocaleObject(), 'months');
  77. };
  78. dayjs.monthsShort = function () {
  79. return getShort(getDayjsLocaleObject(), 'monthsShort', 'months', 3);
  80. };
  81. dayjs.weekdays = function (localeOrder) {
  82. return getShort(getDayjsLocaleObject(), 'weekdays', null, null, localeOrder);
  83. };
  84. dayjs.weekdaysShort = function (localeOrder) {
  85. return getShort(getDayjsLocaleObject(), 'weekdaysShort', 'weekdays', 3, localeOrder);
  86. };
  87. dayjs.weekdaysMin = function (localeOrder) {
  88. return getShort(getDayjsLocaleObject(), 'weekdaysMin', 'weekdays', 2, localeOrder);
  89. };
  90. });