@twin.org/core 0.0.2-next.18 → 0.0.2-next.19

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.
@@ -2941,6 +2941,32 @@ class ObjectHelper {
2941
2941
  }
2942
2942
  return obj;
2943
2943
  }
2944
+ /**
2945
+ * Split an object into two with the specified keys.
2946
+ * @param obj The object to split.
2947
+ * @param keys The property keys to split.
2948
+ * @returns The two partial objects.
2949
+ */
2950
+ static split(obj, keys) {
2951
+ if (Is.object(obj) && Is.array(keys)) {
2952
+ const picked = {};
2953
+ const omitted = {};
2954
+ const allKeys = Object.keys(obj);
2955
+ for (const key of allKeys) {
2956
+ if (keys.includes(key)) {
2957
+ picked[key] = obj[key];
2958
+ }
2959
+ else {
2960
+ omitted[key] = obj[key];
2961
+ }
2962
+ }
2963
+ return {
2964
+ picked: Object.keys(picked).length > 0 ? picked : undefined,
2965
+ omitted: Object.keys(omitted).length > 0 ? omitted : undefined
2966
+ };
2967
+ }
2968
+ return { picked: obj, omitted: undefined };
2969
+ }
2944
2970
  /**
2945
2971
  * Converter the non JSON primitives to extended types.
2946
2972
  * @param obj The object to convert.
@@ -2939,6 +2939,32 @@ class ObjectHelper {
2939
2939
  }
2940
2940
  return obj;
2941
2941
  }
2942
+ /**
2943
+ * Split an object into two with the specified keys.
2944
+ * @param obj The object to split.
2945
+ * @param keys The property keys to split.
2946
+ * @returns The two partial objects.
2947
+ */
2948
+ static split(obj, keys) {
2949
+ if (Is.object(obj) && Is.array(keys)) {
2950
+ const picked = {};
2951
+ const omitted = {};
2952
+ const allKeys = Object.keys(obj);
2953
+ for (const key of allKeys) {
2954
+ if (keys.includes(key)) {
2955
+ picked[key] = obj[key];
2956
+ }
2957
+ else {
2958
+ omitted[key] = obj[key];
2959
+ }
2960
+ }
2961
+ return {
2962
+ picked: Object.keys(picked).length > 0 ? picked : undefined,
2963
+ omitted: Object.keys(omitted).length > 0 ? omitted : undefined
2964
+ };
2965
+ }
2966
+ return { picked: obj, omitted: undefined };
2967
+ }
2942
2968
  /**
2943
2969
  * Converter the non JSON primitives to extended types.
2944
2970
  * @param obj The object to convert.
@@ -80,6 +80,16 @@ export declare class ObjectHelper {
80
80
  * @returns The partial object.
81
81
  */
82
82
  static omit<T>(obj: T | undefined, keys?: (keyof T)[]): Partial<T>;
83
+ /**
84
+ * Split an object into two with the specified keys.
85
+ * @param obj The object to split.
86
+ * @param keys The property keys to split.
87
+ * @returns The two partial objects.
88
+ */
89
+ static split<T>(obj: T | undefined, keys?: (keyof T)[]): {
90
+ picked: Partial<T> | undefined;
91
+ omitted: Partial<T> | undefined;
92
+ };
83
93
  /**
84
94
  * Converter the non JSON primitives to extended types.
85
95
  * @param obj The object to convert.
package/docs/changelog.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @twin.org/core - Changelog
2
2
 
3
+ ## [0.0.2-next.19](https://github.com/twinfoundation/framework/compare/core-v0.0.2-next.18...core-v0.0.2-next.19) (2025-09-30)
4
+
5
+
6
+ ### Features
7
+
8
+ * add objectHelper.split ([386830a](https://github.com/twinfoundation/framework/commit/386830a77f8e842a5b119be0983708e042c3b14b))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/nameof bumped from 0.0.2-next.18 to 0.0.2-next.19
16
+ * devDependencies
17
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.18 to 0.0.2-next.19
18
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.18 to 0.0.2-next.19
19
+
3
20
  ## [0.0.2-next.18](https://github.com/twinfoundation/framework/compare/core-v0.0.2-next.17...core-v0.0.2-next.18) (2025-09-29)
4
21
 
5
22
 
@@ -390,6 +390,48 @@ The partial object.
390
390
 
391
391
  ***
392
392
 
393
+ ### split()
394
+
395
+ > `static` **split**\<`T`\>(`obj`, `keys?`): `object`
396
+
397
+ Split an object into two with the specified keys.
398
+
399
+ #### Type Parameters
400
+
401
+ ##### T
402
+
403
+ `T`
404
+
405
+ #### Parameters
406
+
407
+ ##### obj
408
+
409
+ The object to split.
410
+
411
+ `undefined` | `T`
412
+
413
+ ##### keys?
414
+
415
+ keyof `T`[]
416
+
417
+ The property keys to split.
418
+
419
+ #### Returns
420
+
421
+ `object`
422
+
423
+ The two partial objects.
424
+
425
+ ##### picked
426
+
427
+ > **picked**: `undefined` \| `Partial`\<`T`\>
428
+
429
+ ##### omitted
430
+
431
+ > **omitted**: `undefined` \| `Partial`\<`T`\>
432
+
433
+ ***
434
+
393
435
  ### toExtended()
394
436
 
395
437
  > `static` **toExtended**(`obj`): `any`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/core",
3
- "version": "0.0.2-next.18",
3
+ "version": "0.0.2-next.19",
4
4
  "description": "Helper methods/classes for data type checking/validation/guarding/error handling",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/nameof": "0.0.2-next.18",
17
+ "@twin.org/nameof": "0.0.2-next.19",
18
18
  "intl-messageformat": "10.7.16",
19
19
  "rfc6902": "5.1.2"
20
20
  },