@contrail/util 1.1.3-3 → 1.1.3-alpha.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.
|
@@ -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<T extends object>(data: T): T;
|
|
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,25 @@ class ObjectUtil {
|
|
|
55
55
|
}
|
|
56
56
|
return chunked;
|
|
57
57
|
}
|
|
58
|
+
static removeEmptyProperties(data) {
|
|
59
|
+
if (data === null || data === undefined || typeof data !== 'object') {
|
|
60
|
+
return data;
|
|
61
|
+
}
|
|
62
|
+
const isEmpty = (v) => v === null || v === undefined || v === '';
|
|
63
|
+
if (Array.isArray(data)) {
|
|
64
|
+
const cleaned = data
|
|
65
|
+
.map(item => (typeof item === 'object' && item ? ObjectUtil.removeEmptyProperties(item) : item))
|
|
66
|
+
.filter(item => !isEmpty(item));
|
|
67
|
+
return cleaned;
|
|
68
|
+
}
|
|
69
|
+
const cleaned = Object.entries(data).reduce((acc, [key, value]) => {
|
|
70
|
+
if (!isEmpty(value)) {
|
|
71
|
+
acc[key] = typeof value === 'object' && value ? ObjectUtil.removeEmptyProperties(value) : value;
|
|
72
|
+
}
|
|
73
|
+
return acc;
|
|
74
|
+
}, {});
|
|
75
|
+
return cleaned;
|
|
76
|
+
}
|
|
58
77
|
}
|
|
59
78
|
exports.ObjectUtil = ObjectUtil;
|
|
60
79
|
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;
|