@contrail/util 1.1.10-alpha-5 → 1.1.10-alpha-7
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.
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cloneDeep = void 0;
|
|
4
4
|
function cloneDeep(obj) {
|
|
5
|
-
if (
|
|
5
|
+
if (obj == null)
|
|
6
6
|
return null;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
return JSON.parse(JSON.stringify(obj), (_key, value) => {
|
|
8
|
+
if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(value)) {
|
|
9
|
+
const date = new Date(value);
|
|
10
|
+
if (!isNaN(date.getTime()))
|
|
11
|
+
return date;
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
});
|
|
9
15
|
}
|
|
10
16
|
exports.cloneDeep = cloneDeep;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export declare function retainOnlyProperties<T extends Record<string, any>, K extends readonly string[]>(obj: T[], keysToKeep: K
|
|
2
|
-
|
|
1
|
+
export declare function retainOnlyProperties<T extends Record<string, any>, K extends readonly string[]>(obj: T[], keysToKeep: K, options?: {
|
|
2
|
+
shouldDeleteInPlace: boolean;
|
|
3
|
+
}): Array<Pick<T, K[number]>>;
|
|
4
|
+
export declare function retainOnlyProperties<T extends Record<string, any>, K extends readonly string[]>(obj: T, keysToKeep: K, options?: {
|
|
5
|
+
shouldDeleteInPlace: boolean;
|
|
6
|
+
}): Pick<T, K[number]>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.retainOnlyProperties = void 0;
|
|
4
|
-
|
|
4
|
+
const object_util_1 = require("../object-util");
|
|
5
|
+
function retainOnlyProperties(obj, keysToKeep, options = { shouldDeleteInPlace: false }) {
|
|
5
6
|
const keepSet = new Set(keysToKeep);
|
|
6
7
|
const shouldReturnAsIs = (value) => value === null || value === undefined || typeof value !== 'object' || value instanceof Date;
|
|
7
8
|
const retain = (target) => {
|
|
@@ -20,6 +21,7 @@ function retainOnlyProperties(obj, keysToKeep) {
|
|
|
20
21
|
}
|
|
21
22
|
return target;
|
|
22
23
|
};
|
|
23
|
-
|
|
24
|
+
const objToModify = options.shouldDeleteInPlace ? obj : object_util_1.ObjectUtil.cloneDeep(obj);
|
|
25
|
+
return retain(objToModify);
|
|
24
26
|
}
|
|
25
27
|
exports.retainOnlyProperties = retainOnlyProperties;
|