@contrail/util 1.1.3-3 → 1.1.3-alpha.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.
|
@@ -9,6 +9,7 @@ export declare class ObjectUtil {
|
|
|
9
9
|
static getBySlugs(obj: any, rootSlug: string, slug?: string): any;
|
|
10
10
|
static setByPath(obj: any, path: string, value: any): void;
|
|
11
11
|
static chunk(array: any[], size: number): any[];
|
|
12
|
+
static removeEmptyProperties(json: Record<string, any>): Record<string, any>;
|
|
12
13
|
static isObject: typeof isObject;
|
|
13
14
|
static mergeDeep: typeof mergeDeep;
|
|
14
15
|
static cloneDeep: typeof cloneDeep;
|
|
@@ -15,7 +15,7 @@ class ObjectUtil {
|
|
|
15
15
|
return value === undefined ? def : value;
|
|
16
16
|
}
|
|
17
17
|
const pathUnits = path.split('.');
|
|
18
|
-
pathUnits.forEach(
|
|
18
|
+
pathUnits.forEach(level => {
|
|
19
19
|
if (obj) {
|
|
20
20
|
obj = obj[level];
|
|
21
21
|
}
|
|
@@ -55,6 +55,29 @@ class ObjectUtil {
|
|
|
55
55
|
}
|
|
56
56
|
return chunked;
|
|
57
57
|
}
|
|
58
|
+
static removeEmptyProperties(json) {
|
|
59
|
+
if (typeof json !== 'object' || json === null)
|
|
60
|
+
return json;
|
|
61
|
+
if (Array.isArray(json)) {
|
|
62
|
+
return json
|
|
63
|
+
.map(item => (typeof item === 'object' ? ObjectUtil.removeEmptyProperties(item) : item))
|
|
64
|
+
.filter(item => item !== null && item !== undefined && item !== '');
|
|
65
|
+
}
|
|
66
|
+
return Object.entries(json).reduce((acc, [key, value]) => {
|
|
67
|
+
if (value == null || value === '')
|
|
68
|
+
return acc;
|
|
69
|
+
if (typeof value === 'object') {
|
|
70
|
+
const cleanedValue = ObjectUtil.removeEmptyProperties(value);
|
|
71
|
+
if (Array.isArray(value) || Object.keys(cleanedValue).length > 0) {
|
|
72
|
+
acc[key] = cleanedValue;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
acc[key] = value;
|
|
77
|
+
}
|
|
78
|
+
return acc;
|
|
79
|
+
}, {});
|
|
80
|
+
}
|
|
58
81
|
}
|
|
59
82
|
exports.ObjectUtil = ObjectUtil;
|
|
60
83
|
ObjectUtil.isObject = isObject_1.isObject;
|
|
@@ -2,11 +2,6 @@ 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
|
-
}
|
|
10
5
|
export declare class Timer {
|
|
11
6
|
private startTime?;
|
|
12
7
|
private endTime?;
|
|
@@ -19,4 +14,3 @@ export declare class Timer {
|
|
|
19
14
|
private getCurrentTime;
|
|
20
15
|
}
|
|
21
16
|
export declare function delay(ms: number): Promise<unknown>;
|
|
22
|
-
export declare function timed(): (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.
|
|
12
|
+
exports.delay = exports.Timer = exports.TimeUnit = void 0;
|
|
13
13
|
var TimeUnit;
|
|
14
14
|
(function (TimeUnit) {
|
|
15
15
|
TimeUnit["MILLISECOND"] = "ms";
|
|
@@ -63,24 +63,3 @@ function delay(ms) {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
exports.delay = delay;
|
|
66
|
-
function timed() {
|
|
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 start = Date.now();
|
|
72
|
-
console.log(`⏱️ Starting ${propertyKey}`);
|
|
73
|
-
try {
|
|
74
|
-
const result = yield originalMethod.apply(this, args);
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
77
|
-
finally {
|
|
78
|
-
const end = Date.now();
|
|
79
|
-
console.log(`✅ ${propertyKey} completed in ${end - start}ms`);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
return descriptor;
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
exports.timed = timed;
|