@cloudcare/browser-core 2.0.11 → 2.0.12

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.
@@ -46,7 +46,6 @@ function areCookiesAuthorized(options) {
46
46
  setCookie(testCookieName, testCookieValue, _tools.ONE_SECOND, options);
47
47
  return getCookie(testCookieName) === testCookieValue;
48
48
  } catch (error) {
49
- console.error(error);
50
49
  return false;
51
50
  }
52
51
  }
@@ -14,9 +14,10 @@ var END_OF_TIMES = Infinity;
14
14
  var CLEAR_OLD_CONTEXTS_INTERVAL = _tools.ONE_MINUTE;
15
15
  exports.CLEAR_OLD_CONTEXTS_INTERVAL = CLEAR_OLD_CONTEXTS_INTERVAL;
16
16
 
17
- function ContextHistory(expireDelay) {
17
+ function ContextHistory(expireDelay, maxEntries) {
18
18
  this.expireDelay = expireDelay;
19
19
  this.entries = [];
20
+ this.maxEntries = maxEntries;
20
21
 
21
22
  var _this = this;
22
23
 
@@ -43,6 +44,11 @@ ContextHistory.prototype.add = function (context, startTime) {
43
44
  entry.endTime = endTime;
44
45
  }
45
46
  };
47
+
48
+ if (this.maxEntries && this.entries.length >= this.maxEntries) {
49
+ this.entries.pop();
50
+ }
51
+
46
52
  this.entries.unshift(entry);
47
53
  return entry;
48
54
  };
