cy-element-ui 1.0.8 → 1.0.10

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 (107) hide show
  1. package/lib/alert.js +2 -2
  2. package/lib/aside.js +76 -76
  3. package/lib/autocomplete.js +61 -75
  4. package/lib/avatar.js +2 -2
  5. package/lib/backtop.js +109 -109
  6. package/lib/badge.js +2 -2
  7. package/lib/breadcrumb-item.js +4 -4
  8. package/lib/breadcrumb.js +2 -2
  9. package/lib/button-group.js +2 -2
  10. package/lib/calendar.js +391 -452
  11. package/lib/card.js +2 -2
  12. package/lib/carousel-item.js +9 -9
  13. package/lib/carousel.js +25 -25
  14. package/lib/cascader-panel.js +30 -34
  15. package/lib/cascader.js +101 -116
  16. package/lib/checkbox-button.js +4 -4
  17. package/lib/checkbox-group.js +2 -2
  18. package/lib/col.js +2 -2
  19. package/lib/collapse-item.js +936 -851
  20. package/lib/collapse.js +2 -2
  21. package/lib/color-picker.js +62 -76
  22. package/lib/container.js +2 -2
  23. package/lib/date-picker.js +450 -474
  24. package/lib/descriptions-item.js +2 -2
  25. package/lib/descriptions.js +4 -4
  26. package/lib/dialog.js +5 -9
  27. package/lib/divider.js +105 -105
  28. package/lib/drawer.js +109 -109
  29. package/lib/dropdown-item.js +2 -2
  30. package/lib/dropdown-menu.js +65 -65
  31. package/lib/dropdown.js +1206 -1112
  32. package/lib/element-ui.common.js +43826 -48176
  33. package/lib/empty.js +6 -20
  34. package/lib/fileUpload.js +62 -77
  35. package/lib/footer.js +76 -76
  36. package/lib/form-item.js +7 -21
  37. package/lib/form.js +11 -11
  38. package/lib/header.js +2 -2
  39. package/lib/icon.js +2 -2
  40. package/lib/image.js +22 -36
  41. package/lib/index.js +1 -1
  42. package/lib/infinite-scroll.js +8 -8
  43. package/lib/input-number.js +5 -9
  44. package/lib/link.js +2 -2
  45. package/lib/loading.js +33 -33
  46. package/lib/main.js +65 -65
  47. package/lib/menu-item-group.js +2 -2
  48. package/lib/menu-item.js +63 -78
  49. package/lib/menu.js +2 -16
  50. package/lib/message-box.js +22 -36
  51. package/lib/message.js +8 -22
  52. package/lib/notification.js +8 -22
  53. package/lib/option-group.js +2 -2
  54. package/lib/option.js +14 -18
  55. package/lib/page-header.js +109 -109
  56. package/lib/pagination.js +100 -114
  57. package/lib/popconfirm.js +59 -74
  58. package/lib/popover.js +52 -56
  59. package/lib/progress.js +4 -4
  60. package/lib/radio-button.js +4 -4
  61. package/lib/radio-group.js +4 -4
  62. package/lib/radio.js +2 -2
  63. package/lib/rate.js +18 -18
  64. package/lib/result.js +2 -2
  65. package/lib/row.js +2 -2
  66. package/lib/scrollbar.js +6 -6
  67. package/lib/select.js +82 -86
  68. package/lib/skeleton-item.js +2 -2
  69. package/lib/skeleton.js +107 -107
  70. package/lib/slider.js +72 -86
  71. package/lib/spinner.js +2 -2
  72. package/lib/step.js +2 -2
  73. package/lib/steps.js +9 -9
  74. package/lib/subTitle.js +91 -91
  75. package/lib/submenu.js +250 -250
  76. package/lib/switch.js +883 -811
  77. package/lib/tab-pane.js +2 -2
  78. package/lib/tabDialog.js +19 -33
  79. package/lib/table-column.js +13 -13
  80. package/lib/table.js +96 -110
  81. package/lib/tabs.js +8 -22
  82. package/lib/tag.js +2 -2
  83. package/lib/theme-chalk/src/index.scss +0 -1
  84. package/lib/time-picker.js +450 -474
  85. package/lib/time-select.js +437 -461
  86. package/lib/timeline-item.js +107 -107
  87. package/lib/timeline.js +2 -2
  88. package/lib/tooltip.js +54 -55
  89. package/lib/transfer.js +15 -29
  90. package/lib/tree.js +22 -36
  91. package/lib/treeSelect.js +58 -73
  92. package/lib/upload.js +28 -32
  93. package/lib/utils/date.js +10 -3
  94. package/lib/utils/date_source.js +290 -304
  95. package/lib/utils/lodash_source.js +9290 -9290
  96. package/package.json +1 -1
  97. package/packages/theme-chalk/src/index.scss +0 -1
  98. package/src/index.js +1 -4
  99. package/src/utils/date.js +2 -2
  100. package/src/utils/date_source.js +305 -321
  101. package/src/utils/lodash_source.js +18079 -18064
  102. package/lib/statistic.js +0 -10484
  103. package/lib/theme-chalk/src/statistic.scss +0 -38
  104. package/packages/statistic/index.js +0 -8
  105. package/packages/statistic/src/main.vue +0 -203
  106. package/packages/theme-chalk/src/statistic.scss +0 -38
  107. package/types/statistic.d.ts +0 -37
