@contrail/util 1.1.9 → 1.1.10-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.
@@ -3,6 +3,7 @@ import { isObject } from './isObject/isObject';
3
3
  import { mergeDeep } from './mergeDeep/mergeDeep';
4
4
  import { getObjectDiffs } from './compareDeep/compareDeep';
5
5
  import { applyChangesIfEqual, determineChangesIfEqual, areItemPropertyValuesEqual } from './applyChangesIfEqual/applyChangesIfEqual';
6
+ import { retainOnlyProperties } from './retainOnlyProperties/retainOnlyProperties';
6
7
  export { ObjectDiff } from './compareDeep/compareDeep';
7
8
  export declare class ObjectUtil {
8
9
  static getByPath(obj: any, path: string, def?: any): any;
@@ -17,4 +18,5 @@ export declare class ObjectUtil {
17
18
  static applyChangesIfEqual: typeof applyChangesIfEqual;
18
19
  static determineChangesIfEqual: typeof determineChangesIfEqual;
19
20
  static areItemPropertyValuesEqual: typeof areItemPropertyValuesEqual;
21
+ static retainOnlyProperies: typeof retainOnlyProperties;
20
22
  }
@@ -6,6 +6,7 @@ const isObject_1 = require("./isObject/isObject");
6
6
  const mergeDeep_1 = require("./mergeDeep/mergeDeep");
7
7
  const compareDeep_1 = require("./compareDeep/compareDeep");
8
8
  const applyChangesIfEqual_1 = require("./applyChangesIfEqual/applyChangesIfEqual");
9
+ const retainOnlyProperties_1 = require("./retainOnlyProperties/retainOnlyProperties");
9
10
  class ObjectUtil {
10
11
  static getByPath(obj, path, def = null) {
11
12
  if (obj == undefined)
@@ -83,3 +84,4 @@ ObjectUtil.compareDeep = compareDeep_1.getObjectDiffs;
83
84
  ObjectUtil.applyChangesIfEqual = applyChangesIfEqual_1.applyChangesIfEqual;
84
85
  ObjectUtil.determineChangesIfEqual = applyChangesIfEqual_1.determineChangesIfEqual;
85
86
  ObjectUtil.areItemPropertyValuesEqual = applyChangesIfEqual_1.areItemPropertyValuesEqual;
87
+ ObjectUtil.retainOnlyProperies = retainOnlyProperties_1.retainOnlyProperties;
@@ -0,0 +1 @@
1
+ export declare function retainOnlyProperties<T, K extends keyof T>(obj: T, keysToKeep: K[]): Pick<T, K>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retainOnlyProperties = void 0;
4
+ function retainOnlyProperties(obj, keysToKeep) {
5
+ const keepSet = new Set(keysToKeep);
6
+ for (const key in obj) {
7
+ if (!keepSet.has(key)) {
8
+ delete obj[key];
9
+ }
10
+ }
11
+ return obj;
12
+ }
13
+ exports.retainOnlyProperties = retainOnlyProperties;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/util",
3
- "version": "1.1.9",
3
+ "version": "1.1.10-alpha-1",
4
4
  "description": "General javascript utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",