@haluo/util 1.0.32 → 2.0.0

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 (38) hide show
  1. package/dist/index.js +33 -36
  2. package/dist/modules/cookie/index.js +54 -54
  3. package/dist/modules/date/index.js +192 -192
  4. package/dist/modules/dom/index.js +62 -62
  5. package/dist/modules/filter/index.js +44 -57
  6. package/dist/modules/format/index.js +21 -21
  7. package/dist/modules/match/index.js +31 -31
  8. package/dist/modules/monitor/index.js +17 -17
  9. package/dist/modules/monitor/lib/jsError.js +53 -61
  10. package/dist/modules/monitor/lib/timing.js +69 -69
  11. package/dist/modules/monitor/lib/xhr.js +48 -50
  12. package/dist/modules/monitor/utils/onload.js +11 -11
  13. package/dist/modules/monitor/utils/tracker.js +63 -84
  14. package/dist/modules/number/index.js +102 -102
  15. package/dist/modules/sentry/index.js +81 -78
  16. package/dist/modules/tools/index.js +393 -393
  17. package/package.json +4 -4
  18. package/publish.sh +0 -0
  19. package/src/index.ts +3 -6
  20. package/src/modules/filter/index.ts +0 -14
  21. package/src/modules/monitor/lib/jsError.ts +10 -10
  22. package/src/modules/monitor/lib/xhr.ts +1 -3
  23. package/src/modules/monitor/utils/tracker.ts +1 -15
  24. package/src/modules/sentry/index.ts +7 -4
  25. package/dist/index.cjs.js +0 -89
  26. package/dist/index.d.ts +0 -12
  27. package/dist/index.esm.js +0 -87
  28. package/dist/lib-list.d.ts +0 -2
  29. package/dist/modules/cookie/index.d.ts +0 -27
  30. package/dist/modules/date/index.d.ts +0 -1
  31. package/dist/modules/dom/index.d.ts +0 -1
  32. package/dist/modules/filter/index.d.ts +0 -26
  33. package/dist/modules/format/index.d.ts +0 -13
  34. package/dist/modules/match/index.d.ts +0 -1
  35. package/dist/modules/number/index.d.ts +0 -39
  36. package/dist/modules/sentry/index.d.ts +0 -15
  37. package/dist/modules/tools/index.d.ts +0 -1
  38. package/yarn-error.log +0 -9316
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haluo/util",
3
- "version": "1.0.32",
3
+ "version": "2.0.0",
4
4
  "main": "./dist/index.js",
5
5
  "author": "<wanghui@jddmoto.com>",
6
6
  "description": "哈罗摩托工具库",
@@ -26,11 +26,11 @@
26
26
  "@haluo/util"
27
27
  ],
28
28
  "dependencies": {
29
- "@sentry/browser": "^7.31.1",
30
29
  "@types/jest": "^26.0.24",
31
- "axios": "^1.2.3",
30
+ "axios": "^0.19.2",
32
31
  "clipboard-copy": "^4.0.1",
33
32
  "jest": "^27.0.6",
33
+ "raven-js": "^3.27.2",
34
34
  "ua-parser-js": "^1.0.2",
35
35
  "uuid": "^8.3.2"
36
36
  },
@@ -65,7 +65,7 @@
65
65
  "lodash": "^4.17.21",
66
66
  "normalize.css": "^8.0.1",
67
67
  "ts-jest": "^27.0.4",
68
- "typescript": "^3.9.5",
68
+ "typescript": "^4.9.5",
69
69
  "webpack": "^4.32.2",
70
70
  "webpack-cli": "^3.3.2",
71
71
  "webpack-dev-server": "^3.4.1",
