@twin.org/core 0.0.1-next.34 → 0.0.1-next.35

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.
@@ -2767,6 +2767,29 @@ class ObjectHelper {
2767
2767
  const jsonExtended = JsonHelper.stringifyEx(obj);
2768
2768
  return JsonHelper.parseEx(jsonExtended);
2769
2769
  }
2770
+ /**
2771
+ * Remove empty properties from an object.
2772
+ * @param obj The object to remove the empty properties from.
2773
+ * @param options The options for the removal.
2774
+ * @param options.removeUndefined Remove undefined properties, defaults to true.
2775
+ * @param options.removeNull Remove null properties, defaults to false.
2776
+ * @returns The object with empty properties removed.
2777
+ */
2778
+ static removeEmptyProperties(obj, options) {
2779
+ if (Is.object(obj)) {
2780
+ const removeUndefined = options?.removeUndefined ?? true;
2781
+ const removeNull = options?.removeNull ?? false;
2782
+ const newObj = {};
2783
+ const keys = Object.keys(obj);
2784
+ for (const key of keys) {
2785
+ if (!((removeUndefined && Is.undefined(obj[key])) || (removeNull && Is.null(obj[key])))) {
2786
+ newObj[key] = ObjectHelper.removeEmptyProperties(obj[key], options);
2787
+ }
2788
+ }
2789
+ return newObj;
2790
+ }
2791
+ return obj;
2792
+ }
2770
2793
  }
2771
2794
 
2772
2795
  // Copyright 2024 IOTA Stiftung.
@@ -2765,6 +2765,29 @@ class ObjectHelper {
2765
2765
  const jsonExtended = JsonHelper.stringifyEx(obj);
2766
2766
  return JsonHelper.parseEx(jsonExtended);
2767
2767
  }
2768
+ /**
2769
+ * Remove empty properties from an object.
2770
+ * @param obj The object to remove the empty properties from.
2771
+ * @param options The options for the removal.
2772
+ * @param options.removeUndefined Remove undefined properties, defaults to true.
2773
+ * @param options.removeNull Remove null properties, defaults to false.
2774
+ * @returns The object with empty properties removed.
2775
+ */
2776
+ static removeEmptyProperties(obj, options) {
2777
+ if (Is.object(obj)) {
2778
+ const removeUndefined = options?.removeUndefined ?? true;
2779
+ const removeNull = options?.removeNull ?? false;
2780
+ const newObj = {};
2781
+ const keys = Object.keys(obj);
2782
+ for (const key of keys) {
2783
+ if (!((removeUndefined && Is.undefined(obj[key])) || (removeNull && Is.null(obj[key])))) {
2784
+ newObj[key] = ObjectHelper.removeEmptyProperties(obj[key], options);
2785
+ }
2786
+ }
2787
+ return newObj;
2788
+ }
2789
+ return obj;
2790
+ }
2768
2791
  }
2769
2792
 
2770
2793
  // Copyright 2024 IOTA Stiftung.
@@ -92,4 +92,16 @@ export declare class ObjectHelper {
92
92
  * @returns The object with regular properties.
93
93
  */
94
94
  static fromExtended(obj: any): any;
95
+ /**
96
+ * Remove empty properties from an object.
97
+ * @param obj The object to remove the empty properties from.
98
+ * @param options The options for the removal.
99
+ * @param options.removeUndefined Remove undefined properties, defaults to true.
100
+ * @param options.removeNull Remove null properties, defaults to false.
101
+ * @returns The object with empty properties removed.
102
+ */
103
+ static removeEmptyProperties<T = unknown>(obj: T, options?: {
104
+ removeUndefined?: boolean;
105
+ removeNull?: boolean;
106
+ }): T;
95
107
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/core - Changelog
2
2
 
3
- ## 0.0.1-next.34
3
+ ## 0.0.1-next.35
4
4
 
5
5
  - Initial Release
@@ -411,3 +411,45 @@ The object to convert.
411
411
  `any`
412
412
 
413
413
  The object with regular properties.
414
+
415
+ ***
416
+
417
+ ### removeEmptyProperties()
418
+
419
+ > `static` **removeEmptyProperties**\<`T`\>(`obj`, `options`?): `T`
420
+
421
+ Remove empty properties from an object.
422
+
423
+ #### Type Parameters
424
+
425
+ • **T** = `unknown`
426
+
427
+ #### Parameters
428
+
429
+ ##### obj
430
+
431
+ `T`
432
+
433
+ The object to remove the empty properties from.
434
+
435
+ ##### options?
436
+
437
+ The options for the removal.
438
+
439
+ ###### removeUndefined
440
+
441
+ `boolean`
442
+
443
+ Remove undefined properties, defaults to true.
444
+
445
+ ###### removeNull
446
+
447
+ `boolean`
448
+
449
+ Remove null properties, defaults to false.
450
+
451
+ #### Returns
452
+
453
+ `T`
454
+
455
+ The object with empty properties removed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/core",
3
- "version": "0.0.1-next.34",
3
+ "version": "0.0.1-next.35",
4
4
  "description": "Helper methods/classes for data type checking/validation/guarding/error handling",
5
5
  "repository": {
6
6
  "type": "git",