umy-ui-table 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/lib/button.js +1 -0
  4. package/lib/icon.js +1 -0
  5. package/lib/index.js +1 -0
  6. package/lib/locale/format.js +56 -0
  7. package/lib/locale/index.js +72 -0
  8. package/lib/locale/lang/en.js +123 -0
  9. package/lib/locale/lang/zh-CN.js +119 -0
  10. package/lib/mixins/locale.js +17 -0
  11. package/lib/theme-chalk/base.css +0 -0
  12. package/lib/theme-chalk/button.css +1 -0
  13. package/lib/theme-chalk/fonts/element-icons.ttf +0 -0
  14. package/lib/theme-chalk/fonts/element-icons.woff +0 -0
  15. package/lib/theme-chalk/fonts/iconfont.1785562768224.ttf +0 -0
  16. package/lib/theme-chalk/fonts/iconfont.1785562768224.woff +0 -0
  17. package/lib/theme-chalk/fonts/iconfont.1785562768224.woff2 +0 -0
  18. package/lib/theme-chalk/icon.css +1 -0
  19. package/lib/theme-chalk/index.css +1 -0
  20. package/lib/theme-chalk/u-table-column.css +0 -0
  21. package/lib/theme-chalk/u-table.css +1 -0
  22. package/lib/theme-chalk/ux-grid.css +1 -0
  23. package/lib/theme-chalk/ux-table-column.css +0 -0
  24. package/lib/u-table-column.js +1 -0
  25. package/lib/u-table.js +1 -0
  26. package/lib/umd/locale/en.js +139 -0
  27. package/lib/umd/locale/zh-CN.js +135 -0
  28. package/lib/umy-ui.common.js +1 -0
  29. package/lib/utils/svg.js +33 -0
  30. package/lib/utils/types.js +35 -0
  31. package/lib/utils/util.js +268 -0
  32. package/lib/ux-grid.js +1 -0
  33. package/lib/ux-table-column.js +1 -0
  34. package/package.json +117 -0
  35. package/packages/button/index.js +7 -0
  36. package/packages/button/src/button-group.vue +10 -0
  37. package/packages/button/src/button.vue +166 -0
  38. package/packages/checkbox/index.js +8 -0
  39. package/packages/checkbox/src/checkbox-button.vue +199 -0
  40. package/packages/checkbox/src/checkbox-group.vue +48 -0
  41. package/packages/checkbox/src/checkbox.vue +222 -0
  42. package/packages/checkbox-button/index.js +8 -0
  43. package/packages/checkbox-group/index.js +8 -0
  44. package/packages/icon/index.js +7 -0
  45. package/packages/icon/src/icon.vue +40 -0
  46. package/packages/input/index.js +2 -0
  47. package/packages/input/src/calcTextareaHeight.js +104 -0
  48. package/packages/input/src/input.vue +424 -0
  49. package/packages/option/index.js +2 -0
  50. package/packages/pagination/index.js +2 -0
  51. package/packages/pagination/src/pager.vue +163 -0
  52. package/packages/pagination/src/pagination.js +386 -0
  53. package/packages/scrollbar/index.js +8 -0
  54. package/packages/scrollbar/src/bar.js +92 -0
  55. package/packages/scrollbar/src/main.js +130 -0
  56. package/packages/scrollbar/src/util.js +34 -0
  57. package/packages/select/index.js +2 -0
  58. package/packages/select/src/navigation-mixin.js +54 -0
  59. package/packages/select/src/option-group.vue +60 -0
  60. package/packages/select/src/option.vue +163 -0
  61. package/packages/select/src/select-dropdown.vue +74 -0
  62. package/packages/select/src/select.vue +889 -0
  63. package/packages/table/index.js +8 -0
  64. package/packages/table/src/config.js +123 -0
  65. package/packages/table/src/dropdown.js +28 -0
  66. package/packages/table/src/filter-panel.vue +194 -0
  67. package/packages/table/src/layout-observer.js +68 -0
  68. package/packages/table/src/store/current.js +71 -0
  69. package/packages/table/src/store/expand.js +65 -0
  70. package/packages/table/src/store/helper.js +37 -0
  71. package/packages/table/src/store/index.js +145 -0
  72. package/packages/table/src/store/tree.js +208 -0
  73. package/packages/table/src/store/watcher.js +448 -0
  74. package/packages/table/src/table-body.js +493 -0
  75. package/packages/table/src/table-column.js +381 -0
  76. package/packages/table/src/table-footer.js +174 -0
  77. package/packages/table/src/table-header.js +537 -0
  78. package/packages/table/src/table-layout.js +231 -0
  79. package/packages/table/src/table.vue +741 -0
  80. package/packages/table/src/util.js +256 -0
  81. package/packages/tag/index.js +8 -0
  82. package/packages/tag/src/tag.vue +58 -0
  83. package/packages/tools/directives/mousewheel.js +18 -0
  84. package/packages/tools/directives/repeat-click.js +24 -0
  85. package/packages/tools/locale/format.js +46 -0
  86. package/packages/tools/locale/index.js +48 -0
  87. package/packages/tools/locale/lang/en.js +120 -0
  88. package/packages/tools/locale/lang/zh-CN.js +116 -0
  89. package/packages/tools/mixins/emitter.js +33 -0
  90. package/packages/tools/mixins/focus.js +9 -0
  91. package/packages/tools/mixins/locale.js +9 -0
  92. package/packages/tools/mixins/migrating.js +54 -0
  93. package/packages/tools/transitions/collapse-transition.js +77 -0
  94. package/packages/tools/utils/after-leave.js +27 -0
  95. package/packages/tools/utils/aria-dialog.js +90 -0
  96. package/packages/tools/utils/aria-utils.js +122 -0
  97. package/packages/tools/utils/clickoutside.js +76 -0
  98. package/packages/tools/utils/date-util.js +292 -0
  99. package/packages/tools/utils/date.js +368 -0
  100. package/packages/tools/utils/dom.js +227 -0
  101. package/packages/tools/utils/menu/aria-menubar.js +14 -0
  102. package/packages/tools/utils/menu/aria-menuitem.js +49 -0
  103. package/packages/tools/utils/menu/aria-submenu.js +59 -0
  104. package/packages/tools/utils/merge.js +15 -0
  105. package/packages/tools/utils/popper.js +1276 -0
  106. package/packages/tools/utils/popup/index.js +218 -0
  107. package/packages/tools/utils/popup/popup-manager.js +194 -0
  108. package/packages/tools/utils/resize-event.js +35 -0
  109. package/packages/tools/utils/scroll-into-view.js +27 -0
  110. package/packages/tools/utils/scrollbar-width.js +29 -0
  111. package/packages/tools/utils/shared.js +7 -0
  112. package/packages/tools/utils/svg.js +1 -0
  113. package/packages/tools/utils/types.js +28 -0
  114. package/packages/tools/utils/util.js +241 -0
  115. package/packages/tools/utils/vdom.js +5 -0
  116. package/packages/tools/utils/vue-popper.js +198 -0
  117. package/packages/tooltip/index.js +8 -0
  118. package/packages/tooltip/src/main.js +241 -0
  119. package/packages/u-table/index.js +4 -0
  120. package/packages/u-table/revise-el-table-mixins/index.js +10 -0
  121. package/packages/u-table/revise-el-table-mixins/table-extend.js +60 -0
  122. package/packages/u-table/revise-el-table-mixins/table.mixins.js +261 -0
  123. package/packages/u-table/revise-el-table-mixins/virtual-table-body-render.js +132 -0
  124. package/packages/u-table/src/u-table.vue +248 -0
  125. package/packages/u-table/u-table-mixins/index.js +483 -0
  126. package/packages/u-table/u-table-tree-mixins/methods.js +120 -0
  127. package/packages/u-table/u-table-tree-mixins/u-table-tree-mixins.js +161 -0
  128. package/packages/u-table-column/index.js +8 -0
  129. package/packages/utils/common.js +27 -0
  130. package/packages/ux-grid/index.js +6 -0
  131. package/packages/ux-grid/mixins/index.js +707 -0
  132. package/packages/ux-grid/src/interceptor.js +6 -0
  133. package/packages/ux-grid/src/ux-grid.vue +301 -0
  134. package/packages/ux-table-column/index.js +10 -0
  135. package/tools/locale/format.js +46 -0
  136. package/tools/locale/index.js +54 -0
  137. package/tools/locale/lang/en.js +120 -0
  138. package/tools/locale/lang/zh-CN.js +116 -0
  139. package/tools/mixins/locale.js +9 -0
  140. package/tools/utils/svg.js +1 -0
  141. package/tools/utils/types.js +28 -0
  142. package/tools/utils/util.js +241 -0
