@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,63 +1,84 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- var uuidv4 = require('uuid').v4;
15
- // const Parser = require('ua-parser-js');
16
- var SendTracker = /** @class */ (function () {
17
- function SendTracker() {
18
- this.url = '';
19
- }
20
- SendTracker.prototype.send = function (data) {
21
- if (data === void 0) { data = {}; }
22
- var host = window.location.host;
23
- if (host.indexOf('localhost') > -1)
24
- return;
25
- var reg = /((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}/g;
26
- if (reg.test(host))
27
- return;
28
- var log = __assign(__assign({}, getExtraData()), data);
29
- var formBody = [];
30
- for (var property in log) {
31
- var encodedKey = encodeURIComponent(property);
32
- var encodedValue = encodeURIComponent(log[property]);
33
- formBody.push(encodedKey + "=" + encodedValue);
34
- }
35
- formBody = formBody.join("&");
36
- fetch('https://apm-collect.58moto.com/app/collect/original/info/report/v2', {
37
- method: 'POST',
38
- headers: {
39
- "Content-Type": "application/x-www-form-urlencoded"
40
- },
41
- body: formBody,
42
- }).then(function (res) {
43
- // console.log(res)
44
- }).catch(function (e) {
45
- console.log(e);
46
- });
47
- };
48
- return SendTracker;
49
- }());
50
- function getExtraData() {
51
- return {
52
- deviceId: uuidv4(),
53
- platform: 3,
54
- errorType: 3,
55
- channel: 'h5',
56
- bundle: 'com.jdd.motorfans',
57
- title: '',
58
- frontStatus: 3,
59
- occurTimeStamp: Date.now(),
60
- // userAgent: new Parser().getResult()
61
- };
62
- }
63
- exports.default = new SendTracker();
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var uuidv4 = require('uuid').v4;
15
+ // const Parser = require('ua-parser-js');
16
+ var reg = /((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}/g;
17
+ var SendTracker = /** @class */ (function () {
18
+ function SendTracker() {
19
+ this.url = '';
20
+ }
21
+ SendTracker.prototype.verifyRequest = function (reason) {
22
+ if (!reason)
23
+ return false;
24
+ if (reg.test(reason))
25
+ return false;
26
+ if (reason.startsWith('halomoto'))
27
+ return false;
28
+ if (reason.startsWith('file:'))
29
+ return false;
30
+ if (reason.includes('log-center.58moto.com'))
31
+ return false;
32
+ if (reason.includes('s23.cnzz.com'))
33
+ return false;
34
+ if (reason.includes('g.alicdn.com'))
35
+ return false;
36
+ if (reason.includes('vendors'))
37
+ return false;
38
+ return true;
39
+ };
40
+ SendTracker.prototype.send = function (data) {
41
+ if (data === void 0) { data = {}; }
42
+ var host = window.location.host;
43
+ if (host.indexOf('localhost') > -1)
44
+ return;
45
+ if (reg.test(host))
46
+ return;
47
+ if (!this.verifyRequest(data.reason))
48
+ return;
49
+ data.reason = window.location.href + ' ' + data.reason;
50
+ var log = __assign(__assign({}, getExtraData()), data);
51
+ var formBody = [];
52
+ for (var property in log) {
53
+ var encodedKey = encodeURIComponent(property);
54
+ var encodedValue = encodeURIComponent(log[property]);
55
+ formBody.push(encodedKey + "=" + encodedValue);
56
+ }
57
+ formBody = formBody.join("&");
58
+ fetch('https://apm-collect.58moto.com/app/collect/original/info/report/v2', {
59
+ method: 'POST',
60
+ headers: {
61
+ "Content-Type": "application/x-www-form-urlencoded"
62
+ },
63
+ body: formBody,
64
+ }).then(function (res) {
65
+ // console.log(res)
66
+ }).catch(function (e) {
67
+ console.log(e);
68
+ });
69
+ };
70
+ return SendTracker;
71
+ }());
72
+ function getExtraData() {
73
+ return {
74
+ deviceId: uuidv4(),
75
+ platform: 3,
76
+ errorType: 3,
77
+ channel: 'h5',
78
+ bundle: 'com.jdd.motorfans',
79
+ title: '',
80
+ frontStatus: 3,
81
+ occurTimeStamp: Date.now(),
82
+ };
83
+ }
84
+ exports.default = new SendTracker();
@@ -0,0 +1,39 @@
1
+ declare class NumberClass {
2
+ /**
3
+ * 个位数前面补0
4
+ * @param {Number} num 需要格式化的数字
5
+ * @return {String} '01'
6
+ */
7
+ formatNumber(num: number): string;
8
+ /**
9
+ * 将手机号中间部分替换为星号
10
+ * @param {String} phone 手机号码
11
+ * @return {String} 131****1111
12
+ */
13
+ formatPhone(phone: string): string;
14
+ /**
15
+ * 格式化数字 万
16
+ * @param {Number} num
17
+ * @return {String} 12.3万
18
+ */
19
+ convertToWan(num: number): string | number;
20
+ /**
21
+ * 格式化数字 k
22
+ * @param {Number} num
23
+ * @return {String} 1.2k
24
+ */
25
+ convertToThousand(num: number): string | number;
26
+ /**
27
+ * 随机数,指定范围
28
+ * @param {Number} min 开始
29
+ * @param {Number} max 结束
30
+ * @return {Number|Object}
31
+ */
32
+ random(min: number, max: number): number | null;
33
+ /**
34
+ * 格式化金额
35
+ * @param {Number} num
36
+ * @return {String} 123,456
37
+ */
38
+ formatMoney(money: number | string, signal: string): string;
39
+ }
@@ -1,103 +1,102 @@
1
- /**
2
- * @file number 格式化
3
- * @Author: wanghui
4
- * @createBy: @2020.05.26
5
- */
6
- 'use strict';
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- var NumberClass = /** @class */ (function () {
9
- function NumberClass() {
10
- }
11
- /**
12
- * 个位数前面补0
13
- * @param {Number} num 需要格式化的数字
14
- * @return {String} '01'
15
- */
16
- NumberClass.prototype.formatNumber = function (num) {
17
- var res = num.toString();
18
- return res[1] ? res : '0' + res;
19
- };
20
- /**
21
- * 将手机号中间部分替换为星号
22
- * @param {String} phone 手机号码
23
- * @return {String} 131****1111
24
- */
25
- NumberClass.prototype.formatPhone = function (phone) {
26
- return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
27
- };
28
- /**
29
- * 格式化数字
30
- * @param {Number} num
31
- * @return {String} 12.3万
32
- */
33
- NumberClass.prototype.convertToWan = function (num) {
34
- var result = '';
35
- if (num < 10000) {
36
- result = num;
37
- }
38
- if (num >= 10000) {
39
- result = (num / 10000).toFixed(1) + '万';
40
- }
41
- return result;
42
- };
43
- /**
44
- * 格式化数字 k
45
- * @param {Number} num
46
- * @return {String} 1.2k
47
- */
48
- NumberClass.prototype.convertToThousand = function (num) {
49
- var result = '';
50
- if (num < 1000) {
51
- result = num;
52
- }
53
- if (num >= 1000) {
54
- result = (num / 1000).toFixed(1) + 'k';
55
- }
56
- return result;
57
- };
58
- /**
59
- * 随机数,指定范围
60
- * @param {Number} min 开始
61
- * @param {Number} max 结束
62
- * @return {Number|Object}
63
- */
64
- NumberClass.prototype.random = function (min, max) {
65
- if (arguments.length === 2) {
66
- return Math.floor(min + Math.random() * ((max + 1) - min));
67
- }
68
- else {
69
- return null;
70
- }
71
- };
72
- /**
73
- * 格式化金额
74
- * @param {Number} num
75
- * @return {String} 123,456
76
- */
77
- NumberClass.prototype.formatMoney = function (money, signal) {
78
- var result = '';
79
- if (money === '') {
80
- return result;
81
- }
82
- money = String(money).replace('.00', '');
83
- money = money.substring(money.length - 2) === '.0' ? money.replace('.0', '') : money;
84
- // 小于3位数,直接返回
85
- if (Number(money) < 1000) {
86
- return result = money;
87
- }
88
- if (money.split('.')[0].length < 3) {
89
- return result = money;
90
- }
91
- signal = signal === '' ? '' : ',';
92
- var price = money.split('.')[0] + '';
93
- var pricePoint = money.split('.')[1];
94
- result = price.length > 6 ?
95
- "".concat(price.substring(0, price.length - 6)).concat(signal).concat(price.substring(price.length - 6, price.length - 3), ",").concat(price.substring(price.length - 3, price.length))
96
- :
97
- "".concat(price.substring(0, price.length - 3)).concat(signal).concat(price.substring(price.length - 3, price.length));
98
- result = pricePoint ? "".concat(result).concat(signal).concat(pricePoint) : result;
99
- return result;
100
- };
101
- return NumberClass;
102
- }());
103
- exports.default = new NumberClass();
1
+ /**
2
+ * @file number 格式化
3
+ * @Author: wanghui
4
+ * @createBy: @2020.05.26
5
+ */
6
+ 'use strict';
7
+ var NumberClass = /** @class */ (function () {
8
+ function NumberClass() {
9
+ }
10
+ /**
11
+ * 个位数前面补0
12
+ * @param {Number} num 需要格式化的数字
13
+ * @return {String} '01'
14
+ */
15
+ NumberClass.prototype.formatNumber = function (num) {
16
+ var res = num.toString();
17
+ return res[1] ? res : '0' + res;
18
+ };
19
+ /**
20
+ * 将手机号中间部分替换为星号
21
+ * @param {String} phone 手机号码
22
+ * @return {String} 131****1111
23
+ */
24
+ NumberClass.prototype.formatPhone = function (phone) {
25
+ return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
26
+ };
27
+ /**
28
+ * 格式化数字 万
29
+ * @param {Number} num
30
+ * @return {String} 12.3万
31
+ */
32
+ NumberClass.prototype.convertToWan = function (num) {
33
+ var result = '';
34
+ if (num < 10000) {
35
+ result = num;
36
+ }
37
+ if (num >= 10000) {
38
+ result = (num / 10000).toFixed(1) + '万';
39
+ }
40
+ return result;
41
+ };
42
+ /**
43
+ * 格式化数字 k
44
+ * @param {Number} num
45
+ * @return {String} 1.2k
46
+ */
47
+ NumberClass.prototype.convertToThousand = function (num) {
48
+ var result = '';
49
+ if (num < 1000) {
50
+ result = num;
51
+ }
52
+ if (num >= 1000) {
53
+ result = (num / 1000).toFixed(1) + 'k';
54
+ }
55
+ return result;
56
+ };
57
+ /**
58
+ * 随机数,指定范围
59
+ * @param {Number} min 开始
60
+ * @param {Number} max 结束
61
+ * @return {Number|Object}
62
+ */
63
+ NumberClass.prototype.random = function (min, max) {
64
+ if (arguments.length === 2) {
65
+ return Math.floor(min + Math.random() * ((max + 1) - min));
66
+ }
67
+ else {
68
+ return null;
69
+ }
70
+ };
71
+ /**
72
+ * 格式化金额
73
+ * @param {Number} num
74
+ * @return {String} 123,456
75
+ */
76
+ NumberClass.prototype.formatMoney = function (money, signal) {
77
+ var result = '';
78
+ if (money === '') {
79
+ return result;
80
+ }
81
+ money = String(money).replace('.00', '');
82
+ money = money.substring(money.length - 2) === '.0' ? money.replace('.0', '') : money;
83
+ // 小于3位数,直接返回
84
+ if (Number(money) < 1000) {
85
+ return result = money;
86
+ }
87
+ if (money.split('.')[0].length < 3) {
88
+ return result = money;
89
+ }
90
+ signal = signal === '' ? '' : ',';
91
+ var price = money.split('.')[0] + '';
92
+ var pricePoint = money.split('.')[1];
93
+ result = price.length > 6 ?
94
+ "" + price.substring(0, price.length - 6) + signal + price.substring(price.length - 6, price.length - 3) + "," + price.substring(price.length - 3, price.length)
95
+ :
96
+ "" + price.substring(0, price.length - 3) + signal + price.substring(price.length - 3, price.length);
97
+ result = pricePoint ? "" + result + signal + pricePoint : result;
98
+ return result;
99
+ };
100
+ return NumberClass;
101
+ }());
102
+ module.exports = new NumberClass();
@@ -0,0 +1,15 @@
1
+ declare class Report {
2
+ static instance: any;
3
+ constructor(Vue: Object, options?: {});
4
+ [key: string]: any;
5
+ static getInstance(Vue: Object, Option: Object): any;
6
+ install(): void;
7
+ /**
8
+ * 主动上报
9
+ * @param {String} data
10
+ * @param {String} type 'info','warning','error'
11
+ * @param {Object} options
12
+ */
13
+ log(data?: any, type?: any, options?: any): void;
14
+ }
15
+ export default Report;
@@ -1,81 +1,78 @@
1
- /**
2
- * 异常上报日志监控类
3
- * @Author: wanghui
4
- * 常用配置 option:https://docs.sentry.io/clients/javascript/config/
5
- * 1.自动捕获vue组件内异常
6
- * 2.自动捕获promise内的异常
7
- * 3.自动捕获没有被catch的运行异常
8
- */
9
- 'use strict';
10
- var __importDefault = (this && this.__importDefault) || function (mod) {
11
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- var raven_js_1 = __importDefault(require("raven-js"));
15
- // import RavenVue from 'raven-js/plugins/vue';
16
- var Report = /** @class */ (function () {
17
- function Report(Vue, options) {
18
- if (options === void 0) { options = {}; }
19
- if (process.env.NODE_ENV !== 'development') {
20
- // todo
21
- }
22
- this.vue = Vue;
23
- this.options = options;
24
- }
25
- Report.getInstance = function (Vue, Option) {
26
- if (!(this.instance instanceof this)) {
27
- this.instance = new this(Vue, Option);
28
- this.instance.install();
29
- }
30
- return this.instance;
31
- };
32
- Report.prototype.install = function () {
33
- if (process.env.NODE_ENV !== 'development') {
34
- // Raven.config(this.options.dsn, {
35
- // environment: process.env.NODE_ENV,
36
- // }).addPlugin(RavenVue, this.Vue).install();
37
- // raven内置了vue插件,会通过vue.config.errorHandler来捕获vue组件内错误并上报sentry服务
38
- // 记录用户信息
39
- raven_js_1.default.setUserContext({ user: this.options.user || '' });
40
- // 设置全局tag标签
41
- raven_js_1.default.setTagsContext({ environment: this.options.env || '' });
42
- }
43
- };
44
- /**
45
- * 主动上报
46
- * @param {String} data
47
- * @param {String} type 'info','warning','error'
48
- * @param {Object} options
49
- */
50
- Report.prototype.log = function (data, type, options) {
51
- if (data === void 0) { data = null; }
52
- if (type === void 0) { type = 'error'; }
53
- if (options === void 0) { options = {}; }
54
- // 添加面包屑
55
- raven_js_1.default.captureBreadcrumb({
56
- message: data,
57
- category: 'manual message',
58
- });
59
- // 异常上报
60
- if (data instanceof Error) {
61
- raven_js_1.default.captureException(data, {
62
- level: type,
63
- logger: 'manual exception',
64
- tags: { options: options },
65
- });
66
- }
67
- else {
68
- raven_js_1.default.captureException('error', {
69
- level: type,
70
- logger: 'manual data',
71
- extra: {
72
- data: data,
73
- options: this.options,
74
- date: new Date(),
75
- },
76
- });
77
- }
78
- };
79
- return Report;
80
- }());
81
- exports.default = Report;
1
+ /**
2
+ * 异常上报日志监控类
3
+ * @Author: wanghui
4
+ * 常用配置 option:https://docs.sentry.io/clients/javascript/config/
5
+ * 1.自动捕获vue组件内异常
6
+ * 2.自动捕获promise内的异常
7
+ * 3.自动捕获没有被catch的运行异常
8
+ */
9
+ 'use strict';
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var browser_1 = __importDefault(require("@sentry/browser"));
15
+ var Report = /** @class */ (function () {
16
+ function Report(Vue, options) {
17
+ if (options === void 0) { options = {}; }
18
+ if (process.env.NODE_ENV !== 'development') {
19
+ // todo
20
+ }
21
+ this.vue = Vue;
22
+ this.options = options;
23
+ }
24
+ Report.getInstance = function (Vue, Option) {
25
+ if (!(this.instance instanceof this)) {
26
+ this.instance = new this(Vue, Option);
27
+ this.instance.install();
28
+ }
29
+ return this.instance;
30
+ };
31
+ Report.prototype.install = function () {
32
+ if (process.env.NODE_ENV !== 'development') {
33
+ // Raven.config(this.options.dsn, {
34
+ // environment: process.env.NODE_ENV,
35
+ // }).addPlugin(RavenVue, this.Vue).install();
36
+ // raven内置了vue插件,会通过vue.config.errorHandler来捕获vue组件内错误并上报sentry服务
37
+ // 记录用户信息
38
+ browser_1.default.setUser({ user: this.options.user || '' });
39
+ // 设置全局tag标签
40
+ browser_1.default.setTag('environment', this.options.env || '');
41
+ }
42
+ };
43
+ /**
44
+ * 主动上报
45
+ * @param {String} data
46
+ * @param {String} type 'info','warning','error'
47
+ * @param {Object} options
48
+ */
49
+ Report.prototype.log = function (data, type, options) {
50
+ if (data === void 0) { data = null; }
51
+ if (type === void 0) { type = 'error'; }
52
+ if (options === void 0) { options = {}; }
53
+ // 添加面包屑
54
+ browser_1.default.addBreadcrumb({
55
+ message: data,
56
+ category: 'manual message',
57
+ });
58
+ // 异常上报
59
+ if (data instanceof Error) {
60
+ browser_1.default.captureException(data, {
61
+ level: type,
62
+ tags: { options: options },
63
+ });
64
+ }
65
+ else {
66
+ browser_1.default.captureException('error', {
67
+ level: type,
68
+ extra: {
69
+ data: data,
70
+ options: this.options,
71
+ date: new Date(),
72
+ },
73
+ });
74
+ }
75
+ };
76
+ return Report;
77
+ }());
78
+ exports.default = Report;
@@ -0,0 +1 @@
1
+ export {};