@haluo/util 2.0.5 → 2.0.7

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 (50) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs.js +89 -0
  3. package/dist/index.d.ts +12 -0
  4. package/dist/index.esm.js +87 -0
  5. package/dist/index.js +36 -50
  6. package/dist/lib-list.d.ts +2 -0
  7. package/dist/modules/cookie/index.d.ts +27 -0
  8. package/dist/modules/cookie/index.js +54 -55
  9. package/dist/modules/date/index.d.ts +1 -0
  10. package/dist/modules/date/index.js +192 -192
  11. package/dist/modules/dom/index.d.ts +1 -0
  12. package/dist/modules/dom/index.js +62 -62
  13. package/dist/modules/filter/index.d.ts +26 -0
  14. package/dist/modules/filter/index.js +57 -48
  15. package/dist/modules/format/index.d.ts +13 -0
  16. package/dist/modules/format/index.js +21 -22
  17. package/dist/modules/match/index.d.ts +1 -0
  18. package/dist/modules/match/index.js +31 -31
  19. package/dist/modules/monitor/index.js +17 -17
  20. package/dist/modules/monitor/lib/jsError.js +61 -53
  21. package/dist/modules/monitor/lib/timing.js +69 -69
  22. package/dist/modules/monitor/lib/xhr.js +50 -48
  23. package/dist/modules/monitor/utils/onload.js +11 -11
  24. package/dist/modules/monitor/utils/tracker.js +84 -63
  25. package/dist/modules/number/index.d.ts +39 -0
  26. package/dist/modules/number/index.js +102 -103
  27. package/dist/modules/sentry/index.d.ts +15 -0
  28. package/dist/modules/sentry/index.js +78 -81
  29. package/dist/modules/tools/index.d.ts +1 -0
  30. package/dist/modules/tools/index.js +393 -393
  31. package/dist/tsconfig.tsbuildinfo +2915 -1
  32. package/dist/types/index.d.ts +11 -32
  33. package/dist/types/index.js +2 -2
  34. package/dist/types/modules/cookie/index.d.ts +25 -27
  35. package/dist/types/modules/date/index.d.ts +1 -52
  36. package/dist/types/modules/dom/index.d.ts +1 -28
  37. package/dist/types/modules/filter/index.d.ts +26 -24
  38. package/dist/types/modules/format/index.d.ts +13 -15
  39. package/dist/types/modules/match/index.d.ts +1 -12
  40. package/dist/types/modules/monitor/index.d.ts +3 -3
  41. package/dist/types/modules/monitor/lib/jsError.d.ts +1 -1
  42. package/dist/types/modules/monitor/lib/timing.d.ts +1 -1
  43. package/dist/types/modules/monitor/lib/xhr.d.ts +1 -1
  44. package/dist/types/modules/monitor/utils/onload.d.ts +1 -1
  45. package/dist/types/modules/monitor/utils/tracker.d.ts +8 -7
  46. package/dist/types/modules/number/index.d.ts +39 -41
  47. package/dist/types/modules/sentry/index.d.ts +15 -15
  48. package/dist/types/modules/tools/index.d.ts +1 -166
  49. package/dist/types/types/index.d.ts +3 -3
  50. package/package.json +2 -2