@@ -0,0 +1,292 @@
1
+ import fecha from './date';
2
+ import { t } from '../../locale';
3
+
4
+ const weeks = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
5
+ const months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
6
+
7
+ const newArray = function(start, end) {
8
+ let result = [];
9
+ for (let i = start; i <= end; i++) {
10
+ result.push(i);
11
+ }
12
+ return result;
13
+ };
14
+
15
+ export const getI18nSettings = () => {
16
+ return {
17
+ dayNamesShort: weeks.map(week => t(`el.datepicker.weeks.${ week }`)),
18
+ dayNames: weeks.map(week => t(`el.datepicker.weeks.${ week }`)),
19
+ monthNamesShort: months.map(month => t(`el.datepicker.months.${ month }`)),
20
+ monthNames: months.map((month, index) => t(`el.datepicker.month${ index + 1 }`)),
21
+ amPm: ['am', 'pm']
22
+ };
23
+ };
24
+
25
+ export const toDate = function(date) {
26
+ return isDate(date) ? new Date(date) : null;
27
+ };
28
+
29
+ export const isDate = function(date) {
30
+ if (date === null || date === undefined) return false;
31
+ if (isNaN(new Date(date).getTime())) return false;
32
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
33
+ return true;
34
+ };
35
+
36
+ export const isDateObject = function(val) {
37
+ return val instanceof Date;
38
+ };
39
+
40
+ export const formatDate = function(date, format) {
41
+ date = toDate(date);
42
+ if (!date) return '';
43
+ return fecha.format(date, format || 'yyyy-MM-dd', getI18nSettings());
44
+ };
45
+
46
+ export const parseDate = function(string, format) {
47
+ return fecha.parse(string, format || 'yyyy-MM-dd', getI18nSettings());
48
+ };
49
+
50
+ export const getDayCountOfMonth = function(year, month) {
51
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
52
+ return 30;
53
+ }
54
+
55
+ if (month === 1) {
56
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
57
+ return 29;
58
+ } else {
59
+ return 28;
60
+ }
61
+ }
62
+
63
+ return 31;
64
+ };
65
+
66
+ export const getDayCountOfYear = function(year) {
67
+ const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
68
+ return isLeapYear ? 366 : 365;
69
+ };
70
+
71
+ export const getFirstDayOfMonth = function(date) {
72
+ const temp = new Date(date.getTime());
73
+ temp.setDate(1);
74
+ return temp.getDay();
75
+ };
76
+
77
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
78
+ // {prev, next} Date should work for Daylight Saving Time
79
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
80
+ export const prevDate = function(date, amount = 1) {
81
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
82
+ };
83
+
84
+ export const nextDate = function(date, amount = 1) {
85
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
86
+ };
87
+
88
+ export const getStartDateOfMonth = function(year, month) {
89
+ const result = new Date(year, month, 1);
90
+ const day = result.getDay();
91
+
92
+ if (day === 0) {
93
+ return prevDate(result, 7);
94
+ } else {
95
+ return prevDate(result, day);
96
+ }
97
+ };
98
+
99
+ export const getWeekNumber = function(src) {
100
+ if (!isDate(src)) return null;
101
+ const date = new Date(src.getTime());
102
+ date.setHours(0, 0, 0, 0);
103
+ // Thursday in current week decides the year.
104
+ date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
105
+ // January 4 is always in week 1.
106
+ const week1 = new Date(date.getFullYear(), 0, 4);
107
+ // Adjust to Thursday in week 1 and count number of weeks from date to week 1.
108
+ // Rounding should be fine for Daylight Saving Time. Its shift should never be more than 12 hours.
109
+ return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
110
+ };
111
+
112
+ export const getRangeHours = function(ranges) {
113
+ const hours = [];
114
+ let disabledHours = [];
115
+
116
+ (ranges || []).forEach(range => {
117
+ const value = range.map(date => date.getHours());
118
+
119
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
120
+ });
121
+
122
+ if (disabledHours.length) {
123
+ for (let i = 0; i < 24; i++) {
124
+ hours[i] = disabledHours.indexOf(i) === -1;
125
+ }
126
+ } else {
127
+ for (let i = 0; i < 24; i++) {
128
+ hours[i] = false;
129
+ }
130
+ }
131
+
132
+ return hours;
133
+ };
134
+
135
+ export const getPrevMonthLastDays = (date, amount) => {
136
+ if (amount <= 0) return [];
137
+ const temp = new Date(date.getTime());
138
+ temp.setDate(0);
139
+ const lastDay = temp.getDate();
140
+ return range(amount).map((_, index) => lastDay - (amount - index - 1));
141
+ };
142
+
143
+ export const getMonthDays = (date) => {
144
+ const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
145
+ const days = temp.getDate();
146
+ return range(days).map((_, index) => index + 1);
147
+ };
148
+
149
+ function setRangeData(arr, start, end, value) {
150
+ for (let i = start; i < end; i++) {
151
+ arr[i] = value;
152
+ }
153
+ }
154
+
155
+ export const getRangeMinutes = function(ranges, hour) {
156
+ const minutes = new Array(60);
157
+
158
+ if (ranges.length > 0) {
159
+ ranges.forEach(range => {
160
+ const start = range[0];
161
+ const end = range[1];
162
+ const startHour = start.getHours();
163
+ const startMinute = start.getMinutes();
164
+ const endHour = end.getHours();
165
+ const endMinute = end.getMinutes();
166
+ if (startHour === hour && endHour !== hour) {
167
+ setRangeData(minutes, startMinute, 60, true);
168
+ } else if (startHour === hour && endHour === hour) {
169
+ setRangeData(minutes, startMinute, endMinute + 1, true);
170
+ } else if (startHour !== hour && endHour === hour) {
171
+ setRangeData(minutes, 0, endMinute + 1, true);
172
+ } else if (startHour < hour && endHour > hour) {
173
+ setRangeData(minutes, 0, 60, true);
174
+ }
175
+ });
176
+ } else {
177
+ setRangeData(minutes, 0, 60, true);
178
+ }
179
+ return minutes;
180
+ };
181
+
182
+ export const range = function(n) {
183
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
184
+ return Array.apply(null, {length: n}).map((_, n) => n);
185
+ };
186
+
187
+ export const modifyDate = function(date, y, m, d) {
188
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
189
+ };
190
+
191
+ export const modifyTime = function(date, h, m, s) {
192
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
193
+ };
194
+
195
+ export const modifyWithTimeString = (date, time) => {
196
+ if (date == null || !time) {
197
+ return date;
198
+ }
199
+ time = parseDate(time, 'HH:mm:ss');
200
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
201
+ };
202
+
203
+ export const clearTime = function(date) {
204
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
205
+ };
206
+
207
+ export const clearMilliseconds = function(date) {
208
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
209
+ };
210
+
211
+ export const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
212
+ // TODO: refactory a more elegant solution
213
+ if (ranges.length === 0) return date;
214
+ const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
215
+ const ndate = normalizeDate(date);
216
+ const nranges = ranges.map(range => range.map(normalizeDate));
217
+ if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
218
+
219
+ let minDate = nranges[0][0];
220
+ let maxDate = nranges[0][0];
221
+
222
+ nranges.forEach(nrange => {
223
+ minDate = new Date(Math.min(nrange[0], minDate));
224
+ maxDate = new Date(Math.max(nrange[1], minDate));
225
+ });
226
+
227
+ const ret = ndate < minDate ? minDate : maxDate;
228
+ // preserve Year/Month/Date
229
+ return modifyDate(
230
+ ret,
231
+ date.getFullYear(),
232
+ date.getMonth(),
233
+ date.getDate()
234
+ );
235
+ };
236
+
237
+ export const timeWithinRange = function(date, selectableRange, format) {
238
+ const limitedDate = limitTimeRange(date, selectableRange, format);
239
+ return limitedDate.getTime() === date.getTime();
240
+ };
241
+
242
+ export const changeYearMonthAndClampDate = function(date, year, month) {
243
+ // clamp date to the number of days in `year`, `month`
244
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
245
+ const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
246
+ return modifyDate(date, year, month, monthDate);
247
+ };
248
+
249
+ export const prevMonth = function(date) {
250
+ const year = date.getFullYear();
251
+ const month = date.getMonth();
252
+ return month === 0
253
+ ? changeYearMonthAndClampDate(date, year - 1, 11)
254
+ : changeYearMonthAndClampDate(date, year, month - 1);
255
+ };
256
+
257
+ export const nextMonth = function(date) {
258
+ const year = date.getFullYear();
259
+ const month = date.getMonth();
260
+ return month === 11
261
+ ? changeYearMonthAndClampDate(date, year + 1, 0)
262
+ : changeYearMonthAndClampDate(date, year, month + 1);
263
+ };
264
+
265
+ export const prevYear = function(date, amount = 1) {
266
+ const year = date.getFullYear();
267
+ const month = date.getMonth();
268
+ return changeYearMonthAndClampDate(date, year - amount, month);
269
+ };
270
+
271
+ export const nextYear = function(date, amount = 1) {
272
+ const year = date.getFullYear();
273
+ const month = date.getMonth();
274
+ return changeYearMonthAndClampDate(date, year + amount, month);
275
+ };
276
+
277
+ export const extractDateFormat = function(format) {
278
+ return format
279
+ .replace(/\W?m{1,2}|\W?ZZ/g, '')
280
+ .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
281
+ .trim();
282
+ };
283
+
284
+ export const extractTimeFormat = function(format) {
285
+ return format
286
+ .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
287
+ .trim();
288
+ };
289
+
290
+ export const validateRangeInOneMonth = function(start, end) {
291
+ return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
292
+ };
@@ -0,0 +1,368 @@
1
+ /* Modified from https://github.com/taylorhakes/fecha
2
+ *
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 Taylor Hakes
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ /*eslint-disable*/
27
+ // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
28
+ (function (main) {
29
+ 'use strict';
30
+
31
+ /**
32
+ * Parse or format dates
33
+ * @class fecha
34
+ */
35
+ var fecha = {};
36
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
37
+ var twoDigits = '\\d\\d?';
38
+ var threeDigits = '\\d{3}';
39
+ var fourDigits = '\\d{4}';
40
+ var word = '[^\\s]+';
41
+ var literal = /\[([^]*?)\]/gm;
42
+ var noop = function () {
43
+ };
44
+
45
+ function regexEscape(str) {
46
+ return str.replace( /[|\\{()[^$+*?.-]/g, '\\$&');
47
+ }
48
+
49
+ function shorten(arr, sLen) {
50
+ var newArr = [];
51
+ for (var i = 0, len = arr.length; i < len; i++) {
52
+ newArr.push(arr[i].substr(0, sLen));
53
+ }
54
+ return newArr;
55
+ }
56
+
57
+ function monthUpdate(arrName) {
58
+ return function (d, v, i18n) {
59
+ var index = i18n[arrName].indexOf(v.charAt(0).toUpperCase() + v.substr(1).toLowerCase());
60
+ if (~index) {
61
+ d.month = index;
62
+ }
63
+ };
64
+ }
65
+
66
+ function pad(val, len) {
67
+ val = String(val);
68
+ len = len || 2;
69
+ while (val.length < len) {
70
+ val = '0' + val;
71
+ }
72
+ return val;
73
+ }
74
+
75
+ var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
76
+ var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
77
+ var monthNamesShort = shorten(monthNames, 3);
78
+ var dayNamesShort = shorten(dayNames, 3);
79
+ fecha.i18n = {
80
+ dayNamesShort: dayNamesShort,
81
+ dayNames: dayNames,
82
+ monthNamesShort: monthNamesShort,
83
+ monthNames: monthNames,
84
+ amPm: ['am', 'pm'],
85
+ DoFn: function DoFn(D) {
86
+ return D + ['th', 'st', 'nd', 'rd'][D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10];
87
+ }
88
+ };
89
+
90
+ var formatFlags = {
91
+ D: function(dateObj) {
92
+ return dateObj.getDay();
93
+ },
94
+ DD: function(dateObj) {
95
+ return pad(dateObj.getDay());
96
+ },
97
+ Do: function(dateObj, i18n) {
98
+ return i18n.DoFn(dateObj.getDate());
99
+ },
100
+ d: function(dateObj) {
101
+ return dateObj.getDate();
102
+ },
103
+ dd: function(dateObj) {
104
+ return pad(dateObj.getDate());
105
+ },
106
+ ddd: function(dateObj, i18n) {
107
+ return i18n.dayNamesShort[dateObj.getDay()];
108
+ },
109
+ dddd: function(dateObj, i18n) {
110
+ return i18n.dayNames[dateObj.getDay()];
111
+ },
112
+ M: function(dateObj) {
113
+ return dateObj.getMonth() + 1;
114
+ },
115
+ MM: function(dateObj) {
116
+ return pad(dateObj.getMonth() + 1);
117
+ },
118
+ MMM: function(dateObj, i18n) {
119
+ return i18n.monthNamesShort[dateObj.getMonth()];
120
+ },
121
+ MMMM: function(dateObj, i18n) {
122
+ return i18n.monthNames[dateObj.getMonth()];
123
+ },
124
+ yy: function(dateObj) {
125
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
126
+ },
127
+ yyyy: function(dateObj) {
128
+ return pad(dateObj.getFullYear(), 4);
129
+ },
130
+ h: function(dateObj) {
131
+ return dateObj.getHours() % 12 || 12;
132
+ },
133
+ hh: function(dateObj) {
134
+ return pad(dateObj.getHours() % 12 || 12);
135
+ },
136
+ H: function(dateObj) {
137
+ return dateObj.getHours();
138
+ },
139
+ HH: function(dateObj) {
140
+ return pad(dateObj.getHours());
141
+ },
142
+ m: function(dateObj) {
143
+ return dateObj.getMinutes();
144
+ },
145
+ mm: function(dateObj) {
146
+ return pad(dateObj.getMinutes());
147
+ },
148
+ s: function(dateObj) {
149
+ return dateObj.getSeconds();
150
+ },
151
+ ss: function(dateObj) {
152
+ return pad(dateObj.getSeconds());
153
+ },
154
+ S: function(dateObj) {
155
+ return Math.round(dateObj.getMilliseconds() / 100);
156
+ },
157
+ SS: function(dateObj) {
158
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
159
+ },
160
+ SSS: function(dateObj) {
161
+ return pad(dateObj.getMilliseconds(), 3);
162
+ },
163
+ a: function(dateObj, i18n) {
164
+ return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
165
+ },
166
+ A: function(dateObj, i18n) {
167
+ return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase();
168
+ },
169
+ ZZ: function(dateObj) {
170
+ var o = dateObj.getTimezoneOffset();
171
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
172
+ }
173
+ };
174
+
175
+ var parseFlags = {
176
+ d: [twoDigits, function (d, v) {
177
+ d.day = v;
178
+ }],
179
+ Do: [twoDigits + word, function (d, v) {
180
+ d.day = parseInt(v, 10);
181
+ }],
182
+ M: [twoDigits, function (d, v) {
183
+ d.month = v - 1;
184
+ }],
185
+ yy: [twoDigits, function (d, v) {
186
+ var da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
187
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
188
+ }],
189
+ h: [twoDigits, function (d, v) {
190
+ d.hour = v;
191
+ }],
192
+ m: [twoDigits, function (d, v) {
193
+ d.minute = v;
194
+ }],
195
+ s: [twoDigits, function (d, v) {
196
+ d.second = v;
197
+ }],
198
+ yyyy: [fourDigits, function (d, v) {
199
+ d.year = v;
200
+ }],
201
+ S: ['\\d', function (d, v) {
202
+ d.millisecond = v * 100;
203
+ }],
204
+ SS: ['\\d{2}', function (d, v) {
205
+ d.millisecond = v * 10;
206
+ }],
207
+ SSS: [threeDigits, function (d, v) {
208
+ d.millisecond = v;
209
+ }],
210
+ D: [twoDigits, noop],
211
+ ddd: [word, noop],
212
+ MMM: [word, monthUpdate('monthNamesShort')],
213
+ MMMM: [word, monthUpdate('monthNames')],
214
+ a: [word, function (d, v, i18n) {
215
+ var val = v.toLowerCase();
216
+ if (val === i18n.amPm[0]) {
217
+ d.isPm = false;
218
+ } else if (val === i18n.amPm[1]) {
219
+ d.isPm = true;
220
+ }
221
+ }],
222
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
223
+ var parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
224
+
225
+ if (parts) {
226
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
227
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
228
+ }
229
+ }]
230
+ };
231
+ parseFlags.dd = parseFlags.d;
232
+ parseFlags.dddd = parseFlags.ddd;
233
+ parseFlags.DD = parseFlags.D;
234
+ parseFlags.mm = parseFlags.m;
235
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
236
+ parseFlags.MM = parseFlags.M;
237
+ parseFlags.ss = parseFlags.s;
238
+ parseFlags.A = parseFlags.a;
239
+
240
+
241
+ // Some common format strings
242
+ fecha.masks = {
243
+ default: 'ddd MMM dd yyyy HH:mm:ss',
244
+ shortDate: 'M/D/yy',
245
+ mediumDate: 'MMM d, yyyy',
246
+ longDate: 'MMMM d, yyyy',
247
+ fullDate: 'dddd, MMMM d, yyyy',
248
+ shortTime: 'HH:mm',
249
+ mediumTime: 'HH:mm:ss',
250
+ longTime: 'HH:mm:ss.SSS'
251
+ };
252
+
253
+ /***
254
+ * Format a date
255
+ * @method format
256
+ * @param {Date|number} dateObj
257
+ * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
258
+ */
259
+ fecha.format = function (dateObj, mask, i18nSettings) {
260
+ var i18n = i18nSettings || fecha.i18n;
261
+
262
+ if (typeof dateObj === 'number') {
263
+ dateObj = new Date(dateObj);
264
+ }
265
+
266
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
267
+ throw new Error('Invalid Date in fecha.format');
268
+ }
269
+
270
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
271
+
272
+ var literals = [];
273
+
274
+ // Make literals inactive by replacing them with ??
275
+ mask = mask.replace(literal, function($0, $1) {
276
+ literals.push($1);
277
+ return '@@@';
278
+ });
279
+ // Apply formatting rules
280
+ mask = mask.replace(token, function ($0) {
281
+ return $0 in formatFlags ? formatFlags[$0](dateObj, i18n) : $0.slice(1, $0.length - 1);
282
+ });
283
+ // Inline literal values back into the formatted value
284
+ return mask.replace(/@@@/g, function() {
285
+ return literals.shift();
286
+ });
287
+ };
288
+
289
+ /**
290
+ * Parse a date string into an object, changes - into /
291
+ * @method parse
292
+ * @param {string} dateStr Date string
293
+ * @param {string} format Date parse format
294
+ * @returns {Date|boolean}
295
+ */
296
+ fecha.parse = function (dateStr, format, i18nSettings) {
297
+ var i18n = i18nSettings || fecha.i18n;
298
+
299
+ if (typeof format !== 'string') {
300
+ throw new Error('Invalid format in fecha.parse');
301
+ }
302
+
303
+ format = fecha.masks[format] || format;
304
+
305
+ // Avoid regular expression denial of service, fail early for really long strings
306
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
307
+ if (dateStr.length > 1000) {
308
+ return null;
309
+ }
310
+
311
+ var dateInfo = {};
312
+ var parseInfo = [];
313
+ var literals = [];
314
+ format = format.replace(literal, function($0, $1) {
315
+ literals.push($1);
316
+ return '@@@';
317
+ });
318
+ var newFormat = regexEscape(format).replace(token, function ($0) {
319
+ if (parseFlags[$0]) {
320
+ var info = parseFlags[$0];
321
+ parseInfo.push(info[1]);
322
+ return '(' + info[0] + ')';
323
+ }
324
+
325
+ return $0;
326
+ });
327
+ newFormat = newFormat.replace(/@@@/g, function() {
328
+ return literals.shift();
329
+ });
330
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
331
+ if (!matches) {
332
+ return null;
333
+ }
334
+
335
+ for (var i = 1; i < matches.length; i++) {
336
+ parseInfo[i - 1](dateInfo, matches[i], i18n);
337
+ }
338
+
339
+ var today = new Date();
340
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
341
+ dateInfo.hour = +dateInfo.hour + 12;
342
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
343
+ dateInfo.hour = 0;
344
+ }
345
+
346
+ var date;
347
+ if (dateInfo.timezoneOffset != null) {
348
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
349
+ date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
350
+ dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
351
+ } else {
352
+ date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
353
+ dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
354
+ }
355
+ return date;
356
+ };
357
+
358
+ /* istanbul ignore next */
359
+ if (typeof module !== 'undefined' && module.exports) {
360
+ module.exports = fecha;
361
+ } else if (typeof define === 'function' && define.amd) {
362
+ define(function () {
363
+ return fecha;
364
+ });
365
+ } else {
366
+ main.fecha = fecha;
367
+ }
368
+ })(this);