@percy/sdk-utils 1.28.0 → 1.28.1-alpha.2

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/dist/timing.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _validations = require("./validations.js");
8
+ class TimeIt {
9
+ static data = {};
10
+ static enabled = process.env.PERCY_METRICS === 'true';
11
+ static async run(store, func) {
12
+ if (!this.enabled) return await func();
13
+ const t1 = Date.now();
14
+ try {
15
+ return await func();
16
+ } finally {
17
+ if ((0, _validations.Undefined)(this.data[store])) this.data[store] = [];
18
+ this.data[store].push(Date.now() - t1);
19
+ }
20
+ }
21
+ static min(store) {
22
+ return Math.min(...this.data[store]);
23
+ }
24
+ static max(store) {
25
+ return Math.max(...this.data[store]);
26
+ }
27
+ static avg(store) {
28
+ const vals = this.data[store];
29
+ return vals.reduce((a, b) => a + b, 0) / vals.length;
30
+ }
31
+ static summary({
32
+ includeVals
33
+ } = {}) {
34
+ const agg = {};
35
+ for (const key of Object.keys(this.data)) {
36
+ agg[key] = {
37
+ min: this.min(key),
38
+ max: this.max(key),
39
+ avg: this.avg(key),
40
+ count: this.data[key].length
41
+ };
42
+ if (includeVals) agg[key].vals = this.data[key];
43
+ }
44
+ return agg;
45
+ }
46
+ static reset() {
47
+ this.data = {};
48
+ }
49
+ }
50
+ exports.default = TimeIt;
51
+ ;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Undefined = Undefined;
7
+ exports.default = void 0;
8
+ function Undefined(obj) {
9
+ return obj === undefined;
10
+ }
11
+ var _default = Undefined;
12
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/sdk-utils",
3
- "version": "1.28.0",
3
+ "version": "1.28.1-alpha.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "publishConfig": {
11
11
  "access": "public",
12
- "tag": "latest"
12
+ "tag": "alpha"
13
13
  },
14
14
  "engines": {
15
15
  "node": ">=14"
@@ -51,5 +51,5 @@
51
51
  ]
52
52
  }
53
53
  },
54
- "gitHead": "9d95f18e45e37aa3683e5b8276fd85cf07dba8cb"
54
+ "gitHead": "a3f2e709d0a6445e15a1128686578b1659243a95"
55
55
  }