@haluo/util 2.0.23 → 2.0.25
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.
- package/dist/index.d.ts +3 -1
- package/dist/index.js +33 -61
- package/dist/modules/cookie/index.js +18 -24
- package/dist/modules/date/index.js +49 -56
- package/dist/modules/dom/index.js +16 -23
- package/dist/modules/filter/index.js +15 -25
- package/dist/modules/format/index.js +6 -12
- package/dist/modules/match/index.js +6 -10
- package/dist/modules/monitor/index.js +7 -14
- package/dist/modules/monitor/lib/jsError.js +39 -35
- package/dist/modules/monitor/lib/timing.js +24 -28
- package/dist/modules/monitor/lib/xhr.js +26 -33
- package/dist/modules/monitor/utils/onload.js +1 -4
- package/dist/modules/monitor/utils/tracker.js +13 -27
- package/dist/modules/number/index.js +31 -35
- package/dist/modules/open-app/index.js +66 -61
- package/dist/modules/sentry/index.js +19 -27
- package/dist/modules/tools/index.d.ts +1 -1
- package/dist/modules/tools/index.js +158 -169
- package/dist/modules/upload/aliOss.d.ts +78 -127
- package/dist/modules/upload/aliOss.js +178 -358
- package/dist/modules/upload/index.d.ts +2 -14
- package/dist/modules/upload/index.js +2 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.js +1 -2
- package/package.json +14 -3
- package/dist/modules/upload/aliOss copy.d.ts +0 -321
- package/dist/modules/upload/aliOss copy.js +0 -734
- package/dist/modules/upload/backup-aliOss.d.ts +0 -321
- package/dist/modules/upload/backup-aliOss.js +0 -734
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import match from './modules/match';
|
|
|
7
7
|
import number from './modules/number';
|
|
8
8
|
import openApp from './modules/open-app';
|
|
9
9
|
import tools from './modules/tools';
|
|
10
|
+
import upload from './modules/upload';
|
|
10
11
|
import monitor from './modules/monitor';
|
|
11
12
|
export * from './modules/monitor';
|
|
12
13
|
interface Modules {
|
|
@@ -19,6 +20,7 @@ interface Modules {
|
|
|
19
20
|
number: typeof number;
|
|
20
21
|
openApp: typeof openApp;
|
|
21
22
|
tools: typeof tools;
|
|
23
|
+
upload: typeof upload;
|
|
22
24
|
monitor: typeof monitor;
|
|
23
25
|
}
|
|
24
26
|
declare class Utils {
|
|
@@ -34,4 +36,4 @@ interface Utils extends Modules {
|
|
|
34
36
|
}
|
|
35
37
|
declare const _default: Utils;
|
|
36
38
|
export default _default;
|
|
37
|
-
export { cookie, date, dom, filter, format, match, number, openApp, tools, monitor };
|
|
39
|
+
export { cookie, date, dom, filter, format, match, number, openApp, tools, upload, monitor };
|
package/dist/index.js
CHANGED
|
@@ -1,58 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import cookie from './modules/cookie';
|
|
2
|
+
import date from './modules/date';
|
|
3
|
+
import dom from './modules/dom';
|
|
4
|
+
import filter from './modules/filter';
|
|
5
|
+
import format from './modules/format';
|
|
6
|
+
import match from './modules/match';
|
|
7
|
+
import number from './modules/number';
|
|
8
|
+
import openApp from './modules/open-app';
|
|
9
|
+
import tools from './modules/tools';
|
|
10
|
+
import upload from './modules/upload';
|
|
11
|
+
import monitor from './modules/monitor';
|
|
12
|
+
export * from './modules/monitor';
|
|
13
|
+
const modules = {
|
|
14
|
+
cookie,
|
|
15
|
+
date,
|
|
16
|
+
dom,
|
|
17
|
+
filter,
|
|
18
|
+
format,
|
|
19
|
+
match,
|
|
20
|
+
number,
|
|
21
|
+
openApp,
|
|
22
|
+
tools,
|
|
23
|
+
upload,
|
|
24
|
+
monitor
|
|
18
25
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var cookie_1 = __importDefault(require("./modules/cookie"));
|
|
22
|
-
exports.cookie = cookie_1.default;
|
|
23
|
-
var date_1 = __importDefault(require("./modules/date"));
|
|
24
|
-
exports.date = date_1.default;
|
|
25
|
-
var dom_1 = __importDefault(require("./modules/dom"));
|
|
26
|
-
exports.dom = dom_1.default;
|
|
27
|
-
var filter_1 = __importDefault(require("./modules/filter"));
|
|
28
|
-
exports.filter = filter_1.default;
|
|
29
|
-
var format_1 = __importDefault(require("./modules/format"));
|
|
30
|
-
exports.format = format_1.default;
|
|
31
|
-
var match_1 = __importDefault(require("./modules/match"));
|
|
32
|
-
exports.match = match_1.default;
|
|
33
|
-
var number_1 = __importDefault(require("./modules/number"));
|
|
34
|
-
exports.number = number_1.default;
|
|
35
|
-
var open_app_1 = __importDefault(require("./modules/open-app"));
|
|
36
|
-
exports.openApp = open_app_1.default;
|
|
37
|
-
var tools_1 = __importDefault(require("./modules/tools"));
|
|
38
|
-
exports.tools = tools_1.default;
|
|
39
|
-
var monitor_1 = __importDefault(require("./modules/monitor"));
|
|
40
|
-
exports.monitor = monitor_1.default;
|
|
41
|
-
__exportStar(require("./modules/monitor"), exports);
|
|
42
|
-
var modules = {
|
|
43
|
-
cookie: cookie_1.default,
|
|
44
|
-
date: date_1.default,
|
|
45
|
-
dom: dom_1.default,
|
|
46
|
-
filter: filter_1.default,
|
|
47
|
-
format: format_1.default,
|
|
48
|
-
match: match_1.default,
|
|
49
|
-
number: number_1.default,
|
|
50
|
-
openApp: open_app_1.default,
|
|
51
|
-
tools: tools_1.default,
|
|
52
|
-
monitor: monitor_1.default
|
|
53
|
-
};
|
|
54
|
-
var Utils = /** @class */ (function () {
|
|
55
|
-
function Utils() {
|
|
26
|
+
class Utils {
|
|
27
|
+
constructor() {
|
|
56
28
|
Object.assign(this, modules);
|
|
57
29
|
}
|
|
58
30
|
/**
|
|
@@ -60,12 +32,12 @@ var Utils = /** @class */ (function () {
|
|
|
60
32
|
* 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
|
|
61
33
|
* @param {Object} Vue 需要挂载的目标对象
|
|
62
34
|
*/
|
|
63
|
-
|
|
64
|
-
Object.keys(modules).forEach(
|
|
65
|
-
|
|
35
|
+
install(app) {
|
|
36
|
+
Object.keys(modules).forEach((key) => {
|
|
37
|
+
const globalProperties = app.config.globalProperties;
|
|
66
38
|
globalProperties['$' + key] = modules[key];
|
|
67
39
|
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export default new Utils();
|
|
43
|
+
export { cookie, date, dom, filter, format, match, number, openApp, tools, upload, monitor };
|
|
@@ -4,52 +4,46 @@
|
|
|
4
4
|
* @createBy: @2021.01.21
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
7
|
-
|
|
8
|
-
var CookieClass = /** @class */ (function () {
|
|
9
|
-
function CookieClass() {
|
|
10
|
-
}
|
|
7
|
+
class CookieClass {
|
|
11
8
|
/**
|
|
12
9
|
* 获取cookie
|
|
13
10
|
* @param {String} name
|
|
14
11
|
* @return {String}
|
|
15
12
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
for (
|
|
20
|
-
|
|
13
|
+
getCookie(name) {
|
|
14
|
+
const _name = name + '=';
|
|
15
|
+
const ca = document.cookie.split(';');
|
|
16
|
+
for (let i = 0; i < ca.length; i++) {
|
|
17
|
+
let c = ca[i];
|
|
21
18
|
while (c.charAt(0) === ' ')
|
|
22
19
|
c = c.substring(1);
|
|
23
20
|
if (c.includes(_name))
|
|
24
21
|
return c.substring(_name.length, c.length);
|
|
25
22
|
}
|
|
26
23
|
return '';
|
|
27
|
-
}
|
|
24
|
+
}
|
|
28
25
|
/**
|
|
29
26
|
* 设置cookie
|
|
30
27
|
* @param {Object} ICookie
|
|
31
28
|
*/
|
|
32
|
-
|
|
33
|
-
var _b = _a.name, name = _b === void 0 ? '' : _b, _c = _a.value, value = _c === void 0 ? '' : _c, _d = _a.exdays, exdays = _d === void 0 ? -1 : _d, _e = _a.path, path = _e === void 0 ? '/' : _e, _f = _a.domain, domain = _f === void 0 ? '.jddmoto.com' : _f;
|
|
29
|
+
setCookie({ name = '', value = '', exdays = -1, path = '/', domain = '.jddmoto.com', }) {
|
|
34
30
|
var d = new Date();
|
|
35
31
|
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
|
36
|
-
var expires =
|
|
37
|
-
document.cookie =
|
|
38
|
-
}
|
|
32
|
+
var expires = `expires=${d.toUTCString()}`;
|
|
33
|
+
document.cookie = `${name}=${value};${expires};path=${path};domain=${domain};`;
|
|
34
|
+
}
|
|
39
35
|
/**
|
|
40
36
|
* 清除Cookie
|
|
41
37
|
* @param {String} name
|
|
42
38
|
*/
|
|
43
|
-
|
|
44
|
-
var _b = _a.name, name = _b === void 0 ? '' : _b, _c = _a.path, path = _c === void 0 ? '/' : _c, _d = _a.domain, domain = _d === void 0 ? '.jddmoto.com' : _d;
|
|
39
|
+
clearCookie({ name = '', path = '/', domain = '.jddmoto.com', }) {
|
|
45
40
|
this.setCookie({
|
|
46
|
-
name
|
|
41
|
+
name,
|
|
47
42
|
value: '',
|
|
48
43
|
exdays: -1,
|
|
49
|
-
path
|
|
50
|
-
domain
|
|
44
|
+
path,
|
|
45
|
+
domain
|
|
51
46
|
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
exports.default = new CookieClass();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export default new CookieClass();
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* @createBy: @2020.05.21
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
7
|
/**
|
|
9
8
|
* 格式化时间 详情内容里的时间格式
|
|
10
9
|
* @param {Object} data 格式,可参考format 中的o属性
|
|
@@ -14,7 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
13
|
function replacementDate(data, fmt) {
|
|
15
14
|
for (var k in data) {
|
|
16
15
|
if (new RegExp('(' + k + ')').test(fmt)) {
|
|
17
|
-
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (data[k]) : ((
|
|
16
|
+
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (data[k]) : ((`00${data[k]}`).substr(('' + data[k]).length)));
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
return fmt;
|
|
@@ -31,9 +30,7 @@ function replacementYear(date, fmt) {
|
|
|
31
30
|
}
|
|
32
31
|
return fmt;
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
function DateClass() {
|
|
36
|
-
}
|
|
33
|
+
class DateClass {
|
|
37
34
|
/**
|
|
38
35
|
* 格式化时间
|
|
39
36
|
* @param {String|Number} date 需要格式化的时间 2017-11-11、2017/11/11、linux time
|
|
@@ -43,11 +40,10 @@ var DateClass = /** @class */ (function () {
|
|
|
43
40
|
* date.format(new Date(), 'YYYY:MM:DD') // 自定义格式 'YYYY:MM:DD'
|
|
44
41
|
* @return {String} fmt 'YYYY-MM-DD HH:mm:ss'
|
|
45
42
|
*/
|
|
46
|
-
|
|
47
|
-
if (fmt === void 0) { fmt = 'YYYY-MM-DD HH:mm:ss'; }
|
|
43
|
+
format(date, fmt = 'YYYY-MM-DD HH:mm:ss') {
|
|
48
44
|
if (!date)
|
|
49
45
|
return '';
|
|
50
|
-
|
|
46
|
+
let timeData = typeof date === 'string' ? new Date(date.replace(/-/g, '/')) : date;
|
|
51
47
|
timeData = typeof date === 'number' ? new Date(date) : timeData;
|
|
52
48
|
var o = {
|
|
53
49
|
'M+': timeData.getMonth() + 1,
|
|
@@ -59,7 +55,7 @@ var DateClass = /** @class */ (function () {
|
|
|
59
55
|
'q+': Math.floor((timeData.getMonth() + 3) / 3),
|
|
60
56
|
'S': timeData.getMilliseconds()
|
|
61
57
|
};
|
|
62
|
-
|
|
58
|
+
const week = {
|
|
63
59
|
'0': '\u65e5',
|
|
64
60
|
'1': '\u4e00',
|
|
65
61
|
'2': '\u4e8c',
|
|
@@ -70,10 +66,10 @@ var DateClass = /** @class */ (function () {
|
|
|
70
66
|
};
|
|
71
67
|
fmt = replacementYear(timeData, fmt);
|
|
72
68
|
if (/(E+)/.test(fmt)) {
|
|
73
|
-
fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\u661f\u671f' : '\u5468') : '') + week[
|
|
69
|
+
fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\u661f\u671f' : '\u5468') : '') + week[`${timeData.getDay()} `]);
|
|
74
70
|
}
|
|
75
71
|
return replacementDate(o, fmt);
|
|
76
|
-
}
|
|
72
|
+
}
|
|
77
73
|
/**
|
|
78
74
|
* 天数加减
|
|
79
75
|
* @param {string | Date} date 传入的时间 2020-10-15 or Date
|
|
@@ -82,11 +78,11 @@ var DateClass = /** @class */ (function () {
|
|
|
82
78
|
* addDaysToDate('2020-10-15', -10) // '2020-10-05'
|
|
83
79
|
* @return {String} fmt 'YYYY-MM-DD'
|
|
84
80
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
addDaysToDate(date, days) {
|
|
82
|
+
const d = typeof date === 'object' ? date : new Date(date);
|
|
87
83
|
d.setDate(d.getDate() + days);
|
|
88
84
|
return d.toISOString().split('T')[0];
|
|
89
|
-
}
|
|
85
|
+
}
|
|
90
86
|
/**
|
|
91
87
|
* 获取倒计时剩余时间
|
|
92
88
|
* @param {Date | Number} endTime 截止时间
|
|
@@ -95,56 +91,55 @@ var DateClass = /** @class */ (function () {
|
|
|
95
91
|
* date.format(1586840260500) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
|
|
96
92
|
* @return {object | boolean} {dd: '天', hh: '时', mm: '分', ss: '秒'}
|
|
97
93
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
var ss = Math.floor(ts / 1000 % 60); // 计算剩余的秒数
|
|
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); // 计算剩余的秒数
|
|
105
100
|
if (ts <= 0)
|
|
106
101
|
return false;
|
|
107
102
|
return {
|
|
108
|
-
dd: (dd < 10 ?
|
|
109
|
-
hh: (hh < 10 ?
|
|
110
|
-
mm: (mm < 10 ?
|
|
111
|
-
ss: (ss < 10 ?
|
|
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)
|
|
112
107
|
};
|
|
113
|
-
}
|
|
108
|
+
}
|
|
114
109
|
/**
|
|
115
110
|
* 格式化现在的已过时间
|
|
116
111
|
* @param {Number} startTime
|
|
117
112
|
* @return {String} *年前 *个月前 *天前 *小时前 *分钟前 刚刚
|
|
118
113
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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);
|
|
123
118
|
if (year)
|
|
124
|
-
return
|
|
125
|
-
|
|
119
|
+
return `${year}年前`;
|
|
120
|
+
const month = Math.floor(time / (1000 * 60 * 60 * 24) / 30);
|
|
126
121
|
if (month)
|
|
127
|
-
return
|
|
128
|
-
|
|
122
|
+
return `${month}个月前`;
|
|
123
|
+
const day = Math.floor(time / (1000 * 60 * 60 * 24));
|
|
129
124
|
if (day)
|
|
130
|
-
return
|
|
131
|
-
|
|
125
|
+
return `${day}天前`;
|
|
126
|
+
const hour = Math.floor(time / (1000 * 60 * 60));
|
|
132
127
|
if (hour)
|
|
133
|
-
return
|
|
134
|
-
|
|
128
|
+
return `${hour}小时前`;
|
|
129
|
+
const min = Math.floor(time / (1000 * 60));
|
|
135
130
|
if (min)
|
|
136
|
-
return
|
|
131
|
+
return `${min}分钟前`;
|
|
137
132
|
else
|
|
138
133
|
return '刚刚';
|
|
139
|
-
}
|
|
134
|
+
}
|
|
140
135
|
/**
|
|
141
136
|
* 格式化时间 列表里的时间内容格式 待废弃,统一时间格式
|
|
142
137
|
* @param {Number} time 1494141000*1000
|
|
143
138
|
* @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
|
|
144
139
|
*/
|
|
145
|
-
|
|
140
|
+
formatPassTimeForList(time) {
|
|
146
141
|
return DateClass.prototype.formatPassTimeForDetail(time, 'YYYY年MM月DD日', true);
|
|
147
|
-
}
|
|
142
|
+
}
|
|
148
143
|
/**
|
|
149
144
|
* 格式化时间 详情内容里的时间格式
|
|
150
145
|
* @param {Number} time 1494141000*1000
|
|
@@ -152,25 +147,24 @@ var DateClass = /** @class */ (function () {
|
|
|
152
147
|
* @param {Boolean} noYear 是否显示年
|
|
153
148
|
* @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
|
|
154
149
|
*/
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
var isValidDate = Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime());
|
|
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());
|
|
161
155
|
if (!isValidDate)
|
|
162
156
|
return '';
|
|
163
|
-
|
|
164
|
-
|
|
157
|
+
const formatDate = function () {
|
|
158
|
+
const today = new Date(date);
|
|
165
159
|
var o = {
|
|
166
160
|
'Y+': today.getFullYear(),
|
|
167
161
|
'M+': ('0' + (today.getMonth() + 1)).slice(-2),
|
|
168
162
|
'D+': ('0' + today.getDate()).slice(-2)
|
|
169
163
|
};
|
|
170
164
|
fmt = replacementYear(date, fmt);
|
|
171
|
-
|
|
165
|
+
const year = today.getFullYear();
|
|
172
166
|
if (!(new Date().getFullYear() > year) && noYear) {
|
|
173
|
-
|
|
167
|
+
const backData = replacementDate(o, fmt);
|
|
174
168
|
return backData.split('年')[1];
|
|
175
169
|
}
|
|
176
170
|
return replacementDate(o, fmt);
|
|
@@ -186,7 +180,6 @@ var DateClass = /** @class */ (function () {
|
|
|
186
180
|
(diff < 3600 && Math.floor(diff / 60) + '分钟前') ||
|
|
187
181
|
(diff < 7200 && '1小时前') ||
|
|
188
182
|
(diff < 86400 && Math.floor(diff / 3600) + '小时前'))) || (dayDiff < 16 && dayDiff + '天前');
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
exports.default = new DateClass();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
export default new DateClass();
|
|
@@ -4,59 +4,52 @@
|
|
|
4
4
|
* @createBy: @2021.08.17
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
7
|
-
|
|
8
|
-
var DomClass = /** @class */ (function () {
|
|
9
|
-
function DomClass() {
|
|
10
|
-
}
|
|
7
|
+
class DomClass {
|
|
11
8
|
/**
|
|
12
9
|
* 创建一个子元素并添加至父节点
|
|
13
10
|
* @param {Object} { name = 'div', innerHTML = '', style = {}, parent, }
|
|
14
11
|
* @return {String}
|
|
15
12
|
*/
|
|
16
|
-
|
|
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;
|
|
13
|
+
createElement({ name = 'div', innerHTML = '', style = {}, parent, }) {
|
|
18
14
|
if (!(window && window.document)) {
|
|
19
15
|
return new Error('仅支持浏览器');
|
|
20
16
|
}
|
|
21
|
-
|
|
17
|
+
const element = document.createElement(name);
|
|
22
18
|
element.innerHTML = innerHTML;
|
|
23
|
-
Object.keys(style).map(
|
|
19
|
+
Object.keys(style).map((_) => element.style[_] = style[_]);
|
|
24
20
|
if (parent) {
|
|
25
|
-
|
|
21
|
+
const body = document.querySelector(parent);
|
|
26
22
|
body && body.append(element);
|
|
27
23
|
}
|
|
28
24
|
return element;
|
|
29
|
-
}
|
|
25
|
+
}
|
|
30
26
|
/**
|
|
31
27
|
* 获取文本中的url并用a标签包裹
|
|
32
28
|
* @param {Object} ICookie
|
|
33
29
|
*/
|
|
34
|
-
|
|
30
|
+
wrapperA(text) {
|
|
35
31
|
if (!(window && window.document)) {
|
|
36
32
|
return new Error('仅支持浏览器');
|
|
37
33
|
}
|
|
38
34
|
return text.replace(/((https|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])/g, '<a href="$1">$1</a>');
|
|
39
|
-
}
|
|
35
|
+
}
|
|
40
36
|
/**
|
|
41
37
|
* 对象转化为formdata
|
|
42
38
|
* getFormData({a: 1, b: 2})
|
|
43
39
|
* @param {Object} object
|
|
44
40
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Object.keys(object).forEach(
|
|
48
|
-
|
|
41
|
+
getFormData(object) {
|
|
42
|
+
const formData = new FormData();
|
|
43
|
+
Object.keys(object).forEach(key => {
|
|
44
|
+
const value = object[key];
|
|
49
45
|
if (Array.isArray(value)) {
|
|
50
|
-
value.forEach(
|
|
51
|
-
return formData.append(key + "[".concat(i, "]"), subValue);
|
|
52
|
-
});
|
|
46
|
+
value.forEach((subValue, i) => formData.append(key + `[${i}]`, subValue));
|
|
53
47
|
}
|
|
54
48
|
else {
|
|
55
49
|
formData.append(key, object[key]);
|
|
56
50
|
}
|
|
57
51
|
});
|
|
58
52
|
return formData;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
exports.default = new DomClass();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export default new DomClass();
|
|
@@ -4,45 +4,35 @@
|
|
|
4
4
|
* @createBy: @2020.05.28
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
}
|
|
7
|
+
import dateClass from '../date';
|
|
8
|
+
import numberClass from '../number';
|
|
9
|
+
import toolsClass from '../tools';
|
|
10
|
+
class FilterClass {
|
|
17
11
|
/**
|
|
18
12
|
* 格式化时间,示例:1586840260500 | format('YYYY-MM-DD HH:mm:ss')
|
|
19
13
|
* @param {String|Number} date
|
|
20
14
|
* @param {String} fmt 'YYYY-MM-DD HH:mm:ss'
|
|
21
15
|
* @return {String} 'YYYY-MM-DD HH:mm:ss'
|
|
22
16
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
17
|
+
format(date, fmt = 'YYYY-MM-DD HH:mm:ss') {
|
|
18
|
+
return dateClass.format(date, fmt);
|
|
19
|
+
}
|
|
27
20
|
/**
|
|
28
21
|
* 格式化金额,示例:123456 | formatMoney
|
|
29
22
|
* @param {Number} num
|
|
30
23
|
* @return {String} 123,456
|
|
31
24
|
*/
|
|
32
|
-
|
|
33
|
-
return
|
|
34
|
-
}
|
|
25
|
+
formatMoney(money) {
|
|
26
|
+
return numberClass.formatMoney(money);
|
|
27
|
+
}
|
|
35
28
|
/**
|
|
36
29
|
* 截取数组或字符串,示例:'1234' | slice(3)
|
|
37
30
|
* @param {Array|String} target 数组或字符串
|
|
38
31
|
* @param {Number} length 截取长度,从0开始
|
|
39
32
|
* @return {any}
|
|
40
33
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return FilterClass;
|
|
47
|
-
}());
|
|
48
|
-
exports.default = new FilterClass();
|
|
34
|
+
slice(target = '', length = 0) {
|
|
35
|
+
return toolsClass.slice(target, length);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export default new FilterClass();
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var Format = /** @class */ (function () {
|
|
4
|
-
function Format() {
|
|
5
|
-
}
|
|
1
|
+
class Format {
|
|
6
2
|
/**
|
|
7
3
|
* @desc 对于对象非数字与布尔值的value,当其为falsy时,转换成separator
|
|
8
4
|
* @param {object} obj 传入的对象
|
|
@@ -10,13 +6,11 @@ var Format = /** @class */ (function () {
|
|
|
10
6
|
* transformObjectNullVal({ a: null, b: 0}, '23') // {a: "23", b: 0}
|
|
11
7
|
* @return {object}
|
|
12
8
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return Object.keys(obj).reduce(function (cur, key) {
|
|
9
|
+
transformObjectNullVal(obj, separator = '-') {
|
|
10
|
+
return Object.keys(obj).reduce((cur, key) => {
|
|
16
11
|
cur[key] = obj[key] || ((obj[key] === 0 || obj[key] === false) ? obj[key] : separator);
|
|
17
12
|
return cur;
|
|
18
13
|
}, {});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
exports.default = new Format();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export default new Format();
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
* @Author: wanghui
|
|
4
4
|
*/
|
|
5
5
|
'use strict';
|
|
6
|
-
|
|
7
|
-
var MatchClass = /** @class */ (function () {
|
|
8
|
-
function MatchClass() {
|
|
9
|
-
}
|
|
6
|
+
class MatchClass {
|
|
10
7
|
/**
|
|
11
8
|
* 根据类型返回正则
|
|
12
9
|
* @param {String} str 检测的内容
|
|
@@ -14,8 +11,8 @@ var MatchClass = /** @class */ (function () {
|
|
|
14
11
|
* checkType('10.120.33.11', 'ip') // true
|
|
15
12
|
* @return {Boolean} true or false
|
|
16
13
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
checkType(str, type) {
|
|
15
|
+
const regexp = {
|
|
19
16
|
'ip': /((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/.test(str),
|
|
20
17
|
'port': /^(\d|[1-5]\d{4}|6[1-4]\d{3}|65[1-4]\d{2}|655[1-2]\d|6553[1-5])$/.test(str),
|
|
21
18
|
'phone': /^1[3|4|5|6|7|8][0-9]{9}$/.test(str),
|
|
@@ -25,7 +22,6 @@ var MatchClass = /** @class */ (function () {
|
|
|
25
22
|
'url': /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i.test(str)
|
|
26
23
|
};
|
|
27
24
|
return regexp[type];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
exports.default = new MatchClass();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export default new MatchClass();
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Tracker = void 0;
|
|
7
|
-
var jsError_1 = require("./lib/jsError");
|
|
8
|
-
var xhr_1 = __importDefault(require("./lib/xhr"));
|
|
9
|
-
var tracker_1 = __importDefault(require("./utils/tracker"));
|
|
10
|
-
exports.Tracker = tracker_1.default;
|
|
1
|
+
import { injectJsError } from './lib/jsError';
|
|
2
|
+
import injectXhrError from './lib/xhr';
|
|
3
|
+
import Tracker from './utils/tracker';
|
|
11
4
|
// import timing from './lib/timing'
|
|
12
|
-
function setup(data) {
|
|
13
|
-
|
|
14
|
-
(
|
|
5
|
+
export default function setup(data) {
|
|
6
|
+
injectJsError(data);
|
|
7
|
+
injectXhrError(data);
|
|
15
8
|
}
|
|
16
|
-
|
|
9
|
+
export { Tracker };
|
|
17
10
|
// timing()
|