@haluo/util 2.0.29 → 2.0.30

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