@king-one/monitor 1.0.5 → 1.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.
- package/CHANGELOG.md +12 -0
- package/dist/cdn/index.umd.js +2 -2
- package/dist/es/index.mjs +10 -8
- package/dist/es/src/EventEmitter.mjs +25 -36
- package/dist/es/src/SourceError.mjs +45 -62
- package/dist/es/src/core.mjs +80 -107
- package/dist/es/src/index.mjs +10 -8
- package/dist/es/src/integrations/BrowserError.mjs +39 -48
- package/dist/es/src/integrations/VueError.mjs +20 -22
- package/dist/es/src/utils.mjs +71 -82
- package/dist/lib/index.js +1 -11
- package/dist/lib/src/EventEmitter.js +1 -77
- package/dist/lib/src/SourceError.js +4 -83
- package/dist/lib/src/core.js +1 -239
- package/dist/lib/src/index.js +1 -10
- package/dist/lib/src/integrations/BrowserError.js +1 -76
- package/dist/lib/src/integrations/VueError.js +1 -27
- package/dist/lib/src/utils.js +1 -117
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/types.d.ts +1 -0
- package/dist/types/src/utils.d.ts +1 -0
- package/package.json +1 -1
package/dist/es/src/core.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { EventEmitter } from "./EventEmitter.mjs";
|
|
5
|
-
import { SourceError } from "./SourceError.mjs";
|
|
6
|
-
import { stringify } from "./utils.mjs";
|
|
7
|
-
const
|
|
1
|
+
var p = Object.defineProperty;
|
|
2
|
+
var h = (o, t, e) => t in o ? p(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
|
+
var n = (o, t, e) => h(o, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { EventEmitter as c } from "./EventEmitter.mjs";
|
|
5
|
+
import { SourceError as f } from "./SourceError.mjs";
|
|
6
|
+
import { stringify as l } from "./utils.mjs";
|
|
7
|
+
const r = class r {
|
|
8
8
|
/**
|
|
9
9
|
* 取消订阅错误上报事件
|
|
10
10
|
* @param callback - 错误上报回调函数
|
|
@@ -15,33 +15,28 @@ const _ErrorMonitor = class _ErrorMonitor {
|
|
|
15
15
|
/**
|
|
16
16
|
* 私有构造函数,防止外部直接实例化
|
|
17
17
|
*/
|
|
18
|
-
constructor(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
constructor(t) {
|
|
19
|
+
n(this, "options");
|
|
20
|
+
n(this, "event");
|
|
21
|
+
n(this, "source");
|
|
22
22
|
// 错误事件类型常量
|
|
23
|
-
|
|
24
|
-
this.options = this.validateOptions(
|
|
25
|
-
this.event = new EventEmitter();
|
|
26
|
-
this.source = new SourceError();
|
|
27
|
-
this.init();
|
|
28
|
-
if (options.integrations)
|
|
29
|
-
this.initIntegrations();
|
|
23
|
+
n(this, "ERROR_REPORTED", "error-reported");
|
|
24
|
+
this.options = this.validateOptions(t), this.event = new c(), this.source = new f(), this.init(), t.integrations && this.initIntegrations();
|
|
30
25
|
}
|
|
31
26
|
/**
|
|
32
27
|
* 订阅错误上报事件
|
|
33
28
|
* @param callback - 错误上报回调函数
|
|
34
29
|
*/
|
|
35
|
-
onErrorReported(
|
|
36
|
-
this.event.on(this.ERROR_REPORTED,
|
|
30
|
+
onErrorReported(t) {
|
|
31
|
+
this.event.on(this.ERROR_REPORTED, t);
|
|
37
32
|
}
|
|
38
33
|
initIntegrations() {
|
|
39
|
-
var
|
|
40
|
-
(
|
|
34
|
+
var t;
|
|
35
|
+
(t = this.options.integrations) == null || t.forEach((e) => {
|
|
41
36
|
try {
|
|
42
|
-
|
|
43
|
-
} catch (
|
|
44
|
-
console.error(`Failed to initialize integration ${
|
|
37
|
+
e.install(this);
|
|
38
|
+
} catch (i) {
|
|
39
|
+
console.error(`Failed to initialize integration ${e.name}:`, i);
|
|
45
40
|
}
|
|
46
41
|
});
|
|
47
42
|
}
|
|
@@ -50,10 +45,9 @@ const _ErrorMonitor = class _ErrorMonitor {
|
|
|
50
45
|
* @throws {Error} 当实例未初始化时抛出错误
|
|
51
46
|
*/
|
|
52
47
|
static getInstance() {
|
|
53
|
-
if (!
|
|
48
|
+
if (!r.instance)
|
|
54
49
|
throw new Error("ErrorMonitor未初始化,请先调用initialize方法");
|
|
55
|
-
|
|
56
|
-
return _ErrorMonitor.instance;
|
|
50
|
+
return r.instance;
|
|
57
51
|
}
|
|
58
52
|
/**
|
|
59
53
|
* 静态方法:手动上报错误信息
|
|
@@ -80,17 +74,15 @@ const _ErrorMonitor = class _ErrorMonitor {
|
|
|
80
74
|
* @returns 处理后的完整配置项
|
|
81
75
|
* @throws {Error} 当必要配置项缺失时抛出错误
|
|
82
76
|
*/
|
|
83
|
-
validateOptions(
|
|
84
|
-
if (!
|
|
77
|
+
validateOptions(t) {
|
|
78
|
+
if (!t.url)
|
|
85
79
|
throw new Error("上报地址url不能为空");
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
throw new Error("应用标识appId不能为空");
|
|
89
|
-
}
|
|
80
|
+
if (!t.appId)
|
|
81
|
+
throw new Error("平台标识appId不能为空");
|
|
90
82
|
return {
|
|
91
83
|
env: "development",
|
|
92
84
|
sampleRate: 1,
|
|
93
|
-
...
|
|
85
|
+
...t
|
|
94
86
|
};
|
|
95
87
|
}
|
|
96
88
|
/**
|
|
@@ -98,8 +90,8 @@ const _ErrorMonitor = class _ErrorMonitor {
|
|
|
98
90
|
* 包括:JS运行时错误、Promise异常、资源加载错误
|
|
99
91
|
*/
|
|
100
92
|
init() {
|
|
101
|
-
this.onErrorReported((
|
|
102
|
-
this.reportError(
|
|
93
|
+
this.onErrorReported((t) => {
|
|
94
|
+
this.reportError(t);
|
|
103
95
|
});
|
|
104
96
|
}
|
|
105
97
|
/**
|
|
@@ -118,66 +110,53 @@ const _ErrorMonitor = class _ErrorMonitor {
|
|
|
118
110
|
* 上报错误信息到服务器
|
|
119
111
|
* @param errorInfo - 错误信息对象
|
|
120
112
|
*/
|
|
121
|
-
report(
|
|
122
|
-
if (Math.random() > (this.options.sampleRate || 1))
|
|
113
|
+
report(t) {
|
|
114
|
+
if (Math.random() > (this.options.sampleRate || 1))
|
|
123
115
|
return;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
...errorInfo,
|
|
116
|
+
let e = {
|
|
117
|
+
...t,
|
|
127
118
|
appId: this.options.appId,
|
|
128
119
|
env: this.options.env
|
|
129
|
-
};
|
|
130
|
-
let url = this.options.url;
|
|
120
|
+
}, i = this.options.url;
|
|
131
121
|
if (this.options.paramsSerializer) {
|
|
132
|
-
const
|
|
133
|
-
|
|
122
|
+
const s = this.options.paramsSerializer();
|
|
123
|
+
i = `${i}?${l(s)}`;
|
|
134
124
|
}
|
|
135
125
|
if (this.options.beforeSend) {
|
|
136
|
-
const
|
|
137
|
-
if (!
|
|
126
|
+
const s = this.options.beforeSend(e);
|
|
127
|
+
if (!s)
|
|
138
128
|
return;
|
|
139
|
-
|
|
140
|
-
reportData = result;
|
|
141
|
-
}
|
|
142
|
-
if (navigator.sendBeacon) {
|
|
143
|
-
navigator.sendBeacon(url, JSON.stringify(reportData));
|
|
144
|
-
} else {
|
|
145
|
-
fetch(url, {
|
|
146
|
-
method: "POST",
|
|
147
|
-
body: JSON.stringify(reportData),
|
|
148
|
-
headers: {
|
|
149
|
-
"Content-Type": "application/json"
|
|
150
|
-
},
|
|
151
|
-
keepalive: true
|
|
152
|
-
}).catch(() => {
|
|
153
|
-
});
|
|
129
|
+
e = s;
|
|
154
130
|
}
|
|
131
|
+
navigator.sendBeacon ? navigator.sendBeacon(i, JSON.stringify(e)) : fetch(i, {
|
|
132
|
+
method: "POST",
|
|
133
|
+
body: JSON.stringify(e),
|
|
134
|
+
headers: {
|
|
135
|
+
"Content-Type": "text/plain"
|
|
136
|
+
},
|
|
137
|
+
keepalive: !0
|
|
138
|
+
}).catch(() => {
|
|
139
|
+
});
|
|
155
140
|
}
|
|
156
141
|
/**
|
|
157
142
|
* 标准化错误信息
|
|
158
143
|
* @param error - 原始错误信息
|
|
159
144
|
* @returns 标准化后的错误信息对象
|
|
160
145
|
*/
|
|
161
|
-
normalizeError(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
stack: error.stack,
|
|
174
|
-
extraInfo: this.options.extraInfo,
|
|
175
|
-
...this.getClientInfo()
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
return {
|
|
146
|
+
normalizeError(t) {
|
|
147
|
+
return this.isErrorInfo(t) ? {
|
|
148
|
+
...t,
|
|
149
|
+
extraInfo: { ...this.options.extraInfo, ...t.extraInfo },
|
|
150
|
+
...this.getClientInfo()
|
|
151
|
+
} : t instanceof Error ? {
|
|
152
|
+
type: t.name,
|
|
153
|
+
message: t.message,
|
|
154
|
+
stack: t.stack,
|
|
155
|
+
extraInfo: this.options.extraInfo,
|
|
156
|
+
...this.getClientInfo()
|
|
157
|
+
} : {
|
|
179
158
|
type: "Error",
|
|
180
|
-
message:
|
|
159
|
+
message: t,
|
|
181
160
|
extraInfo: this.options.extraInfo,
|
|
182
161
|
...this.getClientInfo()
|
|
183
162
|
};
|
|
@@ -187,16 +166,14 @@ const _ErrorMonitor = class _ErrorMonitor {
|
|
|
187
166
|
* @param error - 待检查的错误信息
|
|
188
167
|
* @returns 是否为 ErrorInfo 类型
|
|
189
168
|
*/
|
|
190
|
-
isErrorInfo(
|
|
191
|
-
return typeof
|
|
169
|
+
isErrorInfo(t) {
|
|
170
|
+
return typeof t == "object" && t !== null && "type" in t && "message" in t;
|
|
192
171
|
}
|
|
193
|
-
reportError(
|
|
194
|
-
if (!
|
|
172
|
+
reportError(t) {
|
|
173
|
+
if (!r.instance)
|
|
195
174
|
throw new Error("ErrorMonitor未初始化,请先调用initialize方法");
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
console.log("errorInfo", errorInfo);
|
|
199
|
-
this.report(errorInfo);
|
|
175
|
+
const e = this.normalizeError(t);
|
|
176
|
+
this.report(e);
|
|
200
177
|
}
|
|
201
178
|
/**
|
|
202
179
|
* 初始化错误监控实例
|
|
@@ -204,36 +181,32 @@ const _ErrorMonitor = class _ErrorMonitor {
|
|
|
204
181
|
* @returns ErrorMonitor实例
|
|
205
182
|
* @throws {Error} 当重复初始化或配置项缺失时抛出错误
|
|
206
183
|
*/
|
|
207
|
-
static initialize(
|
|
208
|
-
if (
|
|
184
|
+
static initialize(t) {
|
|
185
|
+
if (r.instance)
|
|
209
186
|
throw new Error("ErrorMonitor已经初始化,请勿重复初始化");
|
|
210
|
-
|
|
211
|
-
_ErrorMonitor.instance = new _ErrorMonitor(options);
|
|
212
|
-
return _ErrorMonitor.instance;
|
|
187
|
+
return r.instance = new r(t), r.instance;
|
|
213
188
|
}
|
|
214
189
|
/**
|
|
215
190
|
* 销毁实例,清理资源
|
|
216
191
|
*/
|
|
217
192
|
static destroy() {
|
|
218
|
-
|
|
219
|
-
_ErrorMonitor.instance = null;
|
|
220
|
-
}
|
|
193
|
+
r.instance && (r.instance = null);
|
|
221
194
|
}
|
|
222
|
-
static captureError(
|
|
223
|
-
|
|
195
|
+
static captureError(t) {
|
|
196
|
+
r.getInstance().reportError(t);
|
|
224
197
|
}
|
|
225
|
-
emitError(
|
|
226
|
-
this.event.emit(this.ERROR_REPORTED,
|
|
198
|
+
emitError(t) {
|
|
199
|
+
this.event.emit(this.ERROR_REPORTED, t);
|
|
227
200
|
}
|
|
228
|
-
async getErrorSource(
|
|
229
|
-
return this.source.getErrorSource(
|
|
201
|
+
async getErrorSource(t) {
|
|
202
|
+
return this.source.getErrorSource(t);
|
|
230
203
|
}
|
|
231
204
|
get env() {
|
|
232
205
|
return this.options.env;
|
|
233
206
|
}
|
|
234
207
|
};
|
|
235
|
-
|
|
236
|
-
let
|
|
208
|
+
n(r, "instance", null);
|
|
209
|
+
let a = r;
|
|
237
210
|
export {
|
|
238
|
-
ErrorMonitor
|
|
211
|
+
a as ErrorMonitor
|
|
239
212
|
};
|
package/dist/es/src/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { ErrorMonitor } from "./core.mjs";
|
|
2
|
-
import { SourceError } from "./SourceError.mjs";
|
|
3
|
-
import { VueError } from "./integrations/VueError.mjs";
|
|
4
|
-
import { BrowserError } from "./integrations/BrowserError.mjs";
|
|
1
|
+
import { ErrorMonitor as e } from "./core.mjs";
|
|
2
|
+
import { SourceError as m } from "./SourceError.mjs";
|
|
3
|
+
import { VueError as f } from "./integrations/VueError.mjs";
|
|
4
|
+
import { BrowserError as E } from "./integrations/BrowserError.mjs";
|
|
5
|
+
import { timestampToBase66 as a } from "./utils.mjs";
|
|
5
6
|
export {
|
|
6
|
-
BrowserError,
|
|
7
|
-
ErrorMonitor,
|
|
8
|
-
SourceError,
|
|
9
|
-
VueError
|
|
7
|
+
E as BrowserError,
|
|
8
|
+
e as ErrorMonitor,
|
|
9
|
+
m as SourceError,
|
|
10
|
+
f as VueError,
|
|
11
|
+
a as timestampToBase66
|
|
10
12
|
};
|
|
@@ -1,76 +1,67 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { getClientInfo } from "../utils.mjs";
|
|
5
|
-
class
|
|
1
|
+
var a = Object.defineProperty;
|
|
2
|
+
var m = (t, r, o) => r in t ? a(t, r, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[r] = o;
|
|
3
|
+
var i = (t, r, o) => m(t, typeof r != "symbol" ? r + "" : r, o);
|
|
4
|
+
import { getClientInfo as n } from "../utils.mjs";
|
|
5
|
+
class c {
|
|
6
6
|
constructor() {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
i(this, "name", "BrowserError");
|
|
8
|
+
i(this, "monitor", null);
|
|
9
9
|
}
|
|
10
|
-
install(
|
|
11
|
-
this.monitor =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
window.addEventListener("
|
|
16
|
-
this.
|
|
17
|
-
});
|
|
18
|
-
window.addEventListener("error", (event) => {
|
|
19
|
-
if (event.target && event.target.tagName) {
|
|
20
|
-
this.handleResourceError(event);
|
|
21
|
-
}
|
|
22
|
-
}, true);
|
|
10
|
+
install(r) {
|
|
11
|
+
this.monitor = r, window.addEventListener("error", (o) => {
|
|
12
|
+
this.handleJsError(o);
|
|
13
|
+
}, !0), window.addEventListener("unhandledrejection", (o) => {
|
|
14
|
+
this.handlePromiseError(o);
|
|
15
|
+
}), window.addEventListener("error", (o) => {
|
|
16
|
+
o.target && o.target.tagName && this.handleResourceError(o);
|
|
17
|
+
}, !0);
|
|
23
18
|
}
|
|
24
19
|
/**
|
|
25
20
|
* 处理 JS 运行时错误
|
|
26
21
|
* @param event - 错误事件对象
|
|
27
22
|
*/
|
|
28
|
-
handleJsError(
|
|
29
|
-
var
|
|
30
|
-
const
|
|
31
|
-
type: (
|
|
32
|
-
message:
|
|
23
|
+
handleJsError(r) {
|
|
24
|
+
var e, s;
|
|
25
|
+
const o = {
|
|
26
|
+
type: (e = r.error) == null ? void 0 : e.name,
|
|
27
|
+
message: r.message,
|
|
33
28
|
source: {
|
|
34
|
-
fileName:
|
|
35
|
-
lineNumber:
|
|
36
|
-
columnNumber:
|
|
29
|
+
fileName: r.filename,
|
|
30
|
+
lineNumber: r.lineno,
|
|
31
|
+
columnNumber: r.colno
|
|
37
32
|
},
|
|
38
|
-
stack: (
|
|
39
|
-
...
|
|
33
|
+
stack: (s = r.error) == null ? void 0 : s.stack,
|
|
34
|
+
...n()
|
|
40
35
|
};
|
|
41
|
-
|
|
42
|
-
this.monitor.emitError(errorInfo);
|
|
36
|
+
this.monitor && this.monitor.emitError(o);
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
45
39
|
* 处理 Promise 异常
|
|
46
40
|
* @param event - Promise 异常事件对象
|
|
47
41
|
*/
|
|
48
|
-
handlePromiseError(
|
|
49
|
-
var
|
|
50
|
-
const
|
|
42
|
+
handlePromiseError(r) {
|
|
43
|
+
var e, s;
|
|
44
|
+
const o = {
|
|
51
45
|
type: "NetworkError",
|
|
52
|
-
message: ((
|
|
53
|
-
stack: (
|
|
54
|
-
...
|
|
46
|
+
message: ((e = r.reason) == null ? void 0 : e.message) || "Promise Error",
|
|
47
|
+
stack: (s = r.reason) == null ? void 0 : s.stack,
|
|
48
|
+
...n()
|
|
55
49
|
};
|
|
56
|
-
|
|
57
|
-
this.monitor.emitError(errorInfo);
|
|
50
|
+
this.monitor && this.monitor.emitError(o);
|
|
58
51
|
}
|
|
59
52
|
/**
|
|
60
53
|
* 处理资源加载错误
|
|
61
54
|
* @param event - 资源错误事件对象
|
|
62
55
|
*/
|
|
63
|
-
handleResourceError(
|
|
64
|
-
const
|
|
65
|
-
const errorInfo = {
|
|
56
|
+
handleResourceError(r) {
|
|
57
|
+
const o = r.target, e = {
|
|
66
58
|
type: "ResourceError",
|
|
67
|
-
message: `资源加载失败: ${
|
|
68
|
-
...
|
|
59
|
+
message: `资源加载失败: ${o.tagName} ${o.src || o.href}`,
|
|
60
|
+
...n()
|
|
69
61
|
};
|
|
70
|
-
|
|
71
|
-
this.monitor.emitError(errorInfo);
|
|
62
|
+
this.monitor && this.monitor.emitError(e);
|
|
72
63
|
}
|
|
73
64
|
}
|
|
74
65
|
export {
|
|
75
|
-
BrowserError
|
|
66
|
+
c as BrowserError
|
|
76
67
|
};
|
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
class
|
|
5
|
-
constructor(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.app =
|
|
1
|
+
var c = Object.defineProperty;
|
|
2
|
+
var p = (s, e, a) => e in s ? c(s, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : s[e] = a;
|
|
3
|
+
var r = (s, e, a) => p(s, typeof e != "symbol" ? e + "" : e, a);
|
|
4
|
+
class o {
|
|
5
|
+
constructor(e) {
|
|
6
|
+
r(this, "name", "VueError");
|
|
7
|
+
r(this, "app");
|
|
8
|
+
this.app = e;
|
|
9
9
|
}
|
|
10
|
-
install(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
}
|
|
10
|
+
install(e) {
|
|
11
|
+
e.env === "production" && (this.app.config.errorHandler = async (a) => {
|
|
12
|
+
const t = await e.getErrorSource(a);
|
|
13
|
+
e.emitError({
|
|
14
|
+
type: a.name,
|
|
15
|
+
message: a.message,
|
|
16
|
+
stack: a.stack,
|
|
17
|
+
source: t,
|
|
18
|
+
level: "error"
|
|
19
|
+
});
|
|
20
|
+
});
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
export {
|
|
26
|
-
VueError
|
|
24
|
+
o as VueError
|
|
27
25
|
};
|
package/dist/es/src/utils.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function x() {
|
|
2
2
|
return {
|
|
3
3
|
url: window.location.href,
|
|
4
4
|
userAgent: navigator.userAgent,
|
|
@@ -6,112 +6,101 @@ function getClientInfo() {
|
|
|
6
6
|
timestamp: Date.now()
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function V(i, c = {}) {
|
|
10
10
|
const {
|
|
11
|
-
encode =
|
|
12
|
-
encodeValuesOnly =
|
|
13
|
-
arrayFormat = "indices",
|
|
14
|
-
skipNulls =
|
|
15
|
-
delimiter = "&",
|
|
16
|
-
strictNullHandling =
|
|
17
|
-
sort,
|
|
18
|
-
filter
|
|
19
|
-
allowDots =
|
|
20
|
-
serializeDate = (
|
|
21
|
-
format = "RFC3986",
|
|
22
|
-
addQueryPrefix =
|
|
23
|
-
charset = "utf-8"
|
|
24
|
-
} =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const fullKey = prefix ? `${prefix}[${key}]` : key;
|
|
30
|
-
if (filter) {
|
|
31
|
-
const filtered = filter(fullKey, value);
|
|
32
|
-
if (filtered === void 0)
|
|
11
|
+
encode: t = !0,
|
|
12
|
+
encodeValuesOnly: f = !1,
|
|
13
|
+
arrayFormat: p = "indices",
|
|
14
|
+
skipNulls: g = !1,
|
|
15
|
+
delimiter: k = "&",
|
|
16
|
+
strictNullHandling: I = !1,
|
|
17
|
+
sort: w,
|
|
18
|
+
filter: $,
|
|
19
|
+
allowDots: y = !1,
|
|
20
|
+
serializeDate: S = (r) => r.toISOString(),
|
|
21
|
+
format: j = "RFC3986",
|
|
22
|
+
addQueryPrefix: C = !1,
|
|
23
|
+
charset: D = "utf-8"
|
|
24
|
+
} = c, l = [], E = D === "iso-8859-1" ? O : encodeURIComponent, a = (r) => t ? E(r) : r, d = (r, e, b = null) => {
|
|
25
|
+
const o = b ? `${b}[${r}]` : r;
|
|
26
|
+
if ($) {
|
|
27
|
+
const n = $(o, e);
|
|
28
|
+
if (n === void 0)
|
|
33
29
|
return;
|
|
34
|
-
|
|
30
|
+
e = n;
|
|
35
31
|
}
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
parts.push(encodeValue(fullKey) + (encodeValuesOnly ? "" : "="));
|
|
39
|
-
} else if (!skipNulls) {
|
|
40
|
-
parts.push(`${encodeValue(fullKey)}=`);
|
|
41
|
-
}
|
|
32
|
+
if (e === null) {
|
|
33
|
+
I ? l.push(a(o) + (f ? "" : "=")) : g || l.push(`${a(o)}=`);
|
|
42
34
|
return;
|
|
43
35
|
}
|
|
44
|
-
if (typeof
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
if (value instanceof Date) {
|
|
48
|
-
value = serializeDate(value);
|
|
49
|
-
}
|
|
50
|
-
if (Array.isArray(value)) {
|
|
51
|
-
if (value.length === 0 && skipNulls)
|
|
36
|
+
if ((typeof e == "boolean" || typeof e == "number") && (e = String(e)), e instanceof Date && (e = S(e)), Array.isArray(e)) {
|
|
37
|
+
if (e.length === 0 && g)
|
|
52
38
|
return;
|
|
53
|
-
switch (
|
|
39
|
+
switch (p) {
|
|
54
40
|
case "indices":
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
e.forEach((s, u) => {
|
|
42
|
+
d(String(u), s, o);
|
|
57
43
|
});
|
|
58
44
|
break;
|
|
59
45
|
case "brackets":
|
|
60
|
-
|
|
61
|
-
|
|
46
|
+
e.forEach((s) => {
|
|
47
|
+
d("", s, o);
|
|
62
48
|
});
|
|
63
49
|
break;
|
|
64
50
|
case "repeat":
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
e.forEach((s) => {
|
|
52
|
+
d(o, s);
|
|
67
53
|
});
|
|
68
54
|
break;
|
|
69
55
|
case "comma":
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
);
|
|
75
|
-
}
|
|
56
|
+
const n = e.join(",");
|
|
57
|
+
n.length > 0 && l.push(
|
|
58
|
+
`${a(o)}=${a(n)}`
|
|
59
|
+
);
|
|
76
60
|
break;
|
|
77
61
|
}
|
|
78
|
-
} else if (typeof
|
|
79
|
-
Object.keys(
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
`${fullKey}${separator}${subKey}${suffix}`
|
|
62
|
+
} else if (typeof e == "object")
|
|
63
|
+
Object.keys(e).forEach((n) => {
|
|
64
|
+
const s = y ? "." : "[", u = y ? "" : "]";
|
|
65
|
+
d(
|
|
66
|
+
n,
|
|
67
|
+
e[n],
|
|
68
|
+
`${o}${s}${n}${u}`
|
|
86
69
|
);
|
|
87
70
|
});
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
parts.push(`${encodedKey}=${encodedValue}`);
|
|
71
|
+
else {
|
|
72
|
+
const n = t && !f ? a(o) : o, s = a(String(e));
|
|
73
|
+
l.push(`${n}=${s}`);
|
|
92
74
|
}
|
|
93
75
|
};
|
|
94
|
-
let
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
keys.forEach((key) => {
|
|
99
|
-
const value = obj[key];
|
|
100
|
-
processKeyValue(key, value);
|
|
76
|
+
let m = Object.keys(i);
|
|
77
|
+
w && (m = m.sort(w)), m.forEach((r) => {
|
|
78
|
+
const e = i[r];
|
|
79
|
+
d(r, e);
|
|
101
80
|
});
|
|
102
|
-
let
|
|
103
|
-
|
|
104
|
-
result = `?${result}`;
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
81
|
+
let h = l.join(k);
|
|
82
|
+
return C && h.length > 0 && (h = `?${h}`), h;
|
|
107
83
|
}
|
|
108
|
-
function
|
|
109
|
-
return encodeURIComponent(
|
|
110
|
-
const
|
|
111
|
-
return
|
|
84
|
+
function O(i) {
|
|
85
|
+
return encodeURIComponent(i).replace(/%[0-9A-F]{2}/g, (c) => {
|
|
86
|
+
const t = Number.parseInt(c.substring(1), 16);
|
|
87
|
+
return t >= 128 && t <= 255 ? String.fromCharCode(t) : c;
|
|
112
88
|
});
|
|
113
89
|
}
|
|
90
|
+
function A(i, c = Date.now()) {
|
|
91
|
+
if (i.length !== 66)
|
|
92
|
+
throw new Error("BASE66_CHARS must contain exactly 66 characters");
|
|
93
|
+
let t = c, f = "";
|
|
94
|
+
if (t === 0)
|
|
95
|
+
return i[0];
|
|
96
|
+
for (; t > 0; ) {
|
|
97
|
+
const p = t % 66;
|
|
98
|
+
f = i[p] + f, t = Math.floor(t / 66);
|
|
99
|
+
}
|
|
100
|
+
return f;
|
|
101
|
+
}
|
|
114
102
|
export {
|
|
115
|
-
getClientInfo,
|
|
116
|
-
stringify
|
|
103
|
+
x as getClientInfo,
|
|
104
|
+
V as stringify,
|
|
105
|
+
A as timestampToBase66
|
|
117
106
|
};
|