package/publish.sh CHANGED
File without changes
package/src/index.ts CHANGED
@@ -27,13 +27,10 @@ class Utils {
27
27
  * 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
28
28
  * @param {Object} Vue 需要挂载的目标对象
29
29
  */
30
- install(Vue: any) {
30
+ install(app: any) {
31
31
  Object.keys(modules).forEach((key) => {
32
- if (key === 'filter') {
33
- return modules[key].install(Vue)
34
- }
35
- Vue.prototype['$' + key] = modules[key]
36
- Vue['$' + key] = modules[key]
32
+ const globalProperties = app.config.globalProperties
33
+ globalProperties['$' + key] = modules[key]
37
34
  })
38
35
  }
39
36
 
@@ -3,13 +3,6 @@
3
3
  * @Author: wanghui
4
4
  * @createBy: @2020.05.28
5
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
6
  'use strict'
14
7
 
15
8
  const dateClass = require('../date')
@@ -45,13 +38,6 @@ class FilterClass {
45
38
  slice(target: Array<any> | string = '', length: number = 0) {
46
39
  return toolsClass.slice(target, length)
47
40
  }
48
-
49
- install(Vue: any) {
50
- const _this = this
51
- Vue.filter('format', _this.format)
52
- Vue.filter('formatMoney', _this.formatMoney)
53
- Vue.filter('slice', _this.slice)
54
- }
55
41
  }
56
42
 
57
43
  module.exports = new FilterClass()
@@ -2,16 +2,16 @@ import track from '../utils/tracker'
2
2
  export function injectJsError (data:any={}) {
3
3
  window.addEventListener('error', (e: any) => {
4
4
  if (e.target && (e.target.src || e.target.href)) {
5
- // track.send({
6
- // kind: 'stability',
7
- // type: 'error',
8
- // title: 'resourceError',
9
- // filename: e.target.src || e.target.href,
10
- // tagName: e.target.tagName,
11
- // reason: e.target.src || e.target.href,
12
- // ...data
13
- // // selector: lastEvent ? get
14
- // })
5
+ track.send({
6
+ kind: 'stability',
7
+ type: 'error',
8
+ title: 'resourceError',
9
+ filename: e.target.src || e.target.href,
10
+ tagName: e.target.tagName,
11
+ reason: e.target.src || e.target.href,
12
+ ...data
13
+ // selector: lastEvent ? get
14
+ })
15
15
  return
16
16
  }
17
17
  track.send({
@@ -13,9 +13,7 @@ export default function injectXHR(data:any={}){
13
13
  const startTime = Date.now()
14
14
  const handler = (type:string) => (event:any) => {
15
15
  if(this.logData.url.indexOf('app/collect/original/info/report/v2') > -1 ) return
16
- // status = 0 是在跨域与404的情况下
17
- // 当前都是在readyState为4(请求已完成)的情况下,进行处理
18
- if(type !== 'error' || this.status === 0) return
16
+ if(type !== 'error') return
19
17
  let duration = Date.now() - startTime
20
18
  let status = this.status
21
19
  let statusText = this.statusText
@@ -1,29 +1,15 @@
1
1
  const { v4: uuidv4 } = require('uuid')
2
2
  // const Parser = require('ua-parser-js');
3
- const 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
4
-
5
3
  class SendTracker {
6
4
  url: string
7
5
  constructor() {
8
6
  this.url = ''
9
7
  }
10
- verifyRequest(reason:string):boolean {
11
- if(!reason) return false
12
- if(reg.test(reason)) return false
13
- if(reason.startsWith('halomoto')) return false
14
- if(reason.startsWith('file:')) return false
15
- if(reason.includes('log-center.58moto.com')) return false
16
- if(reason.includes('s23.cnzz.com')) return false
17
- if(reason.includes('g.alicdn.com')) return false
18
- if(reason.includes('vendors')) return false
19
- return true
20
- }
21
8
  send(data:any = {}) {
22
9
  const host = window.location.host
23
10
  if(host.indexOf('localhost') > -1) return
11
+ const 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
24
12
  if(reg.test(host)) return
25
- if(!this.verifyRequest(data.reason)) return
26
- data.reason = window.location.href+' '+data.reason
27
13
  const log = { ...getExtraData(), ...data}
28
14
  let formBody: any = [];
29
15
  for (var property in log) {
@@ -8,7 +8,8 @@
8
8
  */
9
9
  'use strict'
10
10
 
11
- import Raven from '@sentry/browser';
11
+ import Raven from 'raven-js';
12
+ // import RavenVue from 'raven-js/plugins/vue';
12
13
 
13
14
  class Report {
14
15
  static instance: any;
@@ -38,10 +39,10 @@ class Report {
38
39
  // raven内置了vue插件,会通过vue.config.errorHandler来捕获vue组件内错误并上报sentry服务
39
40
 
40
41
  // 记录用户信息
41
- Raven.setUser({ user: this.options.user || '' });
42
+ Raven.setUserContext({ user: this.options.user || '' });
42
43
 
43
44
  // 设置全局tag标签
44
- Raven.setTag('environment', this.options.env || '');
45
+ Raven.setTagsContext({ environment: this.options.env || '' });
45
46
  }
46
47
  }
47
48
 
@@ -53,7 +54,7 @@ class Report {
53
54
  */
54
55
  log(data: any = null, type: any = 'error', options: any = {}) {
55
56
  // 添加面包屑
56
- Raven.addBreadcrumb({
57
+ Raven.captureBreadcrumb({
57
58
  message: data,
58
59
  category: 'manual message',
59
60
  });
@@ -61,11 +62,13 @@ class Report {
61
62
  if (data instanceof Error) {
62
63
  Raven.captureException(data, {
63
64
  level: type,
65
+ logger: 'manual exception',
64
66
  tags: { options },
65
67
  });
66
68
  } else {
67
69
  Raven.captureException('error', {
68
70
  level: type,
71
+ logger: 'manual data',
69
72
  extra: {
70
73
  data,
71
74
  options: this.options,
package/dist/index.cjs.js DELETED
@@ -1,89 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * @file Cookie
5
- * @Author: wanghui
6
- * @createBy: @2021.01.21
7
- */
8
- var CookieClass = /** @class */ (function () {
9
- function CookieClass() {
10
- }
11
- /**
12
- * 获取cookie
13
- * @param {String} name
14
- * @return {String}
15
- */
16
- CookieClass.prototype.getCookie = function (name) {
17
- var _name = name + '=';
18
- var ca = document.cookie.split(';');
19
- for (var i = 0; i < ca.length; i++) {
20
- var c = ca[i];
21
- while (c.charAt(0) === ' ')
22
- c = c.substring(1);
23
- if (c.includes(_name))
24
- return c.substring(_name.length, c.length);
25
- }
26
- return '';
27
- };
28
- /**
29
- * 设置cookie
30
- * @param {Object} ICookie
31
- */
32
- CookieClass.prototype.setCookie = function (_a) {
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;
34
- var d = new Date();
35
- d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
36
- var expires = "expires=" + d.toUTCString();
37
- document.cookie = name + "=" + value + ";" + expires + ";path=" + path + ";domain=" + domain + ";";
38
- };
39
- /**
40
- * 清除Cookie
41
- * @param {String} name
42
- */
43
- CookieClass.prototype.clearCookie = function (name) {
44
- this.setCookie({
45
- name: name,
46
- value: '',
47
- exdays: -1,
48
- });
49
- };
50
- return CookieClass;
51
- }());
52
- var cookie = new CookieClass();
53
-
54
- /**
55
- * @Author: wanghui
56
- * createBy: @2020.05.21
57
- */
58
- // import date from './modules/date'
59
- // import dom from './modules/dom'
60
- // import filter from './modules/filter'
61
- // import format from './modules/format'
62
- // import match from './modules/match'
63
- // import number from './modules/number'
64
- // import tools from './modules/tools'
65
- var modules = {
66
- cookie: cookie,
67
- };
68
- var Utils = /** @class */ (function () {
69
- function Utils() {
70
- Object.assign(this, modules);
71
- }
72
- /**
73
- * 挂载各组件
74
- * 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
75
- * @param {Object} app 需要挂载的目标对象
76
- */
77
- Utils.prototype.install = function (app) {
78
- Object.keys(modules).forEach(function (key) {
79
- if (key === 'filter') {
80
- return modules[key].install(app);
81
- }
82
- app.config.globalProperties['$' + key] = modules[key];
83
- });
84
- };
85
- return Utils;
86
- }());
87
- var utils = new Utils();
88
-
89
- module.exports = utils;
package/dist/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- declare class Utils {
2
- [key: string]: Object;
3
- constructor();
4
- /**
5
- * 挂载各组件
6
- * 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
7
- * @param {Object} app 需要挂载的目标对象
8
- */
9
- install(app: any): void;
10
- }
11
- declare const utils: Utils;
12
- export default utils;
package/dist/index.esm.js DELETED
@@ -1,87 +0,0 @@
1
- /**
2
- * @file Cookie
3
- * @Author: wanghui
4
- * @createBy: @2021.01.21
5
- */
6
- var CookieClass = /** @class */ (function () {
7
- function CookieClass() {
8
- }
9
- /**
10
- * 获取cookie
11
- * @param {String} name
12
- * @return {String}
13
- */
14
- CookieClass.prototype.getCookie = function (name) {
15
- var _name = name + '=';
16
- var ca = document.cookie.split(';');
17
- for (var i = 0; i < ca.length; i++) {
18
- var c = ca[i];
19
- while (c.charAt(0) === ' ')
20
- c = c.substring(1);
21
- if (c.includes(_name))
22
- return c.substring(_name.length, c.length);
23
- }
24
- return '';
25
- };
26
- /**
27
- * 设置cookie
28
- * @param {Object} ICookie
29
- */
30
- CookieClass.prototype.setCookie = function (_a) {
31
- 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;
32
- var d = new Date();
33
- d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
34
- var expires = "expires=" + d.toUTCString();
35
- document.cookie = name + "=" + value + ";" + expires + ";path=" + path + ";domain=" + domain + ";";
36
- };
37
- /**
38
- * 清除Cookie
39
- * @param {String} name
40
- */
41
- CookieClass.prototype.clearCookie = function (name) {
42
- this.setCookie({
43
- name: name,
44
- value: '',
45
- exdays: -1,
46
- });
47
- };
48
- return CookieClass;
49
- }());
50
- var cookie = new CookieClass();
51
-
52
- /**
53
- * @Author: wanghui
54
- * createBy: @2020.05.21
55
- */
56
- // import date from './modules/date'
57
- // import dom from './modules/dom'
58
- // import filter from './modules/filter'
59
- // import format from './modules/format'
60
- // import match from './modules/match'
61
- // import number from './modules/number'
62
- // import tools from './modules/tools'
63
- var modules = {
64
- cookie: cookie,
65
- };
66
- var Utils = /** @class */ (function () {
67
- function Utils() {
68
- Object.assign(this, modules);
69
- }
70
- /**
71
- * 挂载各组件
72
- * 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
73
- * @param {Object} app 需要挂载的目标对象
74
- */
75
- Utils.prototype.install = function (app) {
76
- Object.keys(modules).forEach(function (key) {
77
- if (key === 'filter') {
78
- return modules[key].install(app);
79
- }
80
- app.config.globalProperties['$' + key] = modules[key];
81
- });
82
- };
83
- return Utils;
84
- }());
85
- var utils = new Utils();
86
-
87
- export { utils as default };
@@ -1,2 +0,0 @@
1
- declare const _default: {};
2
- export default _default;
@@ -1,27 +0,0 @@
1
- interface ICookie {
2
- name: string;
3
- value: string;
4
- exdays: number;
5
- path?: string;
6
- domain?: string;
7
- }
8
- declare class CookieClass {
9
- /**
10
- * 获取cookie
11
- * @param {String} name
12
- * @return {String}
13
- */
14
- getCookie(name: string): string;
15
- /**
16
- * 设置cookie
17
- * @param {Object} ICookie
18
- */
19
- setCookie({ name, value, exdays, path, domain, }: ICookie): void;
20
- /**
21
- * 清除Cookie
22
- * @param {String} name
23
- */
24
- clearCookie(name: string): void;
25
- }
26
- declare const _default: CookieClass;
27
- export default _default;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
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,13 +0,0 @@
1
- interface Obj {
2
- [prop: string]: any;
3
- }
4
- declare class Format {
5
- /**
6
- * @desc 对于对象非数字与布尔值的value,当其为falsy时,转换成separator
7
- * @param {object} obj 传入的对象
8
- * @param {string} separator 替换后的值
9
- * transformObjectNullVal({ a: null, b: 0}, '23') // {a: "23", b: 0}
10
- * @return {object}
11
- */
12
- transformObjectNullVal<T extends Obj>(obj: T, separator?: string): T;
13
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,39 +0,0 @@
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,15 +0,0 @@
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 +0,0 @@
1
- export {};