@contrail/util 1.1.1 → 1.1.3-0
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.
|
@@ -50,7 +50,8 @@ function getObjectDiffs(before, after, prefix) {
|
|
|
50
50
|
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
else if (Array.isArray(beforeVal) && !Array.isArray(afterVal))
|
|
53
|
+
else if ((Array.isArray(beforeVal) && !Array.isArray(afterVal)) ||
|
|
54
|
+
(!Array.isArray(beforeVal) && Array.isArray(afterVal))) {
|
|
54
55
|
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
55
56
|
}
|
|
56
57
|
else {
|
|
@@ -2,6 +2,11 @@ export declare enum TimeUnit {
|
|
|
2
2
|
MILLISECOND = "ms",
|
|
3
3
|
SECOND = "s"
|
|
4
4
|
}
|
|
5
|
+
export interface TimerDecoratorOptions {
|
|
6
|
+
onComplete?: (duration: number, methodName: string, args?: any[]) => void;
|
|
7
|
+
timeUnit?: TimeUnit;
|
|
8
|
+
threshold?: number;
|
|
9
|
+
}
|
|
5
10
|
export declare class Timer {
|
|
6
11
|
private startTime?;
|
|
7
12
|
private endTime?;
|
|
@@ -14,3 +19,4 @@ export declare class Timer {
|
|
|
14
19
|
private getCurrentTime;
|
|
15
20
|
}
|
|
16
21
|
export declare function delay(ms: number): Promise<unknown>;
|
|
22
|
+
export declare function timed(options?: TimerDecoratorOptions): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.delay = exports.Timer = exports.TimeUnit = void 0;
|
|
12
|
+
exports.timed = exports.delay = exports.Timer = exports.TimeUnit = void 0;
|
|
13
13
|
var TimeUnit;
|
|
14
14
|
(function (TimeUnit) {
|
|
15
15
|
TimeUnit["MILLISECOND"] = "ms";
|
|
@@ -63,3 +63,32 @@ function delay(ms) {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
exports.delay = delay;
|
|
66
|
+
function timed(options = {}) {
|
|
67
|
+
return function (target, propertyKey, descriptor) {
|
|
68
|
+
const originalMethod = descriptor.value;
|
|
69
|
+
descriptor.value = function (...args) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const timer = new Timer();
|
|
72
|
+
timer.start();
|
|
73
|
+
try {
|
|
74
|
+
const result = yield originalMethod.apply(this, args);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
timer.stop();
|
|
79
|
+
const duration = timer.getElapsedTime(options.timeUnit || TimeUnit.MILLISECOND);
|
|
80
|
+
if (!options.threshold || duration > options.threshold) {
|
|
81
|
+
if (options.onComplete) {
|
|
82
|
+
options.onComplete(duration, propertyKey, args);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
console.log(`${propertyKey} executed in ${duration}${options.timeUnit || 'ms'}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
return descriptor;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
exports.timed = timed;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/util",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3-0",
|
|
4
4
|
"description": "General javascript utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -41,4 +41,4 @@
|
|
|
41
41
|
"@contrail/types": "^3.0.74",
|
|
42
42
|
"lodash": "^4.17.21"
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
}
|