@haluo/util 2.0.0 → 2.0.2-0.1

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 (89) hide show
  1. package/README.md +12 -1
  2. package/dist/index.d.ts +39 -0
  3. package/dist/index.js +74 -33
  4. package/dist/modules/cookie/index.d.ts +27 -0
  5. package/dist/modules/cookie/index.js +55 -54
  6. package/dist/modules/date/index.d.ts +52 -0
  7. package/dist/modules/date/index.js +192 -192
  8. package/dist/modules/dom/index.d.ts +28 -0
  9. package/dist/modules/dom/index.js +62 -62
  10. package/dist/modules/filter/index.d.ts +24 -0
  11. package/dist/modules/filter/index.js +48 -44
  12. package/dist/modules/format/index.d.ts +15 -0
  13. package/dist/modules/format/index.js +22 -21
  14. package/dist/modules/match/index.d.ts +12 -0
  15. package/dist/modules/match/index.js +31 -31
  16. package/dist/modules/monitor/index.d.ts +3 -0
  17. package/dist/modules/monitor/index.js +17 -17
  18. package/dist/modules/monitor/lib/jsError.d.ts +1 -0
  19. package/dist/modules/monitor/lib/jsError.js +53 -53
  20. package/dist/modules/monitor/lib/timing.d.ts +1 -0
  21. package/dist/modules/monitor/lib/timing.js +69 -69
  22. package/dist/modules/monitor/lib/xhr.d.ts +1 -0
  23. package/dist/modules/monitor/lib/xhr.js +48 -48
  24. package/dist/modules/monitor/utils/onload.d.ts +1 -0
  25. package/dist/modules/monitor/utils/onload.js +11 -11
  26. package/dist/modules/monitor/utils/tracker.d.ts +7 -0
  27. package/dist/modules/monitor/utils/tracker.js +63 -63
  28. package/dist/modules/number/index.d.ts +47 -0
  29. package/dist/modules/number/index.js +118 -102
  30. package/dist/modules/open-app/index.d.ts +84 -0
  31. package/dist/modules/open-app/index.js +239 -0
  32. package/dist/modules/sentry/index.d.ts +15 -0
  33. package/dist/modules/sentry/index.js +81 -81
  34. package/dist/modules/tools/index.d.ts +166 -0
  35. package/dist/modules/tools/index.js +393 -393
  36. package/dist/modules/upload/ALIOSS_EXAMPLE.d.ts +12 -0
  37. package/dist/modules/upload/ALIOSS_EXAMPLE.js +320 -0
  38. package/dist/modules/upload/aliOss.d.ts +324 -0
  39. package/dist/modules/upload/aliOss.js +838 -0
  40. package/dist/modules/upload/index.d.ts +51 -0
  41. package/dist/modules/upload/index.js +55 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -0
  43. package/dist/types/index.d.ts +3 -0
  44. package/dist/types/index.js +2 -0
  45. package/dist/types/modules/cookie/index.d.ts +27 -0
  46. package/dist/types/modules/date/index.d.ts +52 -0
  47. package/dist/types/modules/dom/index.d.ts +28 -0
  48. package/dist/types/modules/filter/index.d.ts +24 -0
  49. package/dist/types/modules/format/index.d.ts +15 -0
  50. package/dist/types/modules/match/index.d.ts +12 -0
  51. package/dist/types/modules/monitor/index.d.ts +3 -0
  52. package/dist/types/modules/monitor/lib/jsError.d.ts +1 -0
  53. package/dist/types/modules/monitor/lib/timing.d.ts +1 -0
  54. package/dist/types/modules/monitor/lib/xhr.d.ts +1 -0
  55. package/dist/types/modules/monitor/utils/onload.d.ts +1 -0
  56. package/dist/types/modules/monitor/utils/tracker.d.ts +7 -0
  57. package/dist/types/modules/number/index.d.ts +41 -0
  58. package/dist/types/modules/sentry/index.d.ts +15 -0
  59. package/dist/types/modules/tools/index.d.ts +166 -0
  60. package/dist/types/types/index.d.ts +3 -0
  61. package/package.json +18 -13
  62. package/.babelrc +0 -21
  63. package/.eslintrc.js +0 -216
  64. package/__tests__/unit/date/date.spec.js +0 -14
  65. package/__tests__/unit/jest.conf.js +0 -25
  66. package/__tests__/unit/specs/date.test.js +0 -11
  67. package/global.d.ts +0 -0
  68. package/publish.sh +0 -11
  69. package/specification/CSS.md +0 -25
  70. package/specification/JS.md +0 -9
  71. package/specification/VUE.md +0 -1
  72. package/src/consts/httpCode.js +0 -10
  73. package/src/index.ts +0 -51
  74. package/src/modules/cookie/index.ts +0 -69
  75. package/src/modules/date/index.ts +0 -196
  76. package/src/modules/dom/index.ts +0 -78
  77. package/src/modules/filter/index.ts +0 -43
  78. package/src/modules/format/index.ts +0 -19
  79. package/src/modules/match/index.ts +0 -31
  80. package/src/modules/monitor/index.ts +0 -13
  81. package/src/modules/monitor/lib/jsError.ts +0 -57
  82. package/src/modules/monitor/lib/timing.ts +0 -75
  83. package/src/modules/monitor/lib/xhr.ts +0 -40
  84. package/src/modules/monitor/utils/onload.ts +0 -8
  85. package/src/modules/monitor/utils/tracker.ts +0 -47
  86. package/src/modules/number/index.ts +0 -108
  87. package/src/modules/sentry/index.ts +0 -82
  88. package/src/modules/tools/index.ts +0 -427
  89. package/tsconfig.json +0 -34