@@ -83,13 +89,19 @@ ContextHistory.prototype.closeActive = function (endTime) {
83
89
  */
84
90
 
85
91
 
86
- ContextHistory.prototype.findAll = function (startTime) {
92
+ ContextHistory.prototype.findAll = function (startTime, duration) {
93
+ if (typeof duration === 'undefined') {
94
+ duration = 0;
95
+ }
96
+
97
+ var endTime = (0, _tools.addDuration)(startTime, duration);
98
+
87
99
  if (typeof startTime === 'undefined') {
88
100
  startTime = END_OF_TIMES;
89
101
  }
90
102
 
91
103
  var result = (0, _tools.filter)(this.entries, function (entry) {
92
- return entry.startTime <= startTime && startTime <= entry.endTime;
104
+ return entry.startTime <= endTime && startTime <= entry.endTime;
93
105
  });
94
106
  return (0, _tools.map)(result, function (entry) {
95
107
  return entry.context;
@@ -86,7 +86,7 @@ exports.values = exports.utf8Encode = exports.urlParse = exports.unique = export
86
86
  exports.withSnakeCaseKeys = withSnakeCaseKeys;
87
87
  exports.xhr = void 0;
88
88
 
89
- var _enums = require("./enums");
89
+ var _display = require("./display");
90
90
 
91
91
  var _timer = require("./timer");
92
92
 
@@ -385,9 +385,23 @@ var every = function every(arr, fn, self) {
385
385
 
386
386
  exports.every = every;
387
387
 
388
- var matchList = function matchList(list, value) {
388
+ var matchList = function matchList(list, value, useStartsWith) {
389
+ if (useStartsWith === undefined) {
390
+ useStartsWith = false;
391
+ }
392
+
389
393
  return some(list, function (item) {
390
- return item === value || item instanceof RegExp && item.test(value);
394
+ try {
395
+ if (typeof item === 'function') {
396
+ return item(value);
397
+ } else if (item instanceof RegExp) {
398
+ return item.test(value);
399
+ } else if (typeof item === 'string') {
400
+ return useStartsWith ? startsWith(value, item) : item === value;
401
+ }
402
+ } catch (e) {
403
+ _display.display.error(e);
404
+ }
391
405
  });
392
406
  }; // https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js
393
407
 
@@ -28,7 +28,6 @@ export function areCookiesAuthorized(options) {
28
28
  setCookie(testCookieName, testCookieValue, ONE_SECOND, options);
29
29
  return getCookie(testCookieName) === testCookieValue;
30
30
  } catch (error) {
31
- console.error(error);
32
31
  return false;
33
32
  }
34
33
  }
@@ -1,10 +1,11 @@
1
- import { relativeNow, ONE_MINUTE, filter, map } from './tools';
1
+ import { relativeNow, ONE_MINUTE, filter, map, addDuration } from './tools';
2
2
  import { setInterval, clearInterval } from './timer';
3
3
  var END_OF_TIMES = Infinity;
4
4
  export var CLEAR_OLD_CONTEXTS_INTERVAL = ONE_MINUTE;
5
- export function ContextHistory(expireDelay) {
5
+ export function ContextHistory(expireDelay, maxEntries) {
6
6
  this.expireDelay = expireDelay;
7
7
  this.entries = [];
8
+ this.maxEntries = maxEntries;
8
9
 
9
10
  var _this = this;
10
11
 
@@ -31,6 +32,11 @@ ContextHistory.prototype.add = function (context, startTime) {
31
32
  entry.endTime = endTime;
32
33
  }
33
34
  };
35
+
36
+ if (this.maxEntries && this.entries.length >= this.maxEntries) {
37
+ this.entries.pop();
38
+ }
39
+
34
40
  this.entries.unshift(entry);
35
41
  return entry;
36
42
  };
@@ -71,13 +77,19 @@ ContextHistory.prototype.closeActive = function (endTime) {
71
77
  */
72
78
 
73
79
 
74
- ContextHistory.prototype.findAll = function (startTime) {
80
+ ContextHistory.prototype.findAll = function (startTime, duration) {
81
+ if (typeof duration === 'undefined') {
82
+ duration = 0;
83
+ }
84
+
85
+ var endTime = addDuration(startTime, duration);
86
+
75
87
  if (typeof startTime === 'undefined') {
76
88
  startTime = END_OF_TIMES;
77
89
  }
78
90
 
79
91
  var result = filter(this.entries, function (entry) {
80
- return entry.startTime <= startTime && startTime <= entry.endTime;
92
+ return entry.startTime <= endTime && startTime <= entry.endTime;
81
93
  });
82
94
  return map(result, function (entry) {
83
95
  return entry.context;
@@ -1,4 +1,4 @@
1
- import { DOM_EVENT } from './enums';
1
+ import { display } from './display';
2
2
  import { setTimeout, clearTimeout } from './timer';
3
3
  var ArrayProto = Array.prototype;
4
4
  var FuncProto = Function.prototype;
@@ -242,9 +242,23 @@ export var every = function every(arr, fn, self) {
242
242
 
243
243
  return flag;
244
244
  };
245
- export var matchList = function matchList(list, value) {
245
+ export var matchList = function matchList(list, value, useStartsWith) {
246
+ if (useStartsWith === undefined) {
247
+ useStartsWith = false;
248
+ }
249
+
246
250
  return some(list, function (item) {
247
- return item === value || item instanceof RegExp && item.test(value);
251
+ try {
252
+ if (typeof item === 'function') {
253
+ return item(value);
254
+ } else if (item instanceof RegExp) {
255
+ return item.test(value);
256
+ } else if (typeof item === 'string') {
257
+ return useStartsWith ? startsWith(value, item) : item === value;
258
+ }
259
+ } catch (e) {
260
+ display.error(e);
261
+ }
248
262
  });
249
263
  }; // https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js
250
264
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/browser-core",
3
- "version": "2.0.11",
3
+ "version": "2.0.12",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "scripts": {
@@ -20,5 +20,5 @@
20
20
  "author": "dataflux",
21
21
  "license": "MIT",
22
22
  "description": "DataFlux RUM Web 端数据指标监控",
23
- "gitHead": "3419a0f49ffef058ceff8e94bc8f01274575988a"
23
+ "gitHead": "98664a15be351def98c4e9b33c8366b1fb8aa652"
24
24
  }
@@ -28,7 +28,6 @@ export function deleteCookie(name, options) {
28
28
  setCookie(name, '', 0, options)
29
29
  }
30
30
 
31
-
32
31
  export function areCookiesAuthorized(options) {
33
32
  if (document.cookie === undefined || document.cookie === null) {
34
33
  return false
@@ -41,7 +40,6 @@ export function areCookiesAuthorized(options) {
41
40
  setCookie(testCookieName, testCookieValue, ONE_SECOND, options)
42
41
  return getCookie(testCookieName) === testCookieValue
43
42
  } catch (error) {
44
- console.error(error)
45
43
  return false
46
44
  }
47
45
  }
@@ -1,16 +1,18 @@
1
- import { relativeNow, ONE_MINUTE, filter, map } from './tools'
1
+ import { relativeNow, ONE_MINUTE, filter, map, addDuration } from './tools'
2
2
  import { setInterval, clearInterval } from './timer'
3
3
  var END_OF_TIMES = Infinity
4
4
 
5
5
  export var CLEAR_OLD_CONTEXTS_INTERVAL = ONE_MINUTE
6
- export function ContextHistory(expireDelay) {
6
+ export function ContextHistory(expireDelay, maxEntries) {
7
7
  this.expireDelay = expireDelay
8
8
  this.entries = []
9
+ this.maxEntries = maxEntries
9
10
  var _this = this
10
11
  this.clearOldContextsInterval = setInterval(function () {
11
12
  _this.clearOldContexts()
12
13
  }, CLEAR_OLD_CONTEXTS_INTERVAL)
13
14
  }
15
+
14
16
  ContextHistory.prototype.add = function (context, startTime) {
15
17
  var _this = this
16
18
  var entry = {
@@ -27,6 +29,9 @@ ContextHistory.prototype.add = function (context, startTime) {
27
29
  entry.endTime = endTime
28
30
  }
29
31
  }
32
+ if (this.maxEntries && this.entries.length >= this.maxEntries) {
33
+ this.entries.pop()
34
+ }
30
35
  this.entries.unshift(entry)
31
36
  return entry
32
37
  }
@@ -58,12 +63,16 @@ ContextHistory.prototype.closeActive = function (endTime) {
58
63
  * Return all contexts that were active during `startTime`, or all currently active contexts if no
59
64
  * `startTime` is provided.
60
65
  */
61
- ContextHistory.prototype.findAll = function (startTime) {
66
+ ContextHistory.prototype.findAll = function (startTime, duration) {
67
+ if (typeof duration === 'undefined') {
68
+ duration = 0
69
+ }
70
+ var endTime = addDuration(startTime, duration)
62
71
  if (typeof startTime === 'undefined') {
63
72
  startTime = END_OF_TIMES
64
73
  }
65
74
  var result = filter(this.entries, function (entry) {
66
- return entry.startTime <= startTime && startTime <= entry.endTime
75
+ return entry.startTime <= endTime && startTime <= entry.endTime
67
76
  })
68
77
  return map(result, function (entry) {
69
78
  return entry.context
@@ -1,4 +1,4 @@
1
- import { DOM_EVENT } from './enums'
1
+ import { display } from './display'
2
2
  import { setTimeout, clearTimeout } from './timer'
3
3
  var ArrayProto = Array.prototype
4
4
  var FuncProto = Function.prototype
@@ -214,9 +214,22 @@ export var every = function (arr, fn, self) {
214
214
  }
215
215
  return flag
216
216
  }
217
- export var matchList = function (list, value) {
217
+ export var matchList = function (list, value, useStartsWith) {
218
+ if (useStartsWith === undefined) {
219
+ useStartsWith = false
220
+ }
218
221
  return some(list, function (item) {
219
- return item === value || (item instanceof RegExp && item.test(value))
222
+ try {
223
+ if (typeof item === 'function') {
224
+ return item(value)
225
+ } else if (item instanceof RegExp) {
226
+ return item.test(value)
227
+ } else if (typeof item === 'string') {
228
+ return useStartsWith ? startsWith(value, item) : item === value
229
+ }
230
+ } catch (e) {
231
+ display.error(e)
232
+ }
220
233
  })
221
234
  }
222
235
  // https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js