@@ -25,344 +25,328 @@
25
25
 
26
26
  /*eslint-disable*/
27
27
  // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
28
- (function (main) {
29
- 'use strict';
30
28
 
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
- };
29
+ /**
30
+ * Parse or format dates
31
+ * @class fecha
32
+ */
33
+ const fecha = {};
34
+ const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
35
+ const twoDigits = '\\d\\d?';
36
+ const threeDigits = '\\d{3}';
37
+ const fourDigits = '\\d{4}';
38
+ const word = '[^\\s]+';
39
+ const literal = /\[([^]*?)\]/gm;
40
+ const noop = function () {
41
+ };
44
42
 
45
- function regexEscape(str) {
46
- return str.replace( /[|\\{()[^$+*?.-]/g, '\\$&');
47
- }
43
+ function regexEscape(str) {
44
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
45
+ }
48
46
 
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;
47
+ function shorten(arr, sLen) {
48
+ const newArr = [];
49
+ for (let i = 0, len = arr.length; i < len; i++) {
50
+ newArr.push(arr[i].substr(0, sLen));
55
51
  }
52
+ return newArr;
53
+ }
56
54
 
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);
55
+ function monthUpdate(arrName) {
56
+ return function (d, v, i18n) {
57
+ const index = i18n[arrName].indexOf(v.charAt(0).toUpperCase() + v.substr(1).toLowerCase());
58
+ if (~index) {
59
+ d.month = index;
172
60
  }
173
61
  };
62
+ }
174
63
 
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 = [];
64
+ function pad(val, len) {
65
+ val = String(val);
66
+ len = len || 2;
67
+ while (val.length < len) {
68
+ val = '0' + val;
69
+ }
70
+ return val;
71
+ }
273
72
 
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
- };
73
+ const dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
74
+ const monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
75
+ const monthNamesShort = shorten(monthNames, 3);
76
+ const dayNamesShort = shorten(dayNames, 3);
77
+ fecha.i18n = {
78
+ dayNamesShort: dayNamesShort,
79
+ dayNames: dayNames,
80
+ monthNamesShort: monthNamesShort,
81
+ monthNames: monthNames,
82
+ amPm: ['am', 'pm'],
83
+ DoFn: function DoFn(D) {
84
+ return D + ['th', 'st', 'nd', 'rd'][D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10];
85
+ }
86
+ };
288
87
 
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;
88
+ const formatFlags = {
89
+ D: function (dateObj) {
90
+ return dateObj.getDay();
91
+ },
92
+ DD: function (dateObj) {
93
+ return pad(dateObj.getDay());
94
+ },
95
+ Do: function (dateObj, i18n) {
96
+ return i18n.DoFn(dateObj.getDate());
97
+ },
98
+ d: function (dateObj) {
99
+ return dateObj.getDate();
100
+ },
101
+ dd: function (dateObj) {
102
+ return pad(dateObj.getDate());
103
+ },
104
+ ddd: function (dateObj, i18n) {
105
+ return i18n.dayNamesShort[dateObj.getDay()];
106
+ },
107
+ dddd: function (dateObj, i18n) {
108
+ return i18n.dayNames[dateObj.getDay()];
109
+ },
110
+ M: function (dateObj) {
111
+ return dateObj.getMonth() + 1;
112
+ },
113
+ MM: function (dateObj) {
114
+ return pad(dateObj.getMonth() + 1);
115
+ },
116
+ MMM: function (dateObj, i18n) {
117
+ return i18n.monthNamesShort[dateObj.getMonth()];
118
+ },
119
+ MMMM: function (dateObj, i18n) {
120
+ return i18n.monthNames[dateObj.getMonth()];
121
+ },
122
+ yy: function (dateObj) {
123
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
124
+ },
125
+ yyyy: function (dateObj) {
126
+ return pad(dateObj.getFullYear(), 4);
127
+ },
128
+ h: function (dateObj) {
129
+ return dateObj.getHours() % 12 || 12;
130
+ },
131
+ hh: function (dateObj) {
132
+ return pad(dateObj.getHours() % 12 || 12);
133
+ },
134
+ H: function (dateObj) {
135
+ return dateObj.getHours();
136
+ },
137
+ HH: function (dateObj) {
138
+ return pad(dateObj.getHours());
139
+ },
140
+ m: function (dateObj) {
141
+ return dateObj.getMinutes();
142
+ },
143
+ mm: function (dateObj) {
144
+ return pad(dateObj.getMinutes());
145
+ },
146
+ s: function (dateObj) {
147
+ return dateObj.getSeconds();
148
+ },
149
+ ss: function (dateObj) {
150
+ return pad(dateObj.getSeconds());
151
+ },
152
+ S: function (dateObj) {
153
+ return Math.round(dateObj.getMilliseconds() / 100);
154
+ },
155
+ SS: function (dateObj) {
156
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
157
+ },
158
+ SSS: function (dateObj) {
159
+ return pad(dateObj.getMilliseconds(), 3);
160
+ },
161
+ a: function (dateObj, i18n) {
162
+ return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
163
+ },
164
+ A: function (dateObj, i18n) {
165
+ return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase();
166
+ },
167
+ ZZ: function (dateObj) {
168
+ const o = dateObj.getTimezoneOffset();
169
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
170
+ }
171
+ };
298
172
 
299
- if (typeof format !== 'string') {
300
- throw new Error('Invalid format in fecha.parse');
173
+ const parseFlags = {
174
+ d: [twoDigits, function (d, v) {
175
+ d.day = v;
176
+ }],
177
+ Do: [twoDigits + word, function (d, v) {
178
+ d.day = parseInt(v, 10);
179
+ }],
180
+ M: [twoDigits, function (d, v) {
181
+ d.month = v - 1;
182
+ }],
183
+ yy: [twoDigits, function (d, v) {
184
+ const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
185
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
186
+ }],
187
+ h: [twoDigits, function (d, v) {
188
+ d.hour = v;
189
+ }],
190
+ m: [twoDigits, function (d, v) {
191
+ d.minute = v;
192
+ }],
193
+ s: [twoDigits, function (d, v) {
194
+ d.second = v;
195
+ }],
196
+ yyyy: [fourDigits, function (d, v) {
197
+ d.year = v;
198
+ }],
199
+ S: ['\\d', function (d, v) {
200
+ d.millisecond = v * 100;
201
+ }],
202
+ SS: ['\\d{2}', function (d, v) {
203
+ d.millisecond = v * 10;
204
+ }],
205
+ SSS: [threeDigits, function (d, v) {
206
+ d.millisecond = v;
207
+ }],
208
+ D: [twoDigits, noop],
209
+ ddd: [word, noop],
210
+ MMM: [word, monthUpdate('monthNamesShort')],
211
+ MMMM: [word, monthUpdate('monthNames')],
212
+ a: [word, function (d, v, i18n) {
213
+ const val = v.toLowerCase();
214
+ if (val === i18n.amPm[0]) {
215
+ d.isPm = false;
216
+ } else if (val === i18n.amPm[1]) {
217
+ d.isPm = true;
301
218
  }
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;
219
+ }],
220
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
221
+ let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
222
+
223
+ if (parts) {
224
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
225
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
309
226
  }
227
+ }]
228
+ };
229
+ parseFlags.dd = parseFlags.d;
230
+ parseFlags.dddd = parseFlags.ddd;
231
+ parseFlags.DD = parseFlags.D;
232
+ parseFlags.mm = parseFlags.m;
233
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
234
+ parseFlags.MM = parseFlags.M;
235
+ parseFlags.ss = parseFlags.s;
236
+ parseFlags.A = parseFlags.a;
310
237
 
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
- }
238
+ // Some common format strings
239
+ fecha.masks = {
240
+ default: 'ddd MMM dd yyyy HH:mm:ss',
241
+ shortDate: 'M/D/yy',
242
+ mediumDate: 'MMM d, yyyy',
243
+ longDate: 'MMMM d, yyyy',
244
+ fullDate: 'dddd, MMMM d, yyyy',
245
+ shortTime: 'HH:mm',
246
+ mediumTime: 'HH:mm:ss',
247
+ longTime: 'HH:mm:ss.SSS'
248
+ };
334
249
 