@@ -1,192 +1,192 @@
1
- /**
2
- * @file date 格式化
3
- * @Author: wanghui
4
- * @createBy: @2020.05.21
5
- */
6
- 'use strict';
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- /**
9
- * 格式化时间 详情内容里的时间格式
10
- * @param {Object} data 格式,可参考format 中的o属性
11
- * @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
12
- * @return 返回fmt 格式 时间
13
- */
14
- function replacementDate(data, fmt) {
15
- for (var k in data) {
16
- if (new RegExp('(' + k + ')').test(fmt)) {
17
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (data[k]) : (("00".concat(data[k])).substr(('' + data[k]).length)));
18
- }
19
- }
20
- return fmt;
21
- }
22
- /**
23
- * 格式化年份
24
- * @param {String} date Date 格式
25
- * @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
26
- * @return 仅返回年份
27
- */
28
- function replacementYear(date, fmt) {
29
- if (/(Y+)/.test(fmt)) {
30
- fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
31
- }
32
- return fmt;
33
- }
34
- var DateClass = /** @class */ (function () {
35
- function DateClass() {
36
- }
37
- /**
38
- * 格式化时间
39
- * @param {String|Number} date 需要格式化的时间 2017-11-11、2017/11/11、linux time
40
- * @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
41
- * date.format(new Date()) // 默认格式 'YYYY-MM-DD HH:mm:ss'
42
- * date.format(1586840260500) // 默认格式,传参为linux时间
43
- * date.format(new Date(), 'YYYY:MM:DD') // 自定义格式 'YYYY:MM:DD'
44
- * @return {String} fmt 'YYYY-MM-DD HH:mm:ss'
45
- */
46
- DateClass.prototype.format = function (date, fmt) {
47
- if (fmt === void 0) { fmt = 'YYYY-MM-DD HH:mm:ss'; }
48
- if (!date)
49
- return '';
50
- var timeData = typeof date === 'string' ? new Date(date.replace(/-/g, '/')) : date;
51
- timeData = typeof date === 'number' ? new Date(date) : timeData;
52
- var o = {
53
- 'M+': timeData.getMonth() + 1,
54
- 'D+': timeData.getDate(),
55
- 'h+': timeData.getHours() % 12 === 0 ? 12 : timeData.getHours() % 12,
56
- 'H+': timeData.getHours(),
57
- 'm+': timeData.getMinutes(),
58
- 's+': timeData.getSeconds(),
59
- 'q+': Math.floor((timeData.getMonth() + 3) / 3),
60
- 'S': timeData.getMilliseconds()
61
- };
62
- var week = {
63
- '0': '\u65e5',
64
- '1': '\u4e00',
65
- '2': '\u4e8c',
66
- '3': '\u4e09',
67
- '4': '\u56db',
68
- '5': '\u4e94',
69
- '6': '\u516d'
70
- };
71
- fmt = replacementYear(timeData, fmt);
72
- if (/(E+)/.test(fmt)) {
73
- fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\u661f\u671f' : '\u5468') : '') + week["".concat(timeData.getDay(), " ")]);
74
- }
75
- return replacementDate(o, fmt);
76
- };
77
- /**
78
- * 天数加减
79
- * @param {string | Date} date 传入的时间 2020-10-15 or Date
80
- * @param {String} days 天数
81
- * addDaysToDate('2020-10-15', 10) // '2020-10-25'
82
- * addDaysToDate('2020-10-15', -10) // '2020-10-05'
83
- * @return {String} fmt 'YYYY-MM-DD'
84
- */
85
- DateClass.prototype.addDaysToDate = function (date, days) {
86
- var d = typeof date === 'object' ? date : new Date(date);
87
- d.setDate(d.getDate() + days);
88
- return d.toISOString().split('T')[0];
89
- };
90
- /**
91
- * 获取倒计时剩余时间
92
- * @param {Date | Number} endTime 截止时间
93
- * @param {Date | Number} startTime 开始时间,默认取客户端当前时间
94
- * date.format(new Date()) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
95
- * date.format(1586840260500) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
96
- * @return {object | boolean} {dd: '天', hh: '时', mm: '分', ss: '秒'}
97
- */
98
- DateClass.prototype.remainTime = function (endTime, startTime) {
99
- if (startTime === void 0) { startTime = new Date(); }
100
- var ts = Number(endTime) - Number(startTime); // 计算剩余的毫秒数
101
- var dd = Math.floor(ts / 1000 / 60 / 60 / 24); // 计算剩余的天数
102
- var hh = Math.floor(ts / 1000 / 60 / 60 % 24); // 计算剩余的小时数
103
- var mm = Math.floor(ts / 1000 / 60 % 60); // 计算剩余的分钟数
104
- var ss = Math.floor(ts / 1000 % 60); // 计算剩余的秒数
105
- if (ts <= 0)
106
- return false;
107
- return {
108
- dd: (dd < 10 ? "0".concat(dd) : dd),
109
- hh: (hh < 10 ? "0".concat(hh) : hh),
110
- mm: (mm < 10 ? "0".concat(mm) : mm),
111
- ss: (ss < 10 ? "0".concat(ss) : ss)
112
- };
113
- };
114
- /**
115
- * 格式化现在的已过时间
116
- * @param {Number} startTime
117
- * @return {String} *年前 *个月前 *天前 *小时前 *分钟前 刚刚
118
- */
119
- DateClass.prototype.formatPassTime = function (startTime) {
120
- var currentTime = new Date();
121
- var time = currentTime - startTime;
122
- var year = Math.floor(time / (1000 * 60 * 60 * 24) / 30 / 12);
123
- if (year)
124
- return "".concat(year, "\u5E74\u524D");
125
- var month = Math.floor(time / (1000 * 60 * 60 * 24) / 30);
126
- if (month)
127
- return "".concat(month, "\u4E2A\u6708\u524D");
128
- var day = Math.floor(time / (1000 * 60 * 60 * 24));
129
- if (day)
130
- return "".concat(day, "\u5929\u524D");
131
- var hour = Math.floor(time / (1000 * 60 * 60));
132
- if (hour)
133
- return "".concat(hour, "\u5C0F\u65F6\u524D");
134
- var min = Math.floor(time / (1000 * 60));
135
- if (min)
136
- return "".concat(min, "\u5206\u949F\u524D");
137
- else
138
- return '刚刚';
139
- };
140
- /**
141
- * 格式化时间 列表里的时间内容格式 待废弃,统一时间格式
142
- * @param {Number} time 1494141000*1000
143
- * @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
144
- */
145
- DateClass.prototype.formatPassTimeForList = function (time) {
146
- return DateClass.prototype.formatPassTimeForDetail(time, 'YYYY年MM月DD日', true);
147
- };
148
- /**
149
- * 格式化时间 详情内容里的时间格式
150
- * @param {Number} time 1494141000*1000
151
- * @param {String} fmt 想要格式化的格式
152
- * @param {Boolean} noYear 是否显示年
153
- * @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
154
- */
155
- DateClass.prototype.formatPassTimeForDetail = function (time, fmt, noYear) {
156
- if (fmt === void 0) { fmt = 'YYYY-MM-DD'; }
157
- var date = (typeof time === 'number') ? new Date(time) : new Date((time || '').replace(/-/g, '/'));
158
- var diff = (((new Date()).getTime() - date.getTime()) / 1000);
159
- var dayDiff = Math.floor(diff / 86400);
160
- var isValidDate = Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime());
161
- if (!isValidDate)
162
- return '';
163
- var formatDate = function () {
164
- var today = new Date(date);
165
- var o = {
166
- 'Y+': today.getFullYear(),
167
- 'M+': ('0' + (today.getMonth() + 1)).slice(-2),
168
- 'D+': ('0' + today.getDate()).slice(-2)
169
- };
170
- fmt = replacementYear(date, fmt);
171
- var year = today.getFullYear();
172
- if (!(new Date().getFullYear() > year) && noYear) {
173
- var backData = replacementDate(o, fmt);
174
- return backData.split('年')[1];
175
- }
176
- return replacementDate(o, fmt);
177
- };
178
- if (dayDiff === -1) {
179
- return '刚刚';
180
- }
181
- else if (isNaN(dayDiff) || dayDiff < 0 || dayDiff >= 15) {
182
- return formatDate();
183
- }
184
- return (dayDiff === 0 && ((diff < 60 && '刚刚') ||
185
- (diff < 120 && '1分钟前') ||
186
- (diff < 3600 && Math.floor(diff / 60) + '分钟前') ||
187
- (diff < 7200 && '1小时前') ||
188
- (diff < 86400 && Math.floor(diff / 3600) + '小时前'))) || (dayDiff < 16 && dayDiff + '天前');
189
- };
190
- return DateClass;
191
- }());
192
- module.exports = new DateClass();
1
+ /**
2
+ * @file date 格式化
3
+ * @Author: wanghui
4
+ * @createBy: @2020.05.21
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ /**
9
+ * 格式化时间 详情内容里的时间格式
10
+ * @param {Object} data 格式,可参考format 中的o属性
11
+ * @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
12
+ * @return 返回fmt 格式 时间
13
+ */
14
+ function replacementDate(data, fmt) {
15
+ for (var k in data) {
16
+ if (new RegExp('(' + k + ')').test(fmt)) {
17
+ fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (data[k]) : (("00".concat(data[k])).substr(('' + data[k]).length)));
18
+ }
19
+ }
20
+ return fmt;
21
+ }
22
+ /**
23
+ * 格式化年份
24
+ * @param {String} date Date 格式
25
+ * @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
26
+ * @return 仅返回年份
27
+ */
28
+ function replacementYear(date, fmt) {
29
+ if (/(Y+)/.test(fmt)) {
30
+ fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
31
+ }
32
+ return fmt;
33
+ }
34
+ var DateClass = /** @class */ (function () {
35
+ function DateClass() {
36
+ }
37
+ /**
38
+ * 格式化时间
39
+ * @param {String|Number} date 需要格式化的时间 2017-11-11、2017/11/11、linux time
40
+ * @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
41
+ * date.format(new Date()) // 默认格式 'YYYY-MM-DD HH:mm:ss'
42
+ * date.format(1586840260500) // 默认格式,传参为linux时间
43
+ * date.format(new Date(), 'YYYY:MM:DD') // 自定义格式 'YYYY:MM:DD'
44
+ * @return {String} fmt 'YYYY-MM-DD HH:mm:ss'
45
+ */
46
+ DateClass.prototype.format = function (date, fmt) {
47
+ if (fmt === void 0) { fmt = 'YYYY-MM-DD HH:mm:ss'; }
48
+ if (!date)
49
+ return '';
50
+ var timeData = typeof date === 'string' ? new Date(date.replace(/-/g, '/')) : date;
51
+ timeData = typeof date === 'number' ? new Date(date) : timeData;
52
+ var o = {
53
+ 'M+': timeData.getMonth() + 1,
54
+ 'D+': timeData.getDate(),
55
+ 'h+': timeData.getHours() % 12 === 0 ? 12 : timeData.getHours() % 12,
56
+ 'H+': timeData.getHours(),
57
+ 'm+': timeData.getMinutes(),
58
+ 's+': timeData.getSeconds(),
59
+ 'q+': Math.floor((timeData.getMonth() + 3) / 3),
60
+ 'S': timeData.getMilliseconds()
61
+ };
62
+ var week = {
63
+ '0': '\u65e5',
64
+ '1': '\u4e00',
65
+ '2': '\u4e8c',
66
+ '3': '\u4e09',
67
+ '4': '\u56db',
68
+ '5': '\u4e94',
69
+ '6': '\u516d'
70
+ };
71
+ fmt = replacementYear(timeData, fmt);
72
+ if (/(E+)/.test(fmt)) {
73
+ fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\u661f\u671f' : '\u5468') : '') + week["".concat(timeData.getDay(), " ")]);
74
+ }
75
+ return replacementDate(o, fmt);
76
+ };
77
+ /**
78
+ * 天数加减
79
+ * @param {string | Date} date 传入的时间 2020-10-15 or Date
80
+ * @param {String} days 天数
81
+ * addDaysToDate('2020-10-15', 10) // '2020-10-25'
82
+ * addDaysToDate('2020-10-15', -10) // '2020-10-05'
83
+ * @return {String} fmt 'YYYY-MM-DD'
84
+ */
85
+ DateClass.prototype.addDaysToDate = function (date, days) {
86
+ var d = typeof date === 'object' ? date : new Date(date);
87
+ d.setDate(d.getDate() + days);
88
+ return d.toISOString().split('T')[0];
89
+ };
90
+ /**
91
+ * 获取倒计时剩余时间
92
+ * @param {Date | Number} endTime 截止时间
93
+ * @param {Date | Number} startTime 开始时间,默认取客户端当前时间
94
+ * date.format(new Date()) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
95
+ * date.format(1586840260500) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
96
+ * @return {object | boolean} {dd: '天', hh: '时', mm: '分', ss: '秒'}
97
+ */
98
+ DateClass.prototype.remainTime = function (endTime, startTime) {
99
+ if (startTime === void 0) { startTime = new Date(); }
100
+ var ts = Number(endTime) - Number(startTime); // 计算剩余的毫秒数
101
+ var dd = Math.floor(ts / 1000 / 60 / 60 / 24); // 计算剩余的天数
102
+ var hh = Math.floor(ts / 1000 / 60 / 60 % 24); // 计算剩余的小时数
103
+ var mm = Math.floor(ts / 1000 / 60 % 60); // 计算剩余的分钟数
104
+ var ss = Math.floor(ts / 1000 % 60); // 计算剩余的秒数
105
+ if (ts <= 0)
106
+ return false;
107
+ return {
108
+ dd: (dd < 10 ? "0".concat(dd) : dd),
109
+ hh: (hh < 10 ? "0".concat(hh) : hh),
110
+ mm: (mm < 10 ? "0".concat(mm) : mm),
111
+ ss: (ss < 10 ? "0".concat(ss) : ss)
112
+ };
113
+ };
114
+ /**
115
+ * 格式化现在的已过时间
116
+ * @param {Number} startTime
117
+ * @return {String} *年前 *个月前 *天前 *小时前 *分钟前 刚刚
118
+ */
119
+ DateClass.prototype.formatPassTime = function (startTime) {
120
+ var currentTime = new Date();
121
+ var time = currentTime - startTime;
122
+ var year = Math.floor(time / (1000 * 60 * 60 * 24) / 30 / 12);
123
+ if (year)
124
+ return "".concat(year, "\u5E74\u524D");
125
+ var month = Math.floor(time / (1000 * 60 * 60 * 24) / 30);
126
+ if (month)
127
+ return "".concat(month, "\u4E2A\u6708\u524D");
128
+ var day = Math.floor(time / (1000 * 60 * 60 * 24));
129
+ if (day)
130
+ return "".concat(day, "\u5929\u524D");
131
+ var hour = Math.floor(time / (1000 * 60 * 60));
132
+ if (hour)
133
+ return "".concat(hour, "\u5C0F\u65F6\u524D");
134
+ var min = Math.floor(time / (1000 * 60));
135
+ if (min)
136
+ return "".concat(min, "\u5206\u949F\u524D");
137
+ else
138
+ return '刚刚';
139
+ };
140
+ /**
141
+ * 格式化时间 列表里的时间内容格式 待废弃,统一时间格式
142
+ * @param {Number} time 1494141000*1000
143
+ * @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
144
+ */
145
+ DateClass.prototype.formatPassTimeForList = function (time) {
146
+ return DateClass.prototype.formatPassTimeForDetail(time, 'YYYY年MM月DD日', true);
147
+ };
148
+ /**
149
+ * 格式化时间 详情内容里的时间格式
150
+ * @param {Number} time 1494141000*1000
151
+ * @param {String} fmt 想要格式化的格式
152
+ * @param {Boolean} noYear 是否显示年
153
+ * @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
154
+ */
155
+ DateClass.prototype.formatPassTimeForDetail = function (time, fmt, noYear) {
156
+ if (fmt === void 0) { fmt = 'YYYY-MM-DD'; }
157
+ var date = (typeof time === 'number') ? new Date(time) : new Date((time || '').replace(/-/g, '/'));
158
+ var diff = (((new Date()).getTime() - date.getTime()) / 1000);
159
+ var dayDiff = Math.floor(diff / 86400);
160
+ var isValidDate = Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime());
161
+ if (!isValidDate)
162
+ return '';
163
+ var formatDate = function () {
164
+ var today = new Date(date);
165
+ var o = {
166
+ 'Y+': today.getFullYear(),
167
+ 'M+': ('0' + (today.getMonth() + 1)).slice(-2),
168
+ 'D+': ('0' + today.getDate()).slice(-2)
169
+ };
170
+ fmt = replacementYear(date, fmt);
171
+ var year = today.getFullYear();
172
+ if (!(new Date().getFullYear() > year) && noYear) {
173
+ var backData = replacementDate(o, fmt);
174
+ return backData.split('年')[1];
175
+ }
176
+ return replacementDate(o, fmt);
177
+ };
178
+ if (dayDiff === -1) {
179
+ return '刚刚';
180
+ }
181
+ else if (isNaN(dayDiff) || dayDiff < 0 || dayDiff >= 15) {
182
+ return formatDate();
183
+ }
184
+ return (dayDiff === 0 && ((diff < 60 && '刚刚') ||
185
+ (diff < 120 && '1分钟前') ||
186
+ (diff < 3600 && Math.floor(diff / 60) + '分钟前') ||
187
+ (diff < 7200 && '1小时前') ||
188
+ (diff < 86400 && Math.floor(diff / 3600) + '小时前'))) || (dayDiff < 16 && dayDiff + '天前');
189
+ };
190
+ return DateClass;
191
+ }());
192
+ exports.default = new DateClass();
@@ -0,0 +1,28 @@
1
+ import { IObjectKey } from '../../types/index';
2
+ interface IDom {
3
+ name: string;
4
+ innerHTML?: string;
5
+ style?: IObjectKey<string>;
6
+ parent?: string;
7
+ }
8
+ declare class DomClass {
9
+ /**
10
+ * 创建一个子元素并添加至父节点
11
+ * @param {Object} { name = 'div', innerHTML = '', style = {}, parent, }
12
+ * @return {String}
13
+ */
14
+ createElement({ name, innerHTML, style, parent, }: IDom): any;
15
+ /**
16
+ * 获取文本中的url并用a标签包裹
17
+ * @param {Object} ICookie
18
+ */
19
+ wrapperA(text: string): string | Error;
20
+ /**
21
+ * 对象转化为formdata
22
+ * getFormData({a: 1, b: 2})
23
+ * @param {Object} object
24
+ */
25
+ getFormData(object: IObjectKey<any>): FormData;
26
+ }
27
+ declare const _default: DomClass;
28
+ export default _default;
@@ -1,62 +1,62 @@
1
- /**
2
- * @file Cookie
3
- * @Author: wanghui
4
- * @createBy: @2021.08.17
5
- */
6
- 'use strict';
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- var DomClass = /** @class */ (function () {
9
- function DomClass() {
10
- }
11
- /**
12
- * 创建一个子元素并添加至父节点
13
- * @param {Object} { name = 'div', innerHTML = '', style = {}, parent, }
14
- * @return {String}
15
- */
16
- DomClass.prototype.createElement = function (_a) {
17
- var _b = _a.name, name = _b === void 0 ? 'div' : _b, _c = _a.innerHTML, innerHTML = _c === void 0 ? '' : _c, _d = _a.style, style = _d === void 0 ? {} : _d, parent = _a.parent;
18
- if (!(window && window.document)) {
19
- return new Error('仅支持浏览器');
20
- }
21
- var element = document.createElement(name);
22
- element.innerHTML = innerHTML;
23
- Object.keys(style).map(function (_) { return element.style[_] = style[_]; });
24
- if (parent) {
25
- var body = document.querySelector(parent);
26
- body && body.append(element);
27
- }
28
- return element;
29
- };
30
- /**
31
- * 获取文本中的url并用a标签包裹
32
- * @param {Object} ICookie
33
- */
34
- DomClass.prototype.wrapperA = function (text) {
35
- if (!(window && window.document)) {
36
- return new Error('仅支持浏览器');
37
- }
38
- return text.replace(/((https|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])/g, '<a href="$1">$1</a>');
39
- };
40
- /**
41
- * 对象转化为formdata
42
- * getFormData({a: 1, b: 2})
43
- * @param {Object} object
44
- */
45
- DomClass.prototype.getFormData = function (object) {
46
- var formData = new FormData();
47
- Object.keys(object).forEach(function (key) {
48
- var value = object[key];
49
- if (Array.isArray(value)) {
50
- value.forEach(function (subValue, i) {
51
- return formData.append(key + "[".concat(i, "]"), subValue);
52
- });
53
- }
54
- else {
55
- formData.append(key, object[key]);
56
- }
57
- });
58
- return formData;
59
- };
60
- return DomClass;
61
- }());
62
- module.exports = new DomClass();
1
+ /**
2
+ * @file Cookie
3
+ * @Author: wanghui
4
+ * @createBy: @2021.08.17
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ var DomClass = /** @class */ (function () {
9
+ function DomClass() {
10
+ }
11
+ /**
12
+ * 创建一个子元素并添加至父节点
13
+ * @param {Object} { name = 'div', innerHTML = '', style = {}, parent, }
14
+ * @return {String}
15
+ */
16
+ DomClass.prototype.createElement = function (_a) {
17
+ var _b = _a.name, name = _b === void 0 ? 'div' : _b, _c = _a.innerHTML, innerHTML = _c === void 0 ? '' : _c, _d = _a.style, style = _d === void 0 ? {} : _d, parent = _a.parent;
18
+ if (!(window && window.document)) {
19
+ return new Error('仅支持浏览器');
20
+ }
21
+ var element = document.createElement(name);
22
+ element.innerHTML = innerHTML;
23
+ Object.keys(style).map(function (_) { return element.style[_] = style[_]; });
24
+ if (parent) {
25
+ var body = document.querySelector(parent);
26
+ body && body.append(element);
27
+ }
28
+ return element;
29
+ };
30
+ /**
31
+ * 获取文本中的url并用a标签包裹
32
+ * @param {Object} ICookie
33
+ */
34
+ DomClass.prototype.wrapperA = function (text) {
35
+ if (!(window && window.document)) {
36
+ return new Error('仅支持浏览器');
37
+ }
38
+ return text.replace(/((https|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])/g, '<a href="$1">$1</a>');
39
+ };
40
+ /**
41
+ * 对象转化为formdata
42
+ * getFormData({a: 1, b: 2})
43
+ * @param {Object} object
44
+ */
45
+ DomClass.prototype.getFormData = function (object) {
46
+ var formData = new FormData();
47
+ Object.keys(object).forEach(function (key) {
48
+ var value = object[key];
49
+ if (Array.isArray(value)) {
50
+ value.forEach(function (subValue, i) {
51
+ return formData.append(key + "[".concat(i, "]"), subValue);
52
+ });
53
+ }
54
+ else {
55
+ formData.append(key, object[key]);
56
+ }
57
+ });
58
+ return formData;
59
+ };
60
+ return DomClass;
61
+ }());
62
+ exports.default = new DomClass();
@@ -0,0 +1,24 @@
1
+ declare class FilterClass {
2
+ /**
3
+ * 格式化时间,示例:1586840260500 | format('YYYY-MM-DD HH:mm:ss')
4
+ * @param {String|Number} date
5
+ * @param {String} fmt 'YYYY-MM-DD HH:mm:ss'
6
+ * @return {String} 'YYYY-MM-DD HH:mm:ss'
7
+ */
8
+ format(date: string | number, fmt?: string): string;
9
+ /**
10
+ * 格式化金额,示例:123456 | formatMoney
11
+ * @param {Number} num
12
+ * @return {String} 123,456
13
+ */
14
+ formatMoney(money: number | string): string;
15
+ /**
16
+ * 截取数组或字符串,示例:'1234' | slice(3)
17
+ * @param {Array|String} target 数组或字符串
18
+ * @param {Number} length 截取长度,从0开始
19
+ * @return {any}
20
+ */
21
+ slice(target?: Array<any> | string, length?: number): string | any[];
22
+ }
23
+ declare const _default: FilterClass;
24
+ export default _default;