@@ -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
- exports.default = 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" + 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[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" + dd : dd),
109
+ hh: (hh < 10 ? "0" + hh : hh),
110
+ mm: (mm < 10 ? "0" + mm : mm),
111
+ ss: (ss < 10 ? "0" + 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 year + "\u5E74\u524D";
125
+ var month = Math.floor(time / (1000 * 60 * 60 * 24) / 30);
126
+ if (month)
127
+ return month + "\u4E2A\u6708\u524D";
128
+ var day = Math.floor(time / (1000 * 60 * 60 * 24));
129
+ if (day)
130
+ return day + "\u5929\u524D";
131
+ var hour = Math.floor(time / (1000 * 60 * 60));
132
+ if (hour)
133
+ return hour + "\u5C0F\u65F6\u524D";
134
+ var min = Math.floor(time / (1000 * 60));
135
+ if (min)
136
+ return 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();
@@ -0,0 +1 @@
1
+ export {};
@@ -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
- exports.default = 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 + ("[" + 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();
@@ -0,0 +1,26 @@
1
+ declare const dateClass: any;
2
+ declare const numberClass: any;
3
+ declare const toolsClass: any;
4
+ declare class FilterClass {
5
+ /**
6
+ * 格式化时间,示例:1586840260500 | format('YYYY-MM-DD HH:mm:ss')
7
+ * @param {String|Number} date
8
+ * @param {String} fmt 'YYYY-MM-DD HH:mm:ss'
9
+ * @return {String} 'YYYY-MM-DD HH:mm:ss'
10
+ */
11
+ format(date: string | number, fmt?: string): any;
12
+ /**
13
+ * 格式化金额,示例:123456 | formatMoney
14
+ * @param {Number} num
15
+ * @return {String} 123,456
16
+ */
17
+ formatMoney(money: number | string): string;
18
+ /**
19
+ * 截取数组或字符串,示例:'1234' | slice(3)
20
+ * @param {Array|String} target 数组或字符串
21
+ * @param {Number} length 截取长度,从0开始
22
+ * @return {any}
23
+ */
24
+ slice(target?: Array<any> | string, length?: number): any;
25
+ install(app: any): void;
26
+ }
@@ -1,48 +1,57 @@
1
- /**
2
- * @file 过滤器
3
- * @Author: wanghui
4
- * @createBy: @2020.05.28
5
- */
6
- 'use strict';
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- var date_1 = __importDefault(require("../date"));
12
- var number_1 = __importDefault(require("../number"));
13
- var tools_1 = __importDefault(require("../tools"));
14
- var FilterClass = /** @class */ (function () {
15
- function FilterClass() {
16
- }
17
- /**
18
- * 格式化时间,示例:1586840260500 | format('YYYY-MM-DD HH:mm:ss')
19
- * @param {String|Number} date
20
- * @param {String} fmt 'YYYY-MM-DD HH:mm:ss'
21
- * @return {String} 'YYYY-MM-DD HH:mm:ss'
22
- */
23
- FilterClass.prototype.format = function (date, fmt) {
24
- if (fmt === void 0) { fmt = 'YYYY-MM-DD HH:mm:ss'; }
25
- return date_1.default.format(date, fmt);
26
- };
27
- /**
28
- * 格式化金额,示例:123456 | formatMoney
29
- * @param {Number} num
30
- * @return {String} 123,456
31
- */
32
- FilterClass.prototype.formatMoney = function (money) {
33
- return number_1.default.formatMoney(money);
34
- };
35
- /**
36
- * 截取数组或字符串,示例:'1234' | slice(3)
37
- * @param {Array|String} target 数组或字符串
38
- * @param {Number} length 截取长度,从0开始
39
- * @return {any}
40
- */
41
- FilterClass.prototype.slice = function (target, length) {
42
- if (target === void 0) { target = ''; }
43
- if (length === void 0) { length = 0; }
44
- return tools_1.default.slice(target, length);
45
- };
46
- return FilterClass;
47
- }());
48
- exports.default = new FilterClass();
1
+ /**
2
+ * @file 过滤器
3
+ * @Author: wanghui
4
+ * @createBy: @2020.05.28
5
+ */
6
+ /**
7
+ * 示例:注入所有过滤器
8
+ * import { filter as filters } from '@haluo/util'
9
+ * Object.keys(filters).forEach(key => {
10
+ * Vue.filter(key, filters[key])
11
+ * })
12
+ */
13
+ 'use strict';
14
+ var dateClass = require('../date');
15
+ var numberClass = require('../number');
16
+ var toolsClass = require('../tools');
17
+ var FilterClass = /** @class */ (function () {
18
+ function FilterClass() {
19
+ }
20
+ /**
21
+ * 格式化时间,示例:1586840260500 | format('YYYY-MM-DD HH:mm:ss')
22
+ * @param {String|Number} date
23
+ * @param {String} fmt 'YYYY-MM-DD HH:mm:ss'
24
+ * @return {String} 'YYYY-MM-DD HH:mm:ss'
25
+ */
26
+ FilterClass.prototype.format = function (date, fmt) {
27
+ if (fmt === void 0) { fmt = 'YYYY-MM-DD HH:mm:ss'; }
28
+ return dateClass.format(date, fmt);
29
+ };
30
+ /**
31
+ * 格式化金额,示例:123456 | formatMoney
32
+ * @param {Number} num
33
+ * @return {String} 123,456
34
+ */
35
+ FilterClass.prototype.formatMoney = function (money) {
36
+ return numberClass.formatMoney(money);
37
+ };
38
+ /**
39
+ * 截取数组或字符串,示例:'1234' | slice(3)
40
+ * @param {Array|String} target 数组或字符串
41
+ * @param {Number} length 截取长度,从0开始
42
+ * @return {any}
43
+ */
44
+ FilterClass.prototype.slice = function (target, length) {
45
+ if (target === void 0) { target = ''; }
46
+ if (length === void 0) { length = 0; }
47
+ return toolsClass.slice(target, length);
48
+ };
49
+ FilterClass.prototype.install = function (Vue) {
50
+ var _this = this;
51
+ Vue.filter('format', _this.format);
52
+ Vue.filter('formatMoney', _this.formatMoney);
53
+ Vue.filter('slice', _this.slice);
54
+ };
55
+ return FilterClass;
56
+ }());
57
+ module.exports = new FilterClass();