spy-client 2.0.7 → 2.1.1
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/README.md +119 -10
- package/dist/head/base.d.ts +1 -1
- package/dist/lib/huffman.d.ts +9 -0
- package/dist/lib/interface.d.ts +59 -1
- package/dist/lib/util.d.ts +22 -0
- package/dist/module/longtask.d.ts +1 -1
- package/dist/module/resource.d.ts +19 -9
- package/dist/module/tti.d.ts +1 -1
- package/dist/spy-client-basic.esm.js +233 -1167
- package/dist/spy-client-basic.iife.js +237 -1171
- package/dist/spy-client-basic.iife.min.js +1 -1
- package/dist/spy-client-basic.js +238 -1172
- package/dist/spy-client-basic.min.js +1 -1
- package/dist/spy-client-basic.mjs +82 -54
- package/dist/spy-client.d.ts +5 -4
- package/dist/spy-client.esm.js +1393 -5662
- package/dist/spy-client.iife.js +1401 -5670
- package/dist/spy-client.iife.min.js +1 -1
- package/dist/spy-client.js +1402 -5671
- package/dist/spy-client.min.js +1 -1
- package/dist/spy-client.mjs +704 -455
- package/dist/spy-head.js +330 -276
- package/dist/spy-head.min.js +1 -1
- package/dist/spy-local-cache.d.ts +18 -0
- package/dist/spy-local-cache.js +690 -0
- package/dist/spy-local-cache.min.js +1 -0
- package/example/index.html +8 -2
- package/example/local-cache.html +97 -0
- package/example/saveCache.js +41 -0
- package/karma.conf.js +111 -0
- package/package.json +21 -20
- package/src/head/error.ts +14 -15
- package/src/head/whitescreen.ts +8 -5
- package/src/lib/huffman.ts +326 -0
- package/src/lib/interface.ts +70 -1
- package/src/lib/util.ts +101 -0
- package/src/module/resource.ts +226 -129
- package/src/spy-client-basic.ts +8 -7
- package/src/spy-client.ts +15 -6
- package/src/spy-local-cache.ts +385 -0
- package/src/types/globals.d.ts +1 -1
package/README.md
CHANGED
|
@@ -17,13 +17,13 @@ CDN方式
|
|
|
17
17
|
|
|
18
18
|
```html
|
|
19
19
|
<!--增强版SDK-->
|
|
20
|
-
<script src="https://code.bdstatic.com/npm/spy-client@2.0
|
|
20
|
+
<script src="https://code.bdstatic.com/npm/spy-client@2.1.0/dist/spy-client.min.js" type="text/javascript"></script>
|
|
21
21
|
|
|
22
22
|
<!--增强版SDK spy-head-->
|
|
23
|
-
<script src="https://code.bdstatic.com/npm/spy-client@2.0
|
|
23
|
+
<script src="https://code.bdstatic.com/npm/spy-client@2.1.0/dist/spy-head.min.js" type="text/javascript"></script>
|
|
24
24
|
|
|
25
25
|
<!--基础版SDK-->
|
|
26
|
-
<script src="https://code.bdstatic.com/npm/spy-client@2.0
|
|
26
|
+
<script src="https://code.bdstatic.com/npm/spy-client@2.1.0/dist/spy-client-basic.min.js" type="text/javascript"></script>
|
|
27
27
|
|
|
28
28
|
```
|
|
29
29
|
|
|
@@ -111,7 +111,7 @@ spy.sendPerf({
|
|
|
111
111
|
spy.sendExcept({
|
|
112
112
|
// 必须, 异常信息,msg字段是必须的,是异常唯一标识。其他字段作为补充信息,由用户自定义
|
|
113
113
|
info: {
|
|
114
|
-
msg: 'abc is not undefined',
|
|
114
|
+
msg: 'abc is not undefined', // msg字段是必须的,必须的,必须的,会统计相同msg的总量
|
|
115
115
|
stack: 'xxxxx',
|
|
116
116
|
file: 'xxxxxxx'
|
|
117
117
|
},
|
|
@@ -150,7 +150,7 @@ spy.sendExceptForError(new Error('error'), {
|
|
|
150
150
|
}
|
|
151
151
|
});
|
|
152
152
|
|
|
153
|
-
// 最基础的API
|
|
153
|
+
// 最基础的API,需要自行指定type字段
|
|
154
154
|
spy.send({
|
|
155
155
|
type: 'perf'
|
|
156
156
|
info: {
|
|
@@ -190,18 +190,18 @@ spy.clearAllMark(); // 清除所有mark的信息
|
|
|
190
190
|
|
|
191
191
|
2. spy-client:此部分提供了丰富的性能和异常的指标统计,其中部分功能依赖于spy-head,包含的功能有
|
|
192
192
|
* 性能指标采集:包含体积、卡顿、速度等60+个性能指标采集方法
|
|
193
|
-
* 异常:包含大于
|
|
193
|
+
* 异常:包含大于150K的大图片采集、HTTPS环境下HTTP资源采集
|
|
194
194
|
* 辅助方式: mark系列辅助方法
|
|
195
195
|
|
|
196
196
|
### spy-head使用
|
|
197
197
|
|
|
198
|
-
spy-head JS
|
|
198
|
+
spy-head JS可以视情况通过script内联或嵌入其他JS里
|
|
199
199
|
|
|
200
200
|
> 如果要启用一项异常监控功能,需要设置其抽样sample不为0
|
|
201
201
|
|
|
202
202
|
```html
|
|
203
203
|
<script>
|
|
204
|
-
// spy-head js
|
|
204
|
+
// spy-head js可以视情况通过script内联或外链,外链地址可见文档开头的CDN
|
|
205
205
|
const spyHead = require('spy-client/dist/spy-head');
|
|
206
206
|
spyHead.init({
|
|
207
207
|
pid: '1_1', // spy申请的pid
|
|
@@ -267,7 +267,7 @@ spyHead.init({
|
|
|
267
267
|
### 主体SDK spy-client
|
|
268
268
|
|
|
269
269
|
```javascript
|
|
270
|
-
// enhanced spy-client
|
|
270
|
+
// enhanced spy-client
|
|
271
271
|
const SpyClient = require('spy-client');
|
|
272
272
|
const spy = new SpyClient({
|
|
273
273
|
pid: '1_1000', // 必须
|
|
@@ -407,10 +407,13 @@ export interface TTIMetric {
|
|
|
407
407
|
|
|
408
408
|
```javascript
|
|
409
409
|
// 数据类型:性能,触发时间:500MsAfterOnLoad
|
|
410
|
-
spy.listenResource(function (metric) {
|
|
410
|
+
spy.listenResource(function (metric, hostMetric) {
|
|
411
411
|
spy.sendPerf({
|
|
412
412
|
info: metric
|
|
413
413
|
});
|
|
414
|
+
|
|
415
|
+
// 分域名进行统计的
|
|
416
|
+
console.log('hostMetric', hostMetric);
|
|
414
417
|
});
|
|
415
418
|
```
|
|
416
419
|
|
|
@@ -452,8 +455,68 @@ export interface ResourceMetric {
|
|
|
452
455
|
cssCacheRate: number;
|
|
453
456
|
imgCacheRate: number;
|
|
454
457
|
};
|
|
458
|
+
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
hostMetric定义
|
|
462
|
+
```typescript
|
|
463
|
+
export interface ResourceHostMetric {
|
|
464
|
+
[host: string]: {
|
|
465
|
+
hostNum: number;
|
|
466
|
+
hostSize: number;
|
|
467
|
+
hostTransferSize: number;
|
|
468
|
+
hostDuration: number;
|
|
469
|
+
hostCacheRate: number;
|
|
470
|
+
};
|
|
471
|
+
};
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
#### 加载慢的资源
|
|
475
|
+
|
|
476
|
+
```javascript
|
|
477
|
+
// 数据类型:异常,触发时间:500MsAfterOnLoad
|
|
478
|
+
spy.listenSlowResource(function (info) {
|
|
479
|
+
spy.sendExcept({
|
|
480
|
+
info: info
|
|
481
|
+
});
|
|
482
|
+
}, {threshold: 1000});
|
|
455
483
|
```
|
|
456
484
|
|
|
485
|
+
info定义
|
|
486
|
+
```typescript
|
|
487
|
+
export interface ResourceErrorInfo {
|
|
488
|
+
// 发生异常的资源链接
|
|
489
|
+
msg: string;
|
|
490
|
+
// 发生异常的资源元素的xpath信息,一直到body
|
|
491
|
+
xpath: string;
|
|
492
|
+
// 资源host
|
|
493
|
+
host: string;
|
|
494
|
+
// 资源类型
|
|
495
|
+
type: string;
|
|
496
|
+
// 资源耗时
|
|
497
|
+
dur?: number;
|
|
498
|
+
}
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
第二个参数,option定义
|
|
502
|
+
```typescript
|
|
503
|
+
export interface SlowOption {
|
|
504
|
+
/**
|
|
505
|
+
* 加载时长大于该阈值,就认为是慢资源,默认1000,单位是ms
|
|
506
|
+
*/
|
|
507
|
+
threshold?: number;
|
|
508
|
+
/**
|
|
509
|
+
* 忽略指定path的资源
|
|
510
|
+
*/
|
|
511
|
+
ignorePaths?: string[];
|
|
512
|
+
/**
|
|
513
|
+
* 触发时机,在load事件触发后,还是在用户离开页面后,收集出现的加载慢的资源。,默认是load
|
|
514
|
+
*/
|
|
515
|
+
trigger?: 'load' | 'leave';
|
|
516
|
+
}
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
|
|
457
520
|
#### 大于150KB的大图检测
|
|
458
521
|
大于150KB(默认,第二个参数可以修改)的来自img标签的大图检测。
|
|
459
522
|
```javascript
|
|
@@ -473,6 +536,31 @@ export interface ResourceErrorInfo {
|
|
|
473
536
|
msg: string;
|
|
474
537
|
// 发生异常的资源元素的xpath信息,一直到body
|
|
475
538
|
xpath: string;
|
|
539
|
+
// 资源host
|
|
540
|
+
host: string;
|
|
541
|
+
// 资源类型
|
|
542
|
+
type: string;
|
|
543
|
+
// 资源耗时
|
|
544
|
+
dur?: number;
|
|
545
|
+
}
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
第二个参数,option定义
|
|
550
|
+
```typescript
|
|
551
|
+
export interface BigImgOption {
|
|
552
|
+
/**
|
|
553
|
+
* 体积大于该阈值,就认为是大图,默认150,单位是kb
|
|
554
|
+
*/
|
|
555
|
+
maxSize?: number;
|
|
556
|
+
/**
|
|
557
|
+
* 忽略指定path的资源
|
|
558
|
+
*/
|
|
559
|
+
ignorePaths?: string[];
|
|
560
|
+
/**
|
|
561
|
+
* 触发时机,在load事件触发后,还是在用户离开页面后,收集出现的加载慢的资源。,默认是load
|
|
562
|
+
*/
|
|
563
|
+
trigger?: 'load' | 'leave';
|
|
476
564
|
}
|
|
477
565
|
```
|
|
478
566
|
|
|
@@ -495,6 +583,27 @@ export interface ResourceErrorInfo {
|
|
|
495
583
|
msg: string;
|
|
496
584
|
// 发生异常的资源元素的xpath信息,一直到body
|
|
497
585
|
xpath: string;
|
|
586
|
+
// 资源host
|
|
587
|
+
host: string;
|
|
588
|
+
// 资源类型
|
|
589
|
+
type: string;
|
|
590
|
+
// 资源耗时
|
|
591
|
+
dur?: number;
|
|
592
|
+
}
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
第二个参数,option定义
|
|
597
|
+
```typescript
|
|
598
|
+
export interface HttpResOption {
|
|
599
|
+
/**
|
|
600
|
+
* 忽略指定path的资源
|
|
601
|
+
*/
|
|
602
|
+
ignorePaths?: string[];
|
|
603
|
+
/**
|
|
604
|
+
* 触发时机,在load事件触发后,还是在用户离开页面后,收集出现的加载慢的资源。,默认是load
|
|
605
|
+
*/
|
|
606
|
+
trigger?: 'load' | 'leave';
|
|
498
607
|
}
|
|
499
608
|
```
|
|
500
609
|
|
package/dist/head/base.d.ts
CHANGED
package/dist/lib/interface.d.ts
CHANGED
|
@@ -57,14 +57,30 @@ export interface ResourceMetric {
|
|
|
57
57
|
cssTransferSize: number;
|
|
58
58
|
imgTransferSize: number;
|
|
59
59
|
fontTransferSize: number;
|
|
60
|
+
jsDuration: number;
|
|
61
|
+
cssDuration: number;
|
|
62
|
+
imgDuration: number;
|
|
63
|
+
fontDuration: number;
|
|
60
64
|
jsCacheRate: number;
|
|
61
65
|
cssCacheRate: number;
|
|
62
66
|
imgCacheRate: number;
|
|
63
67
|
}
|
|
64
|
-
export
|
|
68
|
+
export interface ResourceHostMetric {
|
|
69
|
+
[host: string]: {
|
|
70
|
+
hostNum: number;
|
|
71
|
+
hostSize: number;
|
|
72
|
+
hostTransferSize: number;
|
|
73
|
+
hostDuration: number;
|
|
74
|
+
hostCacheRate: number;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export declare type ResourceCB = (metric: ResourceMetric, hostMetric: ResourceHostMetric) => void;
|
|
65
78
|
export interface ResourceErrorInfo {
|
|
66
79
|
msg: string;
|
|
67
80
|
xpath: string;
|
|
81
|
+
host: string;
|
|
82
|
+
type: string;
|
|
83
|
+
dur?: number;
|
|
68
84
|
}
|
|
69
85
|
export declare type ResourceErrorCB = (info: ResourceErrorInfo) => void;
|
|
70
86
|
export interface TimingMetric {
|
|
@@ -145,3 +161,45 @@ export interface PageLongtaskMetric {
|
|
|
145
161
|
pageIframeLongtaskNum: number;
|
|
146
162
|
}
|
|
147
163
|
export declare type PageLongtaskCB = (metric: PageLongtaskMetric) => void;
|
|
164
|
+
export interface ResOption {
|
|
165
|
+
ignorePaths?: string[];
|
|
166
|
+
trigger?: 'load' | 'leave';
|
|
167
|
+
}
|
|
168
|
+
export interface BigImgOption {
|
|
169
|
+
/**
|
|
170
|
+
* 体积大于该阈值,就认为是大图,默认150,单位是kb
|
|
171
|
+
*/
|
|
172
|
+
maxSize?: number;
|
|
173
|
+
/**
|
|
174
|
+
* 忽略指定path的资源
|
|
175
|
+
*/
|
|
176
|
+
ignorePaths?: string[];
|
|
177
|
+
/**
|
|
178
|
+
* 触发时机,在load事件触发后,还是在用户离开页面后,收集出现的加载慢的资源。,默认是load
|
|
179
|
+
*/
|
|
180
|
+
trigger?: 'load' | 'leave';
|
|
181
|
+
}
|
|
182
|
+
export interface HttpResOption {
|
|
183
|
+
/**
|
|
184
|
+
* 忽略指定path的资源
|
|
185
|
+
*/
|
|
186
|
+
ignorePaths?: string[];
|
|
187
|
+
/**
|
|
188
|
+
* 触发时机,在load事件触发后,还是在用户离开页面后,收集出现的加载慢的资源。,默认是load
|
|
189
|
+
*/
|
|
190
|
+
trigger?: 'load' | 'leave';
|
|
191
|
+
}
|
|
192
|
+
export interface SlowOption {
|
|
193
|
+
/**
|
|
194
|
+
* 加载时长大于该阈值,就认为是慢资源,默认1000,单位是ms
|
|
195
|
+
*/
|
|
196
|
+
threshold?: number;
|
|
197
|
+
/**
|
|
198
|
+
* 忽略指定path的资源
|
|
199
|
+
*/
|
|
200
|
+
ignorePaths?: string[];
|
|
201
|
+
/**
|
|
202
|
+
* 触发时机,在load事件触发后,还是在用户离开页面后,收集出现的加载慢的资源。,默认是load
|
|
203
|
+
*/
|
|
204
|
+
trigger?: 'load' | 'leave';
|
|
205
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file utils
|
|
3
|
+
* @author kaivean
|
|
4
|
+
*/
|
|
5
|
+
export declare function assign(...args: any[]): any;
|
|
6
|
+
export interface URLINFO {
|
|
7
|
+
protocol: string;
|
|
8
|
+
host: string;
|
|
9
|
+
pathname: string;
|
|
10
|
+
ext: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function getUrlInfo(url: string): URLINFO;
|
|
13
|
+
export declare function getResTiming(t: PerformanceTiming | PerformanceResourceTiming): {
|
|
14
|
+
wait: number;
|
|
15
|
+
dns: number;
|
|
16
|
+
connect: number;
|
|
17
|
+
req: number;
|
|
18
|
+
res: number;
|
|
19
|
+
};
|
|
20
|
+
export declare function getxpath(el: Element | null): {
|
|
21
|
+
xpath: string;
|
|
22
|
+
};
|
|
@@ -24,7 +24,7 @@ export default class Longtask implements Module {
|
|
|
24
24
|
private pageCB;
|
|
25
25
|
private onceLeave;
|
|
26
26
|
constructor();
|
|
27
|
-
check():
|
|
27
|
+
check(): any;
|
|
28
28
|
listenFSPLongTask(cb: FSPLongtaskCB): void;
|
|
29
29
|
listenLCPLongTask(cb: LCPLongtaskCB): void;
|
|
30
30
|
listenLoadLongTask(cb: LoadLongtaskCB): void;
|
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
import { Module, ResourceCB, ResourceErrorCB } from '../lib/interface';
|
|
1
|
+
import { Module, ResourceCB, ResourceErrorCB, ResOption, BigImgOption, HttpResOption, SlowOption } from '../lib/interface';
|
|
2
2
|
export default class Resource implements Module {
|
|
3
3
|
private cb;
|
|
4
4
|
private bigImgCB;
|
|
5
5
|
private httpResCB;
|
|
6
|
-
private
|
|
6
|
+
private slowResCB;
|
|
7
|
+
private resOption;
|
|
8
|
+
private bigImgOption;
|
|
9
|
+
private httpResOption;
|
|
10
|
+
private slowOption;
|
|
11
|
+
private trigger;
|
|
7
12
|
private readonly jsList;
|
|
8
13
|
private readonly cssList;
|
|
9
14
|
private readonly imgList;
|
|
10
15
|
private readonly fontList;
|
|
11
|
-
private readonly
|
|
16
|
+
private readonly hostList;
|
|
12
17
|
private readonly bigImgList;
|
|
13
18
|
private readonly httpResList;
|
|
19
|
+
private readonly slowList;
|
|
14
20
|
constructor();
|
|
15
|
-
check(): (type: string) =>
|
|
16
|
-
listenResource(cb: ResourceCB): void;
|
|
17
|
-
listenBigImg(cb: ResourceErrorCB,
|
|
18
|
-
listenHttpResource(cb: ResourceErrorCB): void;
|
|
21
|
+
check(): (type: string) => PerformanceEntryList;
|
|
22
|
+
listenResource(cb: ResourceCB, option?: ResOption): void;
|
|
23
|
+
listenBigImg(cb: ResourceErrorCB, option?: BigImgOption): void;
|
|
24
|
+
listenHttpResource(cb: ResourceErrorCB, option?: HttpResOption): void;
|
|
25
|
+
listenSlowResource(cb: ResourceErrorCB, option?: SlowOption): void;
|
|
26
|
+
report(): void;
|
|
19
27
|
load(): void;
|
|
20
|
-
|
|
28
|
+
leave(): void;
|
|
29
|
+
private push;
|
|
30
|
+
private pushWithHost;
|
|
21
31
|
private collectHttpResInHttps;
|
|
22
32
|
private addScript;
|
|
23
|
-
private
|
|
33
|
+
private addResFromCss;
|
|
24
34
|
private addLink;
|
|
25
35
|
private addImg;
|
|
26
36
|
private handleTimings;
|
package/dist/module/tti.d.ts
CHANGED
|
@@ -1,1169 +1,235 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return !!exec();
|
|
24
|
-
} catch (error) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// Thank's IE8 for his funny defineProperty
|
|
30
|
-
var descriptors = !fails(function () {
|
|
31
|
-
return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
var nativePropertyIsEnumerable = {}.propertyIsEnumerable;
|
|
35
|
-
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
36
|
-
|
|
37
|
-
// Nashorn ~ JDK8 bug
|
|
38
|
-
var NASHORN_BUG = getOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 1: 2 }, 1);
|
|
39
|
-
|
|
40
|
-
// `Object.prototype.propertyIsEnumerable` method implementation
|
|
41
|
-
// https://tc39.github.io/ecma262/#sec-object.prototype.propertyisenumerable
|
|
42
|
-
var f = NASHORN_BUG ? function propertyIsEnumerable(V) {
|
|
43
|
-
var descriptor = getOwnPropertyDescriptor(this, V);
|
|
44
|
-
return !!descriptor && descriptor.enumerable;
|
|
45
|
-
} : nativePropertyIsEnumerable;
|
|
46
|
-
|
|
47
|
-
var objectPropertyIsEnumerable = {
|
|
48
|
-
f: f
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
var createPropertyDescriptor = function (bitmap, value) {
|
|
52
|
-
return {
|
|
53
|
-
enumerable: !(bitmap & 1),
|
|
54
|
-
configurable: !(bitmap & 2),
|
|
55
|
-
writable: !(bitmap & 4),
|
|
56
|
-
value: value
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
var toString = {}.toString;
|
|
61
|
-
|
|
62
|
-
var classofRaw = function (it) {
|
|
63
|
-
return toString.call(it).slice(8, -1);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
var split = ''.split;
|
|
67
|
-
|
|
68
|
-
// fallback for non-array-like ES3 and non-enumerable old V8 strings
|
|
69
|
-
var indexedObject = fails(function () {
|
|
70
|
-
// throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
|
|
71
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
72
|
-
return !Object('z').propertyIsEnumerable(0);
|
|
73
|
-
}) ? function (it) {
|
|
74
|
-
return classofRaw(it) == 'String' ? split.call(it, '') : Object(it);
|
|
75
|
-
} : Object;
|
|
76
|
-
|
|
77
|
-
// `RequireObjectCoercible` abstract operation
|
|
78
|
-
// https://tc39.github.io/ecma262/#sec-requireobjectcoercible
|
|
79
|
-
var requireObjectCoercible = function (it) {
|
|
80
|
-
if (it == undefined) throw TypeError("Can't call method on " + it);
|
|
81
|
-
return it;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// toObject with fallback for non-array-like ES3 strings
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
var toIndexedObject = function (it) {
|
|
89
|
-
return indexedObject(requireObjectCoercible(it));
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
var isObject = function (it) {
|
|
93
|
-
return typeof it === 'object' ? it !== null : typeof it === 'function';
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// `ToPrimitive` abstract operation
|
|
97
|
-
// https://tc39.github.io/ecma262/#sec-toprimitive
|
|
98
|
-
// instead of the ES6 spec version, we didn't implement @@toPrimitive case
|
|
99
|
-
// and the second argument - flag - preferred type is a string
|
|
100
|
-
var toPrimitive = function (input, PREFERRED_STRING) {
|
|
101
|
-
if (!isObject(input)) return input;
|
|
102
|
-
var fn, val;
|
|
103
|
-
if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
|
|
104
|
-
if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
|
|
105
|
-
if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
|
|
106
|
-
throw TypeError("Can't convert object to primitive value");
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
var hasOwnProperty = {}.hasOwnProperty;
|
|
110
|
-
|
|
111
|
-
var has = function (it, key) {
|
|
112
|
-
return hasOwnProperty.call(it, key);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
var document = global_1.document;
|
|
116
|
-
// typeof document.createElement is 'object' in old IE
|
|
117
|
-
var EXISTS = isObject(document) && isObject(document.createElement);
|
|
118
|
-
|
|
119
|
-
var documentCreateElement = function (it) {
|
|
120
|
-
return EXISTS ? document.createElement(it) : {};
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// Thank's IE8 for his funny defineProperty
|
|
124
|
-
var ie8DomDefine = !descriptors && !fails(function () {
|
|
125
|
-
return Object.defineProperty(documentCreateElement('div'), 'a', {
|
|
126
|
-
get: function () { return 7; }
|
|
127
|
-
}).a != 7;
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
131
|
-
|
|
132
|
-
// `Object.getOwnPropertyDescriptor` method
|
|
133
|
-
// https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor
|
|
134
|
-
var f$1 = descriptors ? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
|
|
135
|
-
O = toIndexedObject(O);
|
|
136
|
-
P = toPrimitive(P, true);
|
|
137
|
-
if (ie8DomDefine) try {
|
|
138
|
-
return nativeGetOwnPropertyDescriptor(O, P);
|
|
139
|
-
} catch (error) { /* empty */ }
|
|
140
|
-
if (has(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
var objectGetOwnPropertyDescriptor = {
|
|
144
|
-
f: f$1
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
var anObject = function (it) {
|
|
148
|
-
if (!isObject(it)) {
|
|
149
|
-
throw TypeError(String(it) + ' is not an object');
|
|
150
|
-
} return it;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
var nativeDefineProperty = Object.defineProperty;
|
|
154
|
-
|
|
155
|
-
// `Object.defineProperty` method
|
|
156
|
-
// https://tc39.github.io/ecma262/#sec-object.defineproperty
|
|
157
|
-
var f$2 = descriptors ? nativeDefineProperty : function defineProperty(O, P, Attributes) {
|
|
158
|
-
anObject(O);
|
|
159
|
-
P = toPrimitive(P, true);
|
|
160
|
-
anObject(Attributes);
|
|
161
|
-
if (ie8DomDefine) try {
|
|
162
|
-
return nativeDefineProperty(O, P, Attributes);
|
|
163
|
-
} catch (error) { /* empty */ }
|
|
164
|
-
if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
|
|
165
|
-
if ('value' in Attributes) O[P] = Attributes.value;
|
|
166
|
-
return O;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
var objectDefineProperty = {
|
|
170
|
-
f: f$2
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
var createNonEnumerableProperty = descriptors ? function (object, key, value) {
|
|
174
|
-
return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value));
|
|
175
|
-
} : function (object, key, value) {
|
|
176
|
-
object[key] = value;
|
|
177
|
-
return object;
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
var setGlobal = function (key, value) {
|
|
181
|
-
try {
|
|
182
|
-
createNonEnumerableProperty(global_1, key, value);
|
|
183
|
-
} catch (error) {
|
|
184
|
-
global_1[key] = value;
|
|
185
|
-
} return value;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
var SHARED = '__core-js_shared__';
|
|
189
|
-
var store = global_1[SHARED] || setGlobal(SHARED, {});
|
|
190
|
-
|
|
191
|
-
var sharedStore = store;
|
|
192
|
-
|
|
193
|
-
var functionToString = Function.toString;
|
|
194
|
-
|
|
195
|
-
// this helper broken in `3.4.1-3.4.4`, so we can't use `shared` helper
|
|
196
|
-
if (typeof sharedStore.inspectSource != 'function') {
|
|
197
|
-
sharedStore.inspectSource = function (it) {
|
|
198
|
-
return functionToString.call(it);
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
var inspectSource = sharedStore.inspectSource;
|
|
203
|
-
|
|
204
|
-
var WeakMap = global_1.WeakMap;
|
|
205
|
-
|
|
206
|
-
var nativeWeakMap = typeof WeakMap === 'function' && /native code/.test(inspectSource(WeakMap));
|
|
207
|
-
|
|
208
|
-
var shared = createCommonjsModule(function (module) {
|
|
209
|
-
(module.exports = function (key, value) {
|
|
210
|
-
return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {});
|
|
211
|
-
})('versions', []).push({
|
|
212
|
-
version: '3.6.4',
|
|
213
|
-
mode: 'global',
|
|
214
|
-
copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
var id = 0;
|
|
219
|
-
var postfix = Math.random();
|
|
220
|
-
|
|
221
|
-
var uid = function (key) {
|
|
222
|
-
return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
var keys = shared('keys');
|
|
226
|
-
|
|
227
|
-
var sharedKey = function (key) {
|
|
228
|
-
return keys[key] || (keys[key] = uid(key));
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
var hiddenKeys = {};
|
|
232
|
-
|
|
233
|
-
var WeakMap$1 = global_1.WeakMap;
|
|
234
|
-
var set, get, has$1;
|
|
235
|
-
|
|
236
|
-
var enforce = function (it) {
|
|
237
|
-
return has$1(it) ? get(it) : set(it, {});
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
var getterFor = function (TYPE) {
|
|
241
|
-
return function (it) {
|
|
242
|
-
var state;
|
|
243
|
-
if (!isObject(it) || (state = get(it)).type !== TYPE) {
|
|
244
|
-
throw TypeError('Incompatible receiver, ' + TYPE + ' required');
|
|
245
|
-
} return state;
|
|
246
|
-
};
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
if (nativeWeakMap) {
|
|
250
|
-
var store$1 = new WeakMap$1();
|
|
251
|
-
var wmget = store$1.get;
|
|
252
|
-
var wmhas = store$1.has;
|
|
253
|
-
var wmset = store$1.set;
|
|
254
|
-
set = function (it, metadata) {
|
|
255
|
-
wmset.call(store$1, it, metadata);
|
|
256
|
-
return metadata;
|
|
257
|
-
};
|
|
258
|
-
get = function (it) {
|
|
259
|
-
return wmget.call(store$1, it) || {};
|
|
260
|
-
};
|
|
261
|
-
has$1 = function (it) {
|
|
262
|
-
return wmhas.call(store$1, it);
|
|
263
|
-
};
|
|
264
|
-
} else {
|
|
265
|
-
var STATE = sharedKey('state');
|
|
266
|
-
hiddenKeys[STATE] = true;
|
|
267
|
-
set = function (it, metadata) {
|
|
268
|
-
createNonEnumerableProperty(it, STATE, metadata);
|
|
269
|
-
return metadata;
|
|
270
|
-
};
|
|
271
|
-
get = function (it) {
|
|
272
|
-
return has(it, STATE) ? it[STATE] : {};
|
|
273
|
-
};
|
|
274
|
-
has$1 = function (it) {
|
|
275
|
-
return has(it, STATE);
|
|
276
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @file utils
|
|
3
|
+
* @author kaivean
|
|
4
|
+
*/
|
|
5
|
+
function assign() {
|
|
6
|
+
var args = [];
|
|
7
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
8
|
+
args[_i] = arguments[_i];
|
|
9
|
+
}
|
|
10
|
+
var __assign = Object.assign || function __assign(t) {
|
|
11
|
+
for (var s = void 0, i = 1, n = arguments.length; i < n; i++) {
|
|
12
|
+
// eslint-disable-next-line prefer-rest-params
|
|
13
|
+
s = arguments[i];
|
|
14
|
+
for (var p in s) {
|
|
15
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) {
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
return __assign.apply(this, args);
|
|
277
23
|
}
|
|
278
24
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
//
|
|
340
|
-
//
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
var
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
var
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
var GLOBAL = options.global;
|
|
491
|
-
var STATIC = options.stat;
|
|
492
|
-
var FORCED, target, key, targetProperty, sourceProperty, descriptor;
|
|
493
|
-
if (GLOBAL) {
|
|
494
|
-
target = global_1;
|
|
495
|
-
} else if (STATIC) {
|
|
496
|
-
target = global_1[TARGET] || setGlobal(TARGET, {});
|
|
497
|
-
} else {
|
|
498
|
-
target = (global_1[TARGET] || {}).prototype;
|
|
499
|
-
}
|
|
500
|
-
if (target) for (key in source) {
|
|
501
|
-
sourceProperty = source[key];
|
|
502
|
-
if (options.noTargetGet) {
|
|
503
|
-
descriptor = getOwnPropertyDescriptor$1(target, key);
|
|
504
|
-
targetProperty = descriptor && descriptor.value;
|
|
505
|
-
} else targetProperty = target[key];
|
|
506
|
-
FORCED = isForced_1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
|
|
507
|
-
// contained in target
|
|
508
|
-
if (!FORCED && targetProperty !== undefined) {
|
|
509
|
-
if (typeof sourceProperty === typeof targetProperty) continue;
|
|
510
|
-
copyConstructorProperties(sourceProperty, targetProperty);
|
|
511
|
-
}
|
|
512
|
-
// add a flag to not completely full polyfills
|
|
513
|
-
if (options.sham || (targetProperty && targetProperty.sham)) {
|
|
514
|
-
createNonEnumerableProperty(sourceProperty, 'sham', true);
|
|
515
|
-
}
|
|
516
|
-
// extend global
|
|
517
|
-
redefine(target, key, sourceProperty, options);
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
|
|
521
|
-
// `IsArray` abstract operation
|
|
522
|
-
// https://tc39.github.io/ecma262/#sec-isarray
|
|
523
|
-
var isArray = Array.isArray || function isArray(arg) {
|
|
524
|
-
return classofRaw(arg) == 'Array';
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
// `ToObject` abstract operation
|
|
528
|
-
// https://tc39.github.io/ecma262/#sec-toobject
|
|
529
|
-
var toObject = function (argument) {
|
|
530
|
-
return Object(requireObjectCoercible(argument));
|
|
531
|
-
};
|
|
532
|
-
|
|
533
|
-
var createProperty = function (object, key, value) {
|
|
534
|
-
var propertyKey = toPrimitive(key);
|
|
535
|
-
if (propertyKey in object) objectDefineProperty.f(object, propertyKey, createPropertyDescriptor(0, value));
|
|
536
|
-
else object[propertyKey] = value;
|
|
537
|
-
};
|
|
538
|
-
|
|
539
|
-
var nativeSymbol = !!Object.getOwnPropertySymbols && !fails(function () {
|
|
540
|
-
// Chrome 38 Symbol has incorrect toString conversion
|
|
541
|
-
// eslint-disable-next-line no-undef
|
|
542
|
-
return !String(Symbol());
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
var useSymbolAsUid = nativeSymbol
|
|
546
|
-
// eslint-disable-next-line no-undef
|
|
547
|
-
&& !Symbol.sham
|
|
548
|
-
// eslint-disable-next-line no-undef
|
|
549
|
-
&& typeof Symbol.iterator == 'symbol';
|
|
550
|
-
|
|
551
|
-
var WellKnownSymbolsStore = shared('wks');
|
|
552
|
-
var Symbol$1 = global_1.Symbol;
|
|
553
|
-
var createWellKnownSymbol = useSymbolAsUid ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid;
|
|
554
|
-
|
|
555
|
-
var wellKnownSymbol = function (name) {
|
|
556
|
-
if (!has(WellKnownSymbolsStore, name)) {
|
|
557
|
-
if (nativeSymbol && has(Symbol$1, name)) WellKnownSymbolsStore[name] = Symbol$1[name];
|
|
558
|
-
else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
|
|
559
|
-
} return WellKnownSymbolsStore[name];
|
|
560
|
-
};
|
|
561
|
-
|
|
562
|
-
var SPECIES = wellKnownSymbol('species');
|
|
563
|
-
|
|
564
|
-
// `ArraySpeciesCreate` abstract operation
|
|
565
|
-
// https://tc39.github.io/ecma262/#sec-arrayspeciescreate
|
|
566
|
-
var arraySpeciesCreate = function (originalArray, length) {
|
|
567
|
-
var C;
|
|
568
|
-
if (isArray(originalArray)) {
|
|
569
|
-
C = originalArray.constructor;
|
|
570
|
-
// cross-realm fallback
|
|
571
|
-
if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined;
|
|
572
|
-
else if (isObject(C)) {
|
|
573
|
-
C = C[SPECIES];
|
|
574
|
-
if (C === null) C = undefined;
|
|
575
|
-
}
|
|
576
|
-
} return new (C === undefined ? Array : C)(length === 0 ? 0 : length);
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
var engineUserAgent = getBuiltIn('navigator', 'userAgent') || '';
|
|
580
|
-
|
|
581
|
-
var process = global_1.process;
|
|
582
|
-
var versions = process && process.versions;
|
|
583
|
-
var v8 = versions && versions.v8;
|
|
584
|
-
var match, version;
|
|
585
|
-
|
|
586
|
-
if (v8) {
|
|
587
|
-
match = v8.split('.');
|
|
588
|
-
version = match[0] + match[1];
|
|
589
|
-
} else if (engineUserAgent) {
|
|
590
|
-
match = engineUserAgent.match(/Edge\/(\d+)/);
|
|
591
|
-
if (!match || match[1] >= 74) {
|
|
592
|
-
match = engineUserAgent.match(/Chrome\/(\d+)/);
|
|
593
|
-
if (match) version = match[1];
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
var engineV8Version = version && +version;
|
|
598
|
-
|
|
599
|
-
var SPECIES$1 = wellKnownSymbol('species');
|
|
600
|
-
|
|
601
|
-
var arrayMethodHasSpeciesSupport = function (METHOD_NAME) {
|
|
602
|
-
// We can't use this feature detection in V8 since it causes
|
|
603
|
-
// deoptimization and serious performance degradation
|
|
604
|
-
// https://github.com/zloirock/core-js/issues/677
|
|
605
|
-
return engineV8Version >= 51 || !fails(function () {
|
|
606
|
-
var array = [];
|
|
607
|
-
var constructor = array.constructor = {};
|
|
608
|
-
constructor[SPECIES$1] = function () {
|
|
609
|
-
return { foo: 1 };
|
|
610
|
-
};
|
|
611
|
-
return array[METHOD_NAME](Boolean).foo !== 1;
|
|
612
|
-
});
|
|
613
|
-
};
|
|
614
|
-
|
|
615
|
-
var IS_CONCAT_SPREADABLE = wellKnownSymbol('isConcatSpreadable');
|
|
616
|
-
var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF;
|
|
617
|
-
var MAXIMUM_ALLOWED_INDEX_EXCEEDED = 'Maximum allowed index exceeded';
|
|
618
|
-
|
|
619
|
-
// We can't use this feature detection in V8 since it causes
|
|
620
|
-
// deoptimization and serious performance degradation
|
|
621
|
-
// https://github.com/zloirock/core-js/issues/679
|
|
622
|
-
var IS_CONCAT_SPREADABLE_SUPPORT = engineV8Version >= 51 || !fails(function () {
|
|
623
|
-
var array = [];
|
|
624
|
-
array[IS_CONCAT_SPREADABLE] = false;
|
|
625
|
-
return array.concat()[0] !== array;
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
var SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('concat');
|
|
629
|
-
|
|
630
|
-
var isConcatSpreadable = function (O) {
|
|
631
|
-
if (!isObject(O)) return false;
|
|
632
|
-
var spreadable = O[IS_CONCAT_SPREADABLE];
|
|
633
|
-
return spreadable !== undefined ? !!spreadable : isArray(O);
|
|
634
|
-
};
|
|
635
|
-
|
|
636
|
-
var FORCED = !IS_CONCAT_SPREADABLE_SUPPORT || !SPECIES_SUPPORT;
|
|
637
|
-
|
|
638
|
-
// `Array.prototype.concat` method
|
|
639
|
-
// https://tc39.github.io/ecma262/#sec-array.prototype.concat
|
|
640
|
-
// with adding support of @@isConcatSpreadable and @@species
|
|
641
|
-
_export({ target: 'Array', proto: true, forced: FORCED }, {
|
|
642
|
-
concat: function concat(arg) { // eslint-disable-line no-unused-vars
|
|
643
|
-
var O = toObject(this);
|
|
644
|
-
var A = arraySpeciesCreate(O, 0);
|
|
645
|
-
var n = 0;
|
|
646
|
-
var i, k, length, len, E;
|
|
647
|
-
for (i = -1, length = arguments.length; i < length; i++) {
|
|
648
|
-
E = i === -1 ? O : arguments[i];
|
|
649
|
-
if (isConcatSpreadable(E)) {
|
|
650
|
-
len = toLength(E.length);
|
|
651
|
-
if (n + len > MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED);
|
|
652
|
-
for (k = 0; k < len; k++, n++) if (k in E) createProperty(A, n, E[k]);
|
|
653
|
-
} else {
|
|
654
|
-
if (n >= MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED);
|
|
655
|
-
createProperty(A, n++, E);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
A.length = n;
|
|
659
|
-
return A;
|
|
660
|
-
}
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
var arrayMethodIsStrict = function (METHOD_NAME, argument) {
|
|
664
|
-
var method = [][METHOD_NAME];
|
|
665
|
-
return !!method && fails(function () {
|
|
666
|
-
// eslint-disable-next-line no-useless-call,no-throw-literal
|
|
667
|
-
method.call(null, argument || function () { throw 1; }, 1);
|
|
668
|
-
});
|
|
669
|
-
};
|
|
670
|
-
|
|
671
|
-
var defineProperty = Object.defineProperty;
|
|
672
|
-
var cache = {};
|
|
673
|
-
|
|
674
|
-
var thrower = function (it) { throw it; };
|
|
675
|
-
|
|
676
|
-
var arrayMethodUsesToLength = function (METHOD_NAME, options) {
|
|
677
|
-
if (has(cache, METHOD_NAME)) return cache[METHOD_NAME];
|
|
678
|
-
if (!options) options = {};
|
|
679
|
-
var method = [][METHOD_NAME];
|
|
680
|
-
var ACCESSORS = has(options, 'ACCESSORS') ? options.ACCESSORS : false;
|
|
681
|
-
var argument0 = has(options, 0) ? options[0] : thrower;
|
|
682
|
-
var argument1 = has(options, 1) ? options[1] : undefined;
|
|
683
|
-
|
|
684
|
-
return cache[METHOD_NAME] = !!method && !fails(function () {
|
|
685
|
-
if (ACCESSORS && !descriptors) return true;
|
|
686
|
-
var O = { length: -1 };
|
|
687
|
-
|
|
688
|
-
if (ACCESSORS) defineProperty(O, 1, { enumerable: true, get: thrower });
|
|
689
|
-
else O[1] = 1;
|
|
690
|
-
|
|
691
|
-
method.call(O, argument0, argument1);
|
|
692
|
-
});
|
|
693
|
-
};
|
|
694
|
-
|
|
695
|
-
var $indexOf = arrayIncludes.indexOf;
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
var nativeIndexOf = [].indexOf;
|
|
700
|
-
|
|
701
|
-
var NEGATIVE_ZERO = !!nativeIndexOf && 1 / [1].indexOf(1, -0) < 0;
|
|
702
|
-
var STRICT_METHOD = arrayMethodIsStrict('indexOf');
|
|
703
|
-
var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', { ACCESSORS: true, 1: 0 });
|
|
704
|
-
|
|
705
|
-
// `Array.prototype.indexOf` method
|
|
706
|
-
// https://tc39.github.io/ecma262/#sec-array.prototype.indexof
|
|
707
|
-
_export({ target: 'Array', proto: true, forced: NEGATIVE_ZERO || !STRICT_METHOD || !USES_TO_LENGTH }, {
|
|
708
|
-
indexOf: function indexOf(searchElement /* , fromIndex = 0 */) {
|
|
709
|
-
return NEGATIVE_ZERO
|
|
710
|
-
// convert -0 to +0
|
|
711
|
-
? nativeIndexOf.apply(this, arguments) || 0
|
|
712
|
-
: $indexOf(this, searchElement, arguments.length > 1 ? arguments[1] : undefined);
|
|
713
|
-
}
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
var nativeJoin = [].join;
|
|
717
|
-
|
|
718
|
-
var ES3_STRINGS = indexedObject != Object;
|
|
719
|
-
var STRICT_METHOD$1 = arrayMethodIsStrict('join', ',');
|
|
720
|
-
|
|
721
|
-
// `Array.prototype.join` method
|
|
722
|
-
// https://tc39.github.io/ecma262/#sec-array.prototype.join
|
|
723
|
-
_export({ target: 'Array', proto: true, forced: ES3_STRINGS || !STRICT_METHOD$1 }, {
|
|
724
|
-
join: function join(separator) {
|
|
725
|
-
return nativeJoin.call(toIndexedObject(this), separator === undefined ? ',' : separator);
|
|
726
|
-
}
|
|
727
|
-
});
|
|
728
|
-
|
|
729
|
-
var aFunction$1 = function (it) {
|
|
730
|
-
if (typeof it != 'function') {
|
|
731
|
-
throw TypeError(String(it) + ' is not a function');
|
|
732
|
-
} return it;
|
|
733
|
-
};
|
|
734
|
-
|
|
735
|
-
// optional / simple context binding
|
|
736
|
-
var functionBindContext = function (fn, that, length) {
|
|
737
|
-
aFunction$1(fn);
|
|
738
|
-
if (that === undefined) return fn;
|
|
739
|
-
switch (length) {
|
|
740
|
-
case 0: return function () {
|
|
741
|
-
return fn.call(that);
|
|
742
|
-
};
|
|
743
|
-
case 1: return function (a) {
|
|
744
|
-
return fn.call(that, a);
|
|
745
|
-
};
|
|
746
|
-
case 2: return function (a, b) {
|
|
747
|
-
return fn.call(that, a, b);
|
|
748
|
-
};
|
|
749
|
-
case 3: return function (a, b, c) {
|
|
750
|
-
return fn.call(that, a, b, c);
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
return function (/* ...args */) {
|
|
754
|
-
return fn.apply(that, arguments);
|
|
755
|
-
};
|
|
756
|
-
};
|
|
757
|
-
|
|
758
|
-
var push = [].push;
|
|
759
|
-
|
|
760
|
-
// `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` methods implementation
|
|
761
|
-
var createMethod$1 = function (TYPE) {
|
|
762
|
-
var IS_MAP = TYPE == 1;
|
|
763
|
-
var IS_FILTER = TYPE == 2;
|
|
764
|
-
var IS_SOME = TYPE == 3;
|
|
765
|
-
var IS_EVERY = TYPE == 4;
|
|
766
|
-
var IS_FIND_INDEX = TYPE == 6;
|
|
767
|
-
var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
|
|
768
|
-
return function ($this, callbackfn, that, specificCreate) {
|
|
769
|
-
var O = toObject($this);
|
|
770
|
-
var self = indexedObject(O);
|
|
771
|
-
var boundFunction = functionBindContext(callbackfn, that, 3);
|
|
772
|
-
var length = toLength(self.length);
|
|
773
|
-
var index = 0;
|
|
774
|
-
var create = specificCreate || arraySpeciesCreate;
|
|
775
|
-
var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
|
|
776
|
-
var value, result;
|
|
777
|
-
for (;length > index; index++) if (NO_HOLES || index in self) {
|
|
778
|
-
value = self[index];
|
|
779
|
-
result = boundFunction(value, index, O);
|
|
780
|
-
if (TYPE) {
|
|
781
|
-
if (IS_MAP) target[index] = result; // map
|
|
782
|
-
else if (result) switch (TYPE) {
|
|
783
|
-
case 3: return true; // some
|
|
784
|
-
case 5: return value; // find
|
|
785
|
-
case 6: return index; // findIndex
|
|
786
|
-
case 2: push.call(target, value); // filter
|
|
787
|
-
} else if (IS_EVERY) return false; // every
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
|
|
791
|
-
};
|
|
792
|
-
};
|
|
793
|
-
|
|
794
|
-
var arrayIteration = {
|
|
795
|
-
// `Array.prototype.forEach` method
|
|
796
|
-
// https://tc39.github.io/ecma262/#sec-array.prototype.foreach
|
|
797
|
-
forEach: createMethod$1(0),
|
|
798
|
-
// `Array.prototype.map` method
|
|
799
|
-
// https://tc39.github.io/ecma262/#sec-array.prototype.map
|
|
800
|
-
map: createMethod$1(1),
|
|
801
|
-
// `Array.prototype.filter` method
|
|
802
|
-
// https://tc39.github.io/ecma262/#sec-array.prototype.filter
|
|
803
|
-
filter: createMethod$1(2),
|
|
804
|
-
// `Array.prototype.some` method
|
|
805
|
-
// https://tc39.github.io/ecma262/#sec-array.prototype.some
|
|
806
|
-
some: createMethod$1(3),
|
|
807
|
-
// `Array.prototype.every` method
|
|
808
|
-
// https://tc39.github.io/ecma262/#sec-array.prototype.every
|
|
809
|
-
every: createMethod$1(4),
|
|
810
|
-
// `Array.prototype.find` method
|
|
811
|
-
// https://tc39.github.io/ecma262/#sec-array.prototype.find
|
|
812
|
-
find: createMethod$1(5),
|
|
813
|
-
// `Array.prototype.findIndex` method
|
|
814
|
-
// https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
|
|
815
|
-
findIndex: createMethod$1(6)
|
|
816
|
-
};
|
|
817
|
-
|
|
818
|
-
var $map = arrayIteration.map;
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('map');
|
|
823
|
-
// FF49- issue
|
|
824
|
-
var USES_TO_LENGTH$1 = arrayMethodUsesToLength('map');
|
|
825
|
-
|
|
826
|
-
// `Array.prototype.map` method
|
|
827
|
-
// https://tc39.github.io/ecma262/#sec-array.prototype.map
|
|
828
|
-
// with adding support of @@species
|
|
829
|
-
_export({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH$1 }, {
|
|
830
|
-
map: function map(callbackfn /* , thisArg */) {
|
|
831
|
-
return $map(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
|
|
832
|
-
}
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
// `Date.now` method
|
|
836
|
-
// https://tc39.github.io/ecma262/#sec-date.now
|
|
837
|
-
_export({ target: 'Date', stat: true }, {
|
|
838
|
-
now: function now() {
|
|
839
|
-
return new Date().getTime();
|
|
840
|
-
}
|
|
841
|
-
});
|
|
842
|
-
|
|
843
|
-
var DatePrototype = Date.prototype;
|
|
844
|
-
var INVALID_DATE = 'Invalid Date';
|
|
845
|
-
var TO_STRING = 'toString';
|
|
846
|
-
var nativeDateToString = DatePrototype[TO_STRING];
|
|
847
|
-
var getTime = DatePrototype.getTime;
|
|
848
|
-
|
|
849
|
-
// `Date.prototype.toString` method
|
|
850
|
-
// https://tc39.github.io/ecma262/#sec-date.prototype.tostring
|
|
851
|
-
if (new Date(NaN) + '' != INVALID_DATE) {
|
|
852
|
-
redefine(DatePrototype, TO_STRING, function toString() {
|
|
853
|
-
var value = getTime.call(this);
|
|
854
|
-
// eslint-disable-next-line no-self-compare
|
|
855
|
-
return value === value ? nativeDateToString.call(this) : INVALID_DATE;
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
// `Object.keys` method
|
|
860
|
-
// https://tc39.github.io/ecma262/#sec-object.keys
|
|
861
|
-
var objectKeys = Object.keys || function keys(O) {
|
|
862
|
-
return objectKeysInternal(O, enumBugKeys);
|
|
863
|
-
};
|
|
864
|
-
|
|
865
|
-
var nativeAssign = Object.assign;
|
|
866
|
-
var defineProperty$1 = Object.defineProperty;
|
|
867
|
-
|
|
868
|
-
// `Object.assign` method
|
|
869
|
-
// https://tc39.github.io/ecma262/#sec-object.assign
|
|
870
|
-
var objectAssign = !nativeAssign || fails(function () {
|
|
871
|
-
// should have correct order of operations (Edge bug)
|
|
872
|
-
if (descriptors && nativeAssign({ b: 1 }, nativeAssign(defineProperty$1({}, 'a', {
|
|
873
|
-
enumerable: true,
|
|
874
|
-
get: function () {
|
|
875
|
-
defineProperty$1(this, 'b', {
|
|
876
|
-
value: 3,
|
|
877
|
-
enumerable: false
|
|
878
|
-
});
|
|
879
|
-
}
|
|
880
|
-
}), { b: 2 })).b !== 1) return true;
|
|
881
|
-
// should work with symbols and should have deterministic property order (V8 bug)
|
|
882
|
-
var A = {};
|
|
883
|
-
var B = {};
|
|
884
|
-
// eslint-disable-next-line no-undef
|
|
885
|
-
var symbol = Symbol();
|
|
886
|
-
var alphabet = 'abcdefghijklmnopqrst';
|
|
887
|
-
A[symbol] = 7;
|
|
888
|
-
alphabet.split('').forEach(function (chr) { B[chr] = chr; });
|
|
889
|
-
return nativeAssign({}, A)[symbol] != 7 || objectKeys(nativeAssign({}, B)).join('') != alphabet;
|
|
890
|
-
}) ? function assign(target, source) { // eslint-disable-line no-unused-vars
|
|
891
|
-
var T = toObject(target);
|
|
892
|
-
var argumentsLength = arguments.length;
|
|
893
|
-
var index = 1;
|
|
894
|
-
var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
|
|
895
|
-
var propertyIsEnumerable = objectPropertyIsEnumerable.f;
|
|
896
|
-
while (argumentsLength > index) {
|
|
897
|
-
var S = indexedObject(arguments[index++]);
|
|
898
|
-
var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S);
|
|
899
|
-
var length = keys.length;
|
|
900
|
-
var j = 0;
|
|
901
|
-
var key;
|
|
902
|
-
while (length > j) {
|
|
903
|
-
key = keys[j++];
|
|
904
|
-
if (!descriptors || propertyIsEnumerable.call(S, key)) T[key] = S[key];
|
|
905
|
-
}
|
|
906
|
-
} return T;
|
|
907
|
-
} : nativeAssign;
|
|
908
|
-
|
|
909
|
-
// `Object.assign` method
|
|
910
|
-
// https://tc39.github.io/ecma262/#sec-object.assign
|
|
911
|
-
_export({ target: 'Object', stat: true, forced: Object.assign !== objectAssign }, {
|
|
912
|
-
assign: objectAssign
|
|
913
|
-
});
|
|
914
|
-
|
|
915
|
-
var FAILS_ON_PRIMITIVES = fails(function () { objectKeys(1); });
|
|
916
|
-
|
|
917
|
-
// `Object.keys` method
|
|
918
|
-
// https://tc39.github.io/ecma262/#sec-object.keys
|
|
919
|
-
_export({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES }, {
|
|
920
|
-
keys: function keys(it) {
|
|
921
|
-
return objectKeys(toObject(it));
|
|
922
|
-
}
|
|
923
|
-
});
|
|
924
|
-
|
|
925
|
-
function _classCallCheck(instance, Constructor) {
|
|
926
|
-
if (!(instance instanceof Constructor)) {
|
|
927
|
-
throw new TypeError("Cannot call a class as a function");
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
function _defineProperties(target, props) {
|
|
932
|
-
for (var i = 0; i < props.length; i++) {
|
|
933
|
-
var descriptor = props[i];
|
|
934
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
935
|
-
descriptor.configurable = true;
|
|
936
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
937
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
942
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
943
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
944
|
-
return Constructor;
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
|
|
948
|
-
var isIos = /(iPhone|iPod|iPad)/.test(navigator.userAgent);
|
|
949
|
-
|
|
950
|
-
function err(msg) {
|
|
951
|
-
console.error("[SpyClient_log]".concat(msg));
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
function stringify(obj) {
|
|
955
|
-
return Object.keys(obj).map(function (key) {
|
|
956
|
-
var value = obj[key];
|
|
957
|
-
|
|
958
|
-
if (typeof value === 'undefined') {
|
|
959
|
-
value = '';
|
|
960
|
-
} else if (typeof value !== 'string') {
|
|
961
|
-
value = JSON.stringify(value);
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
return encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
|
965
|
-
}).join('&');
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
var SpyClient = function () {
|
|
969
|
-
function SpyClient(option) {
|
|
970
|
-
_classCallCheck(this, SpyClient);
|
|
971
|
-
|
|
972
|
-
this.sample = {};
|
|
973
|
-
this.markCache = {};
|
|
974
|
-
|
|
975
|
-
if (!option.pid) {
|
|
976
|
-
throw new Error('pid is required');
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
this.option = {
|
|
980
|
-
pid: option.pid,
|
|
981
|
-
lid: option.lid,
|
|
982
|
-
check: option.check !== false,
|
|
983
|
-
sample: option.sample,
|
|
984
|
-
logServer: option.logServer || defaultLogServer
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
_createClass(SpyClient, [{
|
|
989
|
-
key: "send",
|
|
990
|
-
value: function send(query) {
|
|
991
|
-
if (!this.check(query)) {
|
|
992
|
-
return;
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
if (typeof query.sample === 'number') {
|
|
996
|
-
if (Math.random() > query.sample) {
|
|
997
|
-
return;
|
|
998
|
-
}
|
|
999
|
-
} else if (typeof this.option.sample === 'number' && Math.random() > this.option.sample) {
|
|
1000
|
-
return;
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
query = Object.assign({
|
|
1004
|
-
pid: this.option.pid,
|
|
1005
|
-
lid: this.option.lid,
|
|
1006
|
-
ts: Date.now(),
|
|
1007
|
-
group: 'common'
|
|
1008
|
-
}, query);
|
|
1009
|
-
delete query.sample;
|
|
1010
|
-
var url = this.option.logServer + stringify(query);
|
|
1011
|
-
|
|
1012
|
-
if (!(!isIos && navigator.sendBeacon && navigator.sendBeacon(url))) {
|
|
1013
|
-
new Image().src = url;
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
}, {
|
|
1017
|
-
key: "check",
|
|
1018
|
-
value: function check(query) {
|
|
1019
|
-
if (!this.option.check) {
|
|
1020
|
-
return true;
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
var types = ['perf', 'except', 'dist', 'count'];
|
|
1024
|
-
|
|
1025
|
-
if (types.indexOf(query.type) === -1) {
|
|
1026
|
-
err('type only is one of ' + types.join(', '));
|
|
1027
|
-
return false;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
if (query.group && query.group.length > 30) {
|
|
1031
|
-
err('group length execeeds 30');
|
|
1032
|
-
return false;
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
var simpleReg = /^[a-zA-Z0-9-_]{0,30}$/;
|
|
1036
|
-
|
|
1037
|
-
if (query.type === 'except') {
|
|
1038
|
-
if (!(typeof query.info.msg === 'string' && query.info.msg.length)) {
|
|
1039
|
-
err('info.msg field must be not empty and is String');
|
|
1040
|
-
return false;
|
|
1041
|
-
}
|
|
1042
|
-
} else {
|
|
1043
|
-
for (var _i = 0, _Object$keys = Object.keys(query.info); _i < _Object$keys.length; _i++) {
|
|
1044
|
-
var infoKey = _Object$keys[_i];
|
|
1045
|
-
|
|
1046
|
-
if (!simpleReg.test(infoKey)) {
|
|
1047
|
-
err("info.".concat(infoKey, " is unexpected. ") + 'Length must be not more than 30. ' + 'Supported chars: a-zA-Z0-9-_');
|
|
1048
|
-
return false;
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
var infoVal = query.info[infoKey];
|
|
1052
|
-
|
|
1053
|
-
if (query.type === 'dist') {
|
|
1054
|
-
if (infoVal.length > 30) {
|
|
1055
|
-
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
1056
|
-
return false;
|
|
1057
|
-
}
|
|
1058
|
-
} else if (typeof infoVal !== 'number') {
|
|
1059
|
-
err("info.".concat(infoKey, " value must be number"));
|
|
1060
|
-
return false;
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
if (query.dim) {
|
|
1066
|
-
for (var _i2 = 0, _Object$keys2 = Object.keys(query.dim); _i2 < _Object$keys2.length; _i2++) {
|
|
1067
|
-
var dimKey = _Object$keys2[_i2];
|
|
1068
|
-
|
|
1069
|
-
if (!simpleReg.test(dimKey)) {
|
|
1070
|
-
err("dim key [".concat(dimKey, "] is unexpected. ") + 'Length must be not more than 30. ' + 'Supported chars: a-zA-Z0-9-_');
|
|
1071
|
-
return false;
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
var dimVal = query.dim[dimKey];
|
|
1075
|
-
|
|
1076
|
-
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
1077
|
-
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ") + 'Length must be not more than 30. ' + 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
1078
|
-
return false;
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
return true;
|
|
1084
|
-
}
|
|
1085
|
-
}, {
|
|
1086
|
-
key: "sendPerf",
|
|
1087
|
-
value: function sendPerf(option) {
|
|
1088
|
-
this.send(Object.assign({
|
|
1089
|
-
type: 'perf'
|
|
1090
|
-
}, option));
|
|
1091
|
-
}
|
|
1092
|
-
}, {
|
|
1093
|
-
key: "sendExcept",
|
|
1094
|
-
value: function sendExcept(option) {
|
|
1095
|
-
this.send(Object.assign({
|
|
1096
|
-
type: 'except'
|
|
1097
|
-
}, option));
|
|
1098
|
-
}
|
|
1099
|
-
}, {
|
|
1100
|
-
key: "sendDist",
|
|
1101
|
-
value: function sendDist(option) {
|
|
1102
|
-
this.send(Object.assign({
|
|
1103
|
-
type: 'dist'
|
|
1104
|
-
}, option));
|
|
1105
|
-
}
|
|
1106
|
-
}, {
|
|
1107
|
-
key: "sendCount",
|
|
1108
|
-
value: function sendCount(option) {
|
|
1109
|
-
this.send(Object.assign({
|
|
1110
|
-
type: 'count'
|
|
1111
|
-
}, option));
|
|
1112
|
-
}
|
|
1113
|
-
}, {
|
|
1114
|
-
key: "sendExceptForError",
|
|
1115
|
-
value: function sendExceptForError(e, option) {
|
|
1116
|
-
var newOpt = Object.assign({}, option);
|
|
1117
|
-
newOpt.info = Object.assign({}, option.info || {}, {
|
|
1118
|
-
msg: e.message,
|
|
1119
|
-
stack: e.stack
|
|
1120
|
-
});
|
|
1121
|
-
this.sendExcept(newOpt);
|
|
1122
|
-
}
|
|
1123
|
-
}, {
|
|
1124
|
-
key: "startMark",
|
|
1125
|
-
value: function startMark(sign) {
|
|
1126
|
-
this.markCache[sign] = {
|
|
1127
|
-
start: Date.now()
|
|
1128
|
-
};
|
|
1129
|
-
}
|
|
1130
|
-
}, {
|
|
1131
|
-
key: "endMark",
|
|
1132
|
-
value: function endMark(sign) {
|
|
1133
|
-
if (this.markCache[sign]) {
|
|
1134
|
-
this.markCache[sign].total = Date.now() - this.markCache[sign].start;
|
|
1135
|
-
return this.markCache[sign].total;
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
return 0;
|
|
1139
|
-
}
|
|
1140
|
-
}, {
|
|
1141
|
-
key: "clearMark",
|
|
1142
|
-
value: function clearMark(sign) {
|
|
1143
|
-
if (this.markCache[sign]) {
|
|
1144
|
-
delete this.markCache[sign];
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
}, {
|
|
1148
|
-
key: "getAllMark",
|
|
1149
|
-
value: function getAllMark() {
|
|
1150
|
-
var ret = {};
|
|
1151
|
-
|
|
1152
|
-
for (var _i3 = 0, _Object$keys3 = Object.keys(this.markCache); _i3 < _Object$keys3.length; _i3++) {
|
|
1153
|
-
var sign = _Object$keys3[_i3];
|
|
1154
|
-
ret[sign] = this.markCache[sign].total;
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
return ret;
|
|
1158
|
-
}
|
|
1159
|
-
}, {
|
|
1160
|
-
key: "clearAllMark",
|
|
1161
|
-
value: function clearAllMark() {
|
|
1162
|
-
this.markCache = {};
|
|
1163
|
-
}
|
|
1164
|
-
}]);
|
|
1165
|
-
|
|
1166
|
-
return SpyClient;
|
|
1167
|
-
}();
|
|
1168
|
-
|
|
1169
|
-
export default SpyClient;
|
|
25
|
+
/**
|
|
26
|
+
* @file SpyClient
|
|
27
|
+
* @author kaivean
|
|
28
|
+
*/
|
|
29
|
+
var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
|
|
30
|
+
var isIos = /(iPhone|iPod|iPad)/.test(navigator.userAgent);
|
|
31
|
+
function err(msg) {
|
|
32
|
+
console.error("[SpyClient_log]" + msg);
|
|
33
|
+
// throw new Error(msg);
|
|
34
|
+
}
|
|
35
|
+
function stringify(obj) {
|
|
36
|
+
return Object.keys(obj).map(function (key) {
|
|
37
|
+
var value = obj[key];
|
|
38
|
+
if (typeof value === 'undefined') {
|
|
39
|
+
value = '';
|
|
40
|
+
}
|
|
41
|
+
else if (typeof value !== 'string') {
|
|
42
|
+
value = JSON.stringify(value);
|
|
43
|
+
}
|
|
44
|
+
return encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
|
45
|
+
}).join('&');
|
|
46
|
+
}
|
|
47
|
+
var SpyClient = /** @class */ (function () {
|
|
48
|
+
function SpyClient(option) {
|
|
49
|
+
this.sample = {};
|
|
50
|
+
this.markCache = {};
|
|
51
|
+
if (!option.pid) {
|
|
52
|
+
throw new Error('pid is required');
|
|
53
|
+
}
|
|
54
|
+
this.option = {
|
|
55
|
+
pid: option.pid,
|
|
56
|
+
lid: option.lid,
|
|
57
|
+
check: option.check !== false,
|
|
58
|
+
sample: option.sample,
|
|
59
|
+
logServer: option.logServer || defaultLogServer,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
SpyClient.prototype.send = function (query) {
|
|
63
|
+
if (!this.check(query)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// 当前api设置了抽样,
|
|
67
|
+
if (typeof query.sample === 'number') {
|
|
68
|
+
if (Math.random() > query.sample) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (typeof this.option.sample === 'number' && Math.random() > this.option.sample) { // 否则,用全局抽样
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
query = assign({
|
|
76
|
+
pid: this.option.pid,
|
|
77
|
+
lid: this.option.lid,
|
|
78
|
+
ts: Date.now(),
|
|
79
|
+
group: 'common',
|
|
80
|
+
}, query);
|
|
81
|
+
delete query.sample;
|
|
82
|
+
var url = this.option.logServer + stringify(query);
|
|
83
|
+
// 目前服务器端支持sendBeacon的post请求,可以优先采用,该api可以降低打点丢失率
|
|
84
|
+
// 但是ios有些问题:在webkit浏览内核环境下,beacon requests的请求方式存在证书验证的bug.
|
|
85
|
+
// 修复说明在如下链接中:https://bugs.webkit.org/show_bug.cgi?id=193508
|
|
86
|
+
// 但是目前为止,在iOS12.2版本中该问题依旧存在
|
|
87
|
+
if (!(!isIos
|
|
88
|
+
&& navigator.sendBeacon
|
|
89
|
+
&& navigator.sendBeacon(url))) {
|
|
90
|
+
(new Image()).src = url;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
SpyClient.prototype.check = function (query) {
|
|
94
|
+
if (!this.option.check) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
var types = ['perf', 'except', 'dist', 'count'];
|
|
98
|
+
if (types.indexOf(query.type) === -1) {
|
|
99
|
+
err('type only is one of ' + types.join(', '));
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (query.group && query.group.length > 30) {
|
|
103
|
+
err('group length execeeds 30');
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
var simpleReg = /^[a-zA-Z0-9-_]{0,30}$/;
|
|
107
|
+
if (query.type === 'except') {
|
|
108
|
+
if (!(typeof query.info.msg === 'string' && query.info.msg.length)) {
|
|
109
|
+
err('info.msg field must be not empty and is String');
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
115
|
+
var infoKey = _a[_i];
|
|
116
|
+
if (!simpleReg.test(infoKey)) {
|
|
117
|
+
err("info." + infoKey + " is unexpected. "
|
|
118
|
+
+ 'Length must be not more than 30. '
|
|
119
|
+
+ 'Supported chars: a-zA-Z0-9-_');
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
var infoVal = query.info[infoKey];
|
|
123
|
+
if (query.type === 'dist') {
|
|
124
|
+
if (infoVal.length > 30) {
|
|
125
|
+
err("info." + infoKey + " value length execeeds 30 when type == 'dist'");
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (typeof infoVal !== 'number') {
|
|
130
|
+
err("info." + infoKey + " value must be number");
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (query.dim) {
|
|
136
|
+
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
137
|
+
var dimKey = _c[_b];
|
|
138
|
+
if (!simpleReg.test(dimKey)) {
|
|
139
|
+
err("dim key [" + dimKey + "] is unexpected. "
|
|
140
|
+
+ 'Length must be not more than 30. '
|
|
141
|
+
+ 'Supported chars: a-zA-Z0-9-_');
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
var dimVal = query.dim[dimKey];
|
|
145
|
+
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
146
|
+
err("dim." + dimKey + " value [" + dimVal + "] is unexpected. "
|
|
147
|
+
+ 'Length must be not more than 30. '
|
|
148
|
+
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
*
|
|
157
|
+
* @param option 配置
|
|
158
|
+
*/
|
|
159
|
+
SpyClient.prototype.sendPerf = function (option) {
|
|
160
|
+
this.send(assign({
|
|
161
|
+
type: 'perf',
|
|
162
|
+
}, option));
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
*
|
|
166
|
+
* @param option 错误配置项
|
|
167
|
+
*/
|
|
168
|
+
SpyClient.prototype.sendExcept = function (option) {
|
|
169
|
+
this.send(assign({
|
|
170
|
+
type: 'except',
|
|
171
|
+
}, option));
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
*
|
|
175
|
+
* @param option 配置
|
|
176
|
+
*/
|
|
177
|
+
SpyClient.prototype.sendDist = function (option) {
|
|
178
|
+
this.send(assign({
|
|
179
|
+
type: 'dist',
|
|
180
|
+
}, option));
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
*
|
|
184
|
+
* @param option 配置
|
|
185
|
+
*/
|
|
186
|
+
SpyClient.prototype.sendCount = function (option) {
|
|
187
|
+
this.send(assign({
|
|
188
|
+
type: 'count',
|
|
189
|
+
}, option));
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
*
|
|
193
|
+
* @param e 错误实例
|
|
194
|
+
* @param option 错误配置项
|
|
195
|
+
*/
|
|
196
|
+
SpyClient.prototype.sendExceptForError = function (e, option) {
|
|
197
|
+
var newOpt = assign({}, option);
|
|
198
|
+
newOpt.info = assign({}, option.info || {}, {
|
|
199
|
+
msg: e.message,
|
|
200
|
+
stack: e.stack,
|
|
201
|
+
});
|
|
202
|
+
this.sendExcept(newOpt);
|
|
203
|
+
};
|
|
204
|
+
SpyClient.prototype.startMark = function (sign) {
|
|
205
|
+
this.markCache[sign] = {
|
|
206
|
+
start: Date.now(),
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
SpyClient.prototype.endMark = function (sign) {
|
|
210
|
+
if (this.markCache[sign]) {
|
|
211
|
+
this.markCache[sign].total = Date.now() - this.markCache[sign].start;
|
|
212
|
+
return this.markCache[sign].total;
|
|
213
|
+
}
|
|
214
|
+
return 0;
|
|
215
|
+
};
|
|
216
|
+
SpyClient.prototype.clearMark = function (sign) {
|
|
217
|
+
if (this.markCache[sign]) {
|
|
218
|
+
delete this.markCache[sign];
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
SpyClient.prototype.getAllMark = function () {
|
|
222
|
+
var ret = {};
|
|
223
|
+
for (var _i = 0, _a = Object.keys(this.markCache); _i < _a.length; _i++) {
|
|
224
|
+
var sign = _a[_i];
|
|
225
|
+
ret[sign] = this.markCache[sign].total;
|
|
226
|
+
}
|
|
227
|
+
return ret;
|
|
228
|
+
};
|
|
229
|
+
SpyClient.prototype.clearAllMark = function () {
|
|
230
|
+
this.markCache = {};
|
|
231
|
+
};
|
|
232
|
+
return SpyClient;
|
|
233
|
+
}());
|
|
234
|
+
|
|
235
|
+
export { SpyClient as default };
|