@twin.org/core 0.0.1-next.34 → 0.0.1-next.36
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.
package/dist/cjs/index.cjs
CHANGED
|
@@ -2767,6 +2767,36 @@ 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
|
+
else if (Is.array(obj)) {
|
|
2792
|
+
const arr = [];
|
|
2793
|
+
for (const element of obj) {
|
|
2794
|
+
arr.push(ObjectHelper.removeEmptyProperties(element, options));
|
|
2795
|
+
}
|
|
2796
|
+
return arr;
|
|
2797
|
+
}
|
|
2798
|
+
return obj;
|
|
2799
|
+
}
|
|
2770
2800
|
}
|
|
2771
2801
|
|
|
2772
2802
|
// Copyright 2024 IOTA Stiftung.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -2765,6 +2765,36 @@ 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
|
+
else if (Is.array(obj)) {
|
|
2790
|
+
const arr = [];
|
|
2791
|
+
for (const element of obj) {
|
|
2792
|
+
arr.push(ObjectHelper.removeEmptyProperties(element, options));
|
|
2793
|
+
}
|
|
2794
|
+
return arr;
|
|
2795
|
+
}
|
|
2796
|
+
return obj;
|
|
2797
|
+
}
|
|
2768
2798
|
}
|
|
2769
2799
|
|
|
2770
2800
|
// 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
|
@@ -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.
|