@contrail/util 1.1.10 → 1.1.11

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,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: boolean;
2
+ shouldDeleteInPlace?: boolean;
3
+ shouldSkipKeys?: 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: boolean;
6
+ shouldDeleteInPlace?: boolean;
7
+ shouldSkipKeys?: readonly string[];
6
8
  }): Pick<T, K[number]>;
@@ -2,8 +2,12 @@
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
+ function retainOnlyProperties(obj, keysToKeep, options = {
6
+ shouldDeleteInPlace: false,
7
+ shouldSkipKeys: [],
8
+ }) {
6
9
  const keepSet = new Set(keysToKeep);
10
+ const skipSet = new Set(options.shouldSkipKeys || []);
7
11
  const shouldReturnAsIs = (value) => value === null || value === undefined || typeof value !== 'object' || value instanceof Date;
8
12
  const retain = (target) => {
9
13
  if (shouldReturnAsIs(target))
@@ -12,6 +16,9 @@ function retainOnlyProperties(obj, keysToKeep, options = { shouldDeleteInPlace:
12
16
  return target.map(retain);
13
17
  }
14
18
  for (const key in target) {
19
+ if (skipSet.has(key)) {
20
+ continue;
21
+ }
15
22
  if (!keepSet.has(key)) {
16
23
  delete target[key];
17
24
  }
@@ -22,6 +29,7 @@ function retainOnlyProperties(obj, keysToKeep, options = { shouldDeleteInPlace:
22
29
  return target;
23
30
  };
24
31
  const objToModify = options.shouldDeleteInPlace ? obj : object_util_1.ObjectUtil.cloneDeep(obj);
25
- return retain(objToModify);
32
+ const toRetain = retain(objToModify);
33
+ return toRetain;
26
34
  }
27
35
  exports.retainOnlyProperties = retainOnlyProperties;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/util",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
4
4
  "description": "General javascript utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",