@haluo/util 2.0.20 → 2.0.21

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 (43) hide show
  1. package/dist/index.js +33 -64
  2. package/dist/modules/cookie/index.js +18 -24
  3. package/dist/modules/date/index.js +49 -56
  4. package/dist/modules/dom/index.js +16 -23
  5. package/dist/modules/filter/index.js +15 -25
  6. package/dist/modules/format/index.js +6 -12
  7. package/dist/modules/match/index.js +6 -10
  8. package/dist/modules/monitor/index.js +7 -14
  9. package/dist/modules/monitor/lib/jsError.js +39 -35
  10. package/dist/modules/monitor/lib/timing.js +24 -28
  11. package/dist/modules/monitor/lib/xhr.js +26 -33
  12. package/dist/modules/monitor/utils/onload.js +1 -4
  13. package/dist/modules/monitor/utils/tracker.js +13 -27
  14. package/dist/modules/number/index.js +31 -35
  15. package/dist/modules/open-app/index.js +66 -61
  16. package/dist/modules/sentry/index.js +19 -27
  17. package/dist/modules/tools/index.d.ts +1 -1
  18. package/dist/modules/tools/index.js +158 -169
  19. package/dist/modules/upload/aliOss.d.ts +97 -45
  20. package/dist/modules/upload/aliOss.js +437 -575
  21. package/dist/modules/upload/index.d.ts +46 -1
  22. package/dist/modules/upload/index.js +41 -12
  23. package/dist/tsconfig.tsbuildinfo +1 -1
  24. package/dist/types/index.js +1 -2
  25. package/package.json +15 -4
  26. package/dist/modules/upload/ALIOSS_EXAMPLE.d.ts +0 -83
  27. package/dist/modules/upload/ALIOSS_EXAMPLE.js +0 -320
  28. package/dist/types/modules/cookie/index.d.ts +0 -27
  29. package/dist/types/modules/date/index.d.ts +0 -52
  30. package/dist/types/modules/dom/index.d.ts +0 -28
  31. package/dist/types/modules/filter/index.d.ts +0 -24
  32. package/dist/types/modules/format/index.d.ts +0 -15
  33. package/dist/types/modules/match/index.d.ts +0 -12
  34. package/dist/types/modules/monitor/index.d.ts +0 -3
  35. package/dist/types/modules/monitor/lib/jsError.d.ts +0 -1
  36. package/dist/types/modules/monitor/lib/timing.d.ts +0 -1
  37. package/dist/types/modules/monitor/lib/xhr.d.ts +0 -1
  38. package/dist/types/modules/monitor/utils/onload.d.ts +0 -1
  39. package/dist/types/modules/monitor/utils/tracker.d.ts +0 -7
  40. package/dist/types/modules/number/index.d.ts +0 -41
  41. package/dist/types/modules/sentry/index.d.ts +0 -15
  42. package/dist/types/modules/tools/index.d.ts +0 -166
  43. package/dist/types/types/index.d.ts +0 -3
@@ -1,8 +1,3 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
1
  /**
7
2
  * H5打开APP工具类
8
3
  *
@@ -10,17 +5,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
5
  * 1、应用宝打开app指定页面,参考今日头条
11
6
  * 2、浏览器中进入页面立即打开app,参考掘金
12
7
  */