335
- for (var i = 1; i < matches.length; i++) {
336
- parseInfo[i - 1](dateInfo, matches[i], i18n);
337
- }
250
+ /***
251
+ * Format a date
252
+ * @method format
253
+ * @param {Date|number} dateObj
254
+ * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
255
+ */
256
+ fecha.format = function (dateObj, mask, i18nSettings) {
257
+ const i18n = i18nSettings || fecha.i18n;
258
+
259
+ if (typeof dateObj === 'number') {
260
+ dateObj = new Date(dateObj);
261
+ }
262
+
263
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
264
+ throw new Error('Invalid Date in fecha.format');
265
+ }
266
+
267
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
268
+
269
+ const literals = [];
270
+
271
+ // Make literals inactive by replacing them with ??
272
+ mask = mask.replace(literal, function ($0, $1) {
273
+ literals.push($1);
274
+ return '@@@';
275
+ });
276
+ // Apply formatting rules
277
+ mask = mask.replace(token, function ($0) {
278
+ return $0 in formatFlags ? formatFlags[$0](dateObj, i18n) : $0.slice(1, $0.length - 1);
279
+ });
280
+ // Inline literal values back into the formatted value
281
+ return mask.replace(/@@@/g, function () {
282
+ return literals.shift();
283
+ });
284
+ };
338
285
 
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;
286
+ /**
287
+ * Parse a date string into an object, changes - into /
288
+ * @method parse
289
+ * @param {string} dateStr Date string
290
+ * @param {string} format Date parse format
291
+ * @returns {Date|boolean}
292
+ */
293
+ fecha.parse = function (dateStr, format, i18nSettings) {
294
+ const i18n = i18nSettings || fecha.i18n;
295
+
296
+ if (typeof format !== 'string') {
297
+ throw new Error('Invalid format in fecha.parse');
298
+ }
299
+
300
+ format = fecha.masks[format] || format;
301
+
302
+ // Avoid regular expression denial of service, fail early for really long strings
303
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
304
+ if (dateStr.length > 1000) {
305
+ return null;
306
+ }
307
+
308
+ const dateInfo = {};
309
+ const parseInfo = [];
310
+ const literals = [];
311
+ format = format.replace(literal, function ($0, $1) {
312
+ literals.push($1);
313
+ return '@@@';
314
+ });
315
+ const newFormat = regexEscape(format).replace(token, function ($0) {
316
+ if (parseFlags[$0]) {
317
+ const info = parseFlags[$0];
318
+ parseInfo.push(info[1]);
319
+ return '(' + info[0] + ')';
344
320
  }
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,
321
+
322
+ return $0;
323
+ });
324
+ const matches = dateStr.match(new RegExp(newFormat, 'i'));
325
+ if (!matches) {
326
+ return null;
327
+ }
328
+
329
+ for (let i = 1; i < matches.length; i++) {
330
+ parseInfo[i - 1](dateInfo, matches[i], i18n);
331
+ }
332
+
333
+ const today = new Date();
334
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
335
+ dateInfo.hour = +dateInfo.hour + 12;
336
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
337
+ dateInfo.hour = 0;
338
+ }
339
+
340
+ let date;
341
+ if (dateInfo.timezoneOffset != null) {
342
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
343
+ date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
350
344
  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
345
  } else {
366
- main.fecha = fecha;
346
+ date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
347
+ dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
367
348
  }
368
- })(this);
349
+ return date;
350
+ };
351
+
352
+ export default fecha;