@contrail/util 1.1.13 → 1.1.14-alpha
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.
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cloneDeep = cloneDeep;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return date;
|
|
12
|
-
}
|
|
13
|
-
return value;
|
|
14
|
-
});
|
|
4
|
+
const cloneDefault = require('rfdc')();
|
|
5
|
+
const cloneWithCircles = require('rfdc')({ circles: true });
|
|
6
|
+
function cloneDeep(obj, options) {
|
|
7
|
+
var _a;
|
|
8
|
+
const shouldPreserveCircles = (_a = options === null || options === void 0 ? void 0 : options.shouldPreserveCircularReferences) !== null && _a !== void 0 ? _a : false;
|
|
9
|
+
const clone = shouldPreserveCircles ? cloneWithCircles : cloneDefault;
|
|
10
|
+
return clone(obj);
|
|
15
11
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare function retainOnlyProperties<T extends Record<string, any>, K extends readonly string[]>(obj: T[], keysToKeep: K, options?: {
|
|
2
|
-
shouldDeleteInPlace
|
|
2
|
+
shouldDeleteInPlace?: boolean;
|
|
3
|
+
skipKeys?: readonly string[];
|
|
3
4
|
}): Array<Pick<T, K[number]>>;
|
|
4
5
|
export declare function retainOnlyProperties<T extends Record<string, any>, K extends readonly string[]>(obj: T, keysToKeep: K, options?: {
|
|
5
|
-
shouldDeleteInPlace
|
|
6
|
+
shouldDeleteInPlace?: boolean;
|
|
7
|
+
skipKeys?: readonly string[];
|
|
6
8
|
}): Pick<T, K[number]>;
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.retainOnlyProperties = retainOnlyProperties;
|
|
4
4
|
const object_util_1 = require("../object-util");
|
|
5
|
-
function retainOnlyProperties(obj, keysToKeep, options = {
|
|
5
|
+
function retainOnlyProperties(obj, keysToKeep, options = {}) {
|
|
6
6
|
const keepSet = new Set(keysToKeep);
|
|
7
|
+
const skipSet = new Set(options.skipKeys || []);
|
|
7
8
|
const shouldReturnAsIs = (value) => value === null || value === undefined || typeof value !== 'object' || value instanceof Date;
|
|
8
9
|
const retain = (target) => {
|
|
9
10
|
if (shouldReturnAsIs(target))
|
|
@@ -12,6 +13,9 @@ function retainOnlyProperties(obj, keysToKeep, options = { shouldDeleteInPlace:
|
|
|
12
13
|
return target.map(retain);
|
|
13
14
|
}
|
|
14
15
|
for (const key in target) {
|
|
16
|
+
if (skipSet.has(key)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
15
19
|
if (!keepSet.has(key)) {
|
|
16
20
|
delete target[key];
|
|
17
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/util",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14-alpha",
|
|
4
4
|
"description": "General javascript utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@contrail/types": "^3.0.95",
|
|
43
43
|
"fflate": "^0.8.2",
|
|
44
|
-
"lodash": "^4.17.21"
|
|
44
|
+
"lodash": "^4.17.21",
|
|
45
|
+
"rfdc": "^1.4.1"
|
|
45
46
|
}
|
|
46
47
|
}
|