13
- var qs_1 = __importDefault(require("qs"));
14
- var tools_1 = __importDefault(require("../tools"));
15
- var OpenAppClass = /** @class */ (function () {
8
+ import qs from 'qs';
9
+ import tools from '../tools';
10
+ class OpenAppClass {
11
+ env;
12
+ postJddTrack;
13
+ trackId;
14
+ openAppState;
15
+ ua;
16
+ _wx;
17
+ _android;
18
+ _isHarmonyos;
19
+ _ios;
20
+ _isPrice;
21
+ currentEnv;
22
+ appUrl;
23
+ appStoreUrl;
24
+ underway;
16
25
  /**
17
26
  * @param {Object} env - 环境配置,必须
18
27
  * @param {Function} postJddTrack - 埋点方法,必须
19
28
  * @param {String} trackId - 埋点id,可选
20
29
  * @param {Object} openAppState - 打开app状态,可选
21
30
  */
22
- function OpenAppClass(env, postJddTrack, trackId, openAppState) {
23
- if (trackId === void 0) { trackId = 'S_00000000000108'; }
31
+ constructor(env, postJddTrack, trackId = 'S_00000000000108', openAppState) {
24
32
  this.env = env; // 环境配置,必须
25
33
  this.postJddTrack = postJddTrack; // 埋点方法,必须
26
34
  this.trackId = trackId; // 埋点id,可选
@@ -40,8 +48,8 @@ var OpenAppClass = /** @class */ (function () {
40
48
  /**
41
49
  * 根据域名动态获取配置,保证多项目代码一样
42
50
  */
43
- OpenAppClass.prototype.getCurrentEnv = function () {
44
- var host = location.host;
51
+ getCurrentEnv() {
52
+ const host = location.host;
45
53
  if (host.includes('58moto')) {
46
54
  this.currentEnv = {
47
55
  motoAndroidScheme: this.env.motoAndroidScheme,
@@ -66,11 +74,11 @@ var OpenAppClass = /** @class */ (function () {
66
74
  APPLINKIOS: this.env.BIAOFINEAPPLINKIOS,
67
75
  };
68
76
  }
69
- };
77
+ }
70
78
  /**
71
79
  * 打开APP主流程
72
80
  */
73
- OpenAppClass.prototype.invoke = function () {
81
+ invoke() {
74
82
  if (this.underway) {
75
83
  return;
76
84
  }
@@ -81,13 +89,13 @@ var OpenAppClass = /** @class */ (function () {
81
89
  }
82
90
  this.underway = true;
83
91
  // 生成url并且放到剪贴板
84
- var url = this.getSechmaUrl();
92
+ let url = this.getSechmaUrl();
85
93
  if (url) {
86
- tools_1.default.clipboard(url);
94
+ tools.clipboard(url);
87
95
  }
88
- var apk = JSON.parse(sessionStorage.getItem('downloadApk') || '{}');
89
- var tag = this._ios ? (apk.channelName ? "App Store-".concat(apk.channelName) : 'App Store') : (apk.channelName ? "\u6E20\u9053".concat(apk.channelName, "\u5305") : '安卓包');
90
- this.postJddTrack(this.trackId, { tag: tag });
96
+ const apk = JSON.parse(sessionStorage.getItem('downloadApk') || '{}');
97
+ const tag = this._ios ? (apk.channelName ? `App Store-${apk.channelName}` : 'App Store') : (apk.channelName ? `渠道${apk.channelName}包` : '安卓包');
98
+ this.postJddTrack(this.trackId, { tag });
91
99
  // 厂家版 app
92
100
  if (this._android && location.href.includes('downloadPrise')) {
93
101
  window.location.href = (apk && apk.path) || this.appUrl;
@@ -97,7 +105,7 @@ var OpenAppClass = /** @class */ (function () {
97
105
  // 客户端打开app-下载页特殊处理
98
106
  if (location.href.includes('download') && window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
99
107
  this.underway = false;
100
- return window.AppCall.openOtherAppUrlRouter({ appUrlRouter: "https://".concat(location.host, "/home") });
108
+ return window.AppCall.openOtherAppUrlRouter({ appUrlRouter: `https://${location.host}/home` });
101
109
  }
102
110
  // 客户端打开app
103
111
  if (window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
@@ -110,22 +118,21 @@ var OpenAppClass = /** @class */ (function () {
110
118
  url = this.appStoreUrl;
111
119
  }
112
120
  this.open(url);
113
- };
121
+ }
114
122
  // 获取自定义的url
115
- OpenAppClass.prototype.getUrl = function () {
116
- var searchParams = qs_1.default.parse(location.search.slice(1)); // 路由的query
117
- var url = searchParams.customOpenUrl || window.location.href;
123
+ getUrl() {
124
+ const searchParams = qs.parse(location.search.slice(1)); // 路由的query
125
+ const url = searchParams.customOpenUrl || window.location.href;
118
126
  return url;
119
- };
127
+ }
120
128
  /**
121
129
  * 获取打开 app sechma url
122
130
  * @returns {string | undefined} 打开app的schema或跳转链接
123
131
  * params:params={"type":"","id":0,"name":"","travelId":0}
124
132
  * type:原生页面key(必须);id:页面id(可选);subject 短话题、版块名称 或 页面标题(可选);travelId 游记id(可选)
125
133
  */
126
- OpenAppClass.prototype.getSechmaUrl = function () {
127
- var _a, _b;
128
- var keys = {
134
+ getSechmaUrl() {
135
+ const keys = {
129
136
  '/posts/': 'thread_detail',
130
137
  '/detailedForum/': 'forum_detail',
131
138
  '/video/': 'video_detail',
@@ -144,96 +151,94 @@ var OpenAppClass = /** @class */ (function () {
144
151
  '/coupon-detail': 'coupon_detail',
145
152
  '/news/': 'essay_detail' // 文章详情
146
153
  };
147
- var target = Object.keys(keys).filter(function (value) {
154
+ const target = Object.keys(keys).filter(function (value) {
148
155
  return window.location.href.indexOf(value) > -1;
149
156
  });
150
- var type = target && target[0] && keys[target[0]];
151
- var searchParams = qs_1.default.parse(location.search.slice(1)); // 路由的query
152
- var id = parseInt(location.pathname.split('/').reverse()[0]) ||
157
+ const type = target && target[0] && keys[target[0]];
158
+ const searchParams = qs.parse(location.search.slice(1)); // 路由的query
159
+ const id = parseInt(location.pathname.split('/').reverse()[0]) ||
153
160
  parseInt(searchParams.id) ||
154
161
  parseInt(searchParams.carId) ||
155
162
  parseInt(searchParams.goodId); // 页面id
156
- var subject = searchParams.subject || undefined; // 页面标题或name
157
- var temp = {
163
+ const subject = searchParams.subject || undefined; // 页面标题或name
164
+ const temp = {
158
165
  relationType: type,
159
166
  id: id,
160
167
  name: subject
161
168
  };
162
- var data = ((_b = (_a = this.openAppState) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.openApps) || {};
163
- var open_url = '';
169
+ const data = this.openAppState?.state?.openApps || {};
170
+ let open_url = '';
164
171
  if (data.type && data.href === window.location.href) {
165
172
  temp.relationType = keys[data.type] || '';
166
173
  temp.id = data.id || '';
167
174
  temp.name = data.title || '';
168
175
  open_url = data.url || '';
169
176
  }
170
- var openUrl = open_url || searchParams.customOpenUrl || window.location.href;
177
+ const openUrl = open_url || searchParams.customOpenUrl || window.location.href;
171
178
  // activityId 大于零,type 为 activity
172
179
  if (searchParams.activityId) {
173
180
  temp.relationType = 'activity';
174
181
  temp.link = decodeURIComponent(decodeURIComponent(openUrl));
175
182
  }
176
183
  temp.jumpUrl = decodeURIComponent(decodeURIComponent(openUrl));
177
- var params = JSON.stringify(temp);
184
+ const params = JSON.stringify(temp);
178
185
  if (this._ios) {
179
- return "".concat(this.currentEnv.motoIOSScheme, "?params=").concat(params);
186
+ return `${this.currentEnv.motoIOSScheme}?params=${params}`;
180
187
  }
181
188
  if (this._android || this._isHarmonyos) {
182
- var url = this._wx ? "".concat(this.appUrl, "&android_scheme=").concat(this.currentEnv.motoAndroidScheme, "?params=").concat(params) : "".concat(this.currentEnv.motoAndroidScheme, "?params=").concat(params);
189
+ const url = this._wx ? `${this.appUrl}&android_scheme=${this.currentEnv.motoAndroidScheme}?params=${params}` : `${this.currentEnv.motoAndroidScheme}?params=${params}`;
183
190
  return url;
184
191
  }
185
192
  return undefined;
186
- };
193
+ }
187
194
  /**
188
195
  * 方法一(推荐):打开APP
189
196
  * http://www.cnblogs.com/shadajin/p/5724117.html
190
197
  */
191
- OpenAppClass.prototype.open = function (openUrl) {
192
- var _this = this;
198
+ open(openUrl) {
193
199
  if (!openUrl) {
194
200
  this.underway = false;
195
201
  return;
196
202
  }
197
203
  if (this._ios) {
198
204
  this.underway = false;
199
- setTimeout(function () { return (location.href = _this.appStoreUrl || ''); }, 3000);
205
+ setTimeout(() => (location.href = this.appStoreUrl || ''), 3000);
200
206
  return (location.href = openUrl);
201
207
  }
202
208
  if (this._android) {
203
- var ifr_1 = document.createElement('iframe');
204
- ifr_1.src = openUrl;
205
- ifr_1.style.display = 'none';
206
- document.body.appendChild(ifr_1);
209
+ const ifr = document.createElement('iframe');
210
+ ifr.src = openUrl;
211
+ ifr.style.display = 'none';
212
+ document.body.appendChild(ifr);
207
213
  setTimeout(function () {
208
- document.body.removeChild(ifr_1);
214
+ document.body.removeChild(ifr);
209
215
  }, 3000);
210
216
  }
211
- return new Promise(function (resolve, reject) {
217
+ return new Promise((resolve, reject) => {
212
218
  // 检查APP是否打开
213
- var check = function (elsTime) {
219
+ const check = (elsTime) => {
214
220
  if (elsTime > 3000 || document.hidden) {
215
221
  // @ts-ignore
216
222
  resolve('成功打开APP');
217
223
  }
218
224
  else {
219
225
  // @ts-ignore
220
- window.location.href = "https://".concat(location.host, "/download");
226
+ window.location.href = `https://${location.host}/download`;
221
227
  reject('打开APP失败');
222
228
  }
223
- _this.underway = false;
229
+ this.underway = false;
224
230
  };
225
- var _count = 0;
226
- var _clickTime = +new Date();
227
- var intHandle = setInterval(function () {
231
+ let _count = 0;
232
+ const _clickTime = +new Date();
233
+ const intHandle = setInterval(() => {
228
234
  _count++;
229
- var elsTime = +new Date() - _clickTime;
235
+ const elsTime = +new Date() - _clickTime;
230
236
  if (_count >= 100 || elsTime > 3000) {
231
237
  clearInterval(intHandle);
232
238
  check(elsTime);
233
239
  }
234
240
  }, 20);
235
241
  });
236
- };
237
- return OpenAppClass;
238
- }());
239
- exports.default = OpenAppClass;
242
+ }
243
+ }
244
+ export default OpenAppClass;
@@ -7,75 +7,67 @@
7
7
  * 3.自动捕获没有被catch的运行异常
8
8
  */
9
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"));
10
+ import Raven from 'raven-js';
15
11
  // import RavenVue from 'raven-js/plugins/vue';
16
- var Report = /** @class */ (function () {
17
- function Report(Vue, options) {
18
- if (options === void 0) { options = {}; }
12
+ class Report {
13
+ static instance;
14
+ constructor(Vue, options = {}) {
19
15
  if (process.env.NODE_ENV !== 'development') {
20
16
  // todo
21
17
  }
22
18
  this.vue = Vue;
23
19
  this.options = options;
24
20
  }
25
- Report.getInstance = function (Vue, Option) {
21
+ static getInstance(Vue, Option) {
26
22
  if (!(this.instance instanceof this)) {
27
23
  this.instance = new this(Vue, Option);
28
24
  this.instance.install();
29
25
  }
30
26
  return this.instance;
31
- };
32
- Report.prototype.install = function () {
27
+ }
28
+ install() {
33
29
  if (process.env.NODE_ENV !== 'development') {
34
30
  // Raven.config(this.options.dsn, {
35
31
  // environment: process.env.NODE_ENV,
36
32
  // }).addPlugin(RavenVue, this.Vue).install();
37
33
  // raven内置了vue插件,会通过vue.config.errorHandler来捕获vue组件内错误并上报sentry服务
38
34
  // 记录用户信息
39
- raven_js_1.default.setUserContext({ user: this.options.user || '' });
35
+ Raven.setUserContext({ user: this.options.user || '' });
40
36
  // 设置全局tag标签
41
- raven_js_1.default.setTagsContext({ environment: this.options.env || '' });
37
+ Raven.setTagsContext({ environment: this.options.env || '' });
42
38
  }
43
- };
39
+ }
44
40
  /**
45
41
  * 主动上报
46
42
  * @param {String} data
47
43
  * @param {String} type 'info','warning','error'
48
44
  * @param {Object} options
49
45
  */
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 = {}; }
46
+ log(data = null, type = 'error', options = {}) {
54
47
  // 添加面包屑
55
- raven_js_1.default.captureBreadcrumb({
48
+ Raven.captureBreadcrumb({
56
49
  message: data,
57
50
  category: 'manual message',
58
51
  });
59
52
  // 异常上报
60
53
  if (data instanceof Error) {
61
- raven_js_1.default.captureException(data, {
54
+ Raven.captureException(data, {
62
55
  level: type,
63
56
  logger: 'manual exception',
64
- tags: { options: options },
57
+ tags: { options },
65
58
  });
66
59
  }
67
60
  else {
68
- raven_js_1.default.captureException('error', {
61
+ Raven.captureException('error', {
69
62
  level: type,
70
63
  logger: 'manual data',
71
64
  extra: {
72
- data: data,
65
+ data,
73
66
  options: this.options,
74
67
  date: new Date(),
75
68
  },
76
69
  });
77
70
  }
78
- };
79
- return Report;
80
- }());
81
- exports.default = Report;
71
+ }
72
+ }
73
+ export default Report;
@@ -76,7 +76,7 @@ declare class ToolsClass {
76
76
  * @param {String} str
77
77
  * @return {String}
78
78
  */
79
- clipboard(str: string): any;
79
+ clipboard(str: string): Error | Promise<void>;
80
80
  /**
81
81
  * 首字母大写
82
82
  * @param {String} str