@twin.org/core 0.0.2-next.17 → 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.
- package/dist/cjs/index.cjs +28 -2
- package/dist/esm/index.mjs +28 -2
- package/dist/types/helpers/objectHelper.d.ts +10 -0
- package/dist/types/helpers/stringHelper.d.ts +4 -16
- package/docs/changelog.md +34 -0
- package/docs/reference/classes/ObjectHelper.md +42 -0
- package/docs/reference/classes/StringHelper.md +10 -72
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -400,7 +400,7 @@ class StringHelper {
|
|
|
400
400
|
/**
|
|
401
401
|
* Implementation signature for trimTrailingSlashes.
|
|
402
402
|
* @param value The value to trim.
|
|
403
|
-
* @returns The trimmed string or the original
|
|
403
|
+
* @returns The trimmed string or the original.
|
|
404
404
|
*/
|
|
405
405
|
static trimTrailingSlashes(value) {
|
|
406
406
|
if (Is.string(value)) {
|
|
@@ -411,7 +411,7 @@ class StringHelper {
|
|
|
411
411
|
/**
|
|
412
412
|
* Implementation signature for trimLeadingSlashes.
|
|
413
413
|
* @param value The value to trim.
|
|
414
|
-
* @returns The trimmed string or the original
|
|
414
|
+
* @returns The trimmed string or the original.
|
|
415
415
|
*/
|
|
416
416
|
static trimLeadingSlashes(value) {
|
|
417
417
|
if (Is.string(value)) {
|
|
@@ -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.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -398,7 +398,7 @@ class StringHelper {
|
|
|
398
398
|
/**
|
|
399
399
|
* Implementation signature for trimTrailingSlashes.
|
|
400
400
|
* @param value The value to trim.
|
|
401
|
-
* @returns The trimmed string or the original
|
|
401
|
+
* @returns The trimmed string or the original.
|
|
402
402
|
*/
|
|
403
403
|
static trimTrailingSlashes(value) {
|
|
404
404
|
if (Is.string(value)) {
|
|
@@ -409,7 +409,7 @@ class StringHelper {
|
|
|
409
409
|
/**
|
|
410
410
|
* Implementation signature for trimLeadingSlashes.
|
|
411
411
|
* @param value The value to trim.
|
|
412
|
-
* @returns The trimmed string or the original
|
|
412
|
+
* @returns The trimmed string or the original.
|
|
413
413
|
*/
|
|
414
414
|
static trimLeadingSlashes(value) {
|
|
415
415
|
if (Is.string(value)) {
|
|
@@ -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.
|
|
@@ -3,29 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export declare class StringHelper {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Overloads preserve null/undefined instead of coercing to empty string.
|
|
6
|
+
* Implementation signature for trimTrailingSlashes.
|
|
8
7
|
* @param value The value to trim.
|
|
9
|
-
* @returns The trimmed
|
|
8
|
+
* @returns The trimmed string or the original.
|
|
10
9
|
*/
|
|
11
10
|
static trimTrailingSlashes(value: string): string;
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @param value
|
|
15
|
-
*/
|
|
16
|
-
static trimTrailingSlashes<T extends null | undefined>(value: T): T;
|
|
17
|
-
/**
|
|
18
|
-
* Trim leading slashes from a string.
|
|
19
|
-
* Overloads preserve null/undefined instead of coercing to empty string.
|
|
12
|
+
* Implementation signature for trimLeadingSlashes.
|
|
20
13
|
* @param value The value to trim.
|
|
21
|
-
* @returns The trimmed
|
|
14
|
+
* @returns The trimmed string or the original.
|
|
22
15
|
*/
|
|
23
16
|
static trimLeadingSlashes(value: string): string;
|
|
24
|
-
/**
|
|
25
|
-
* Overload for null/undefined passthrough.
|
|
26
|
-
* @param value The null or undefined value.
|
|
27
|
-
*/
|
|
28
|
-
static trimLeadingSlashes<T extends null | undefined>(value: T): T;
|
|
29
17
|
/**
|
|
30
18
|
* Convert the input string to kebab case.
|
|
31
19
|
* @param input The input to convert.
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
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
|
+
|
|
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)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* simplify StringHelper signature ([0390403](https://github.com/twinfoundation/framework/commit/039040344952f91ee3c671249bc0e1c8f3b38e17))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Dependencies
|
|
29
|
+
|
|
30
|
+
* The following workspace dependencies were updated
|
|
31
|
+
* dependencies
|
|
32
|
+
* @twin.org/nameof bumped from 0.0.2-next.17 to 0.0.2-next.18
|
|
33
|
+
* devDependencies
|
|
34
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.17 to 0.0.2-next.18
|
|
35
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.17 to 0.0.2-next.18
|
|
36
|
+
|
|
3
37
|
## [0.0.2-next.17](https://github.com/twinfoundation/framework/compare/core-v0.0.2-next.16...core-v0.0.2-next.17) (2025-09-29)
|
|
4
38
|
|
|
5
39
|
|
|
@@ -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`
|
|
@@ -16,107 +16,45 @@ Class to help with string.
|
|
|
16
16
|
|
|
17
17
|
### trimTrailingSlashes()
|
|
18
18
|
|
|
19
|
-
Implementation signature for trimTrailingSlashes.
|
|
20
|
-
|
|
21
|
-
#### Param
|
|
22
|
-
|
|
23
|
-
The value to trim.
|
|
24
|
-
|
|
25
|
-
#### Call Signature
|
|
26
|
-
|
|
27
19
|
> `static` **trimTrailingSlashes**(`value`): `string`
|
|
28
20
|
|
|
29
|
-
|
|
30
|
-
Overloads preserve null/undefined instead of coercing to empty string.
|
|
21
|
+
Implementation signature for trimTrailingSlashes.
|
|
31
22
|
|
|
32
|
-
|
|
23
|
+
#### Parameters
|
|
33
24
|
|
|
34
|
-
|
|
25
|
+
##### value
|
|
35
26
|
|
|
36
27
|
`string`
|
|
37
28
|
|
|
38
29
|
The value to trim.
|
|
39
30
|
|
|
40
|
-
|
|
31
|
+
#### Returns
|
|
41
32
|
|
|
42
33
|
`string`
|
|
43
34
|
|
|
44
|
-
The trimmed
|
|
45
|
-
|
|
46
|
-
#### Call Signature
|
|
47
|
-
|
|
48
|
-
> `static` **trimTrailingSlashes**\<`T`\>(`value`): `T`
|
|
49
|
-
|
|
50
|
-
##### Type Parameters
|
|
51
|
-
|
|
52
|
-
###### T
|
|
53
|
-
|
|
54
|
-
`T` *extends* `undefined` \| `null`
|
|
55
|
-
|
|
56
|
-
##### Parameters
|
|
57
|
-
|
|
58
|
-
###### value
|
|
59
|
-
|
|
60
|
-
`T`
|
|
61
|
-
|
|
62
|
-
##### Returns
|
|
63
|
-
|
|
64
|
-
`T`
|
|
35
|
+
The trimmed string or the original.
|
|
65
36
|
|
|
66
37
|
***
|
|
67
38
|
|
|
68
39
|
### trimLeadingSlashes()
|
|
69
40
|
|
|
70
|
-
Implementation signature for trimLeadingSlashes.
|
|
71
|
-
|
|
72
|
-
#### Param
|
|
73
|
-
|
|
74
|
-
The value to trim.
|
|
75
|
-
|
|
76
|
-
#### Call Signature
|
|
77
|
-
|
|
78
41
|
> `static` **trimLeadingSlashes**(`value`): `string`
|
|
79
42
|
|
|
80
|
-
|
|
81
|
-
Overloads preserve null/undefined instead of coercing to empty string.
|
|
43
|
+
Implementation signature for trimLeadingSlashes.
|
|
82
44
|
|
|
83
|
-
|
|
45
|
+
#### Parameters
|
|
84
46
|
|
|
85
|
-
|
|
47
|
+
##### value
|
|
86
48
|
|
|
87
49
|
`string`
|
|
88
50
|
|
|
89
51
|
The value to trim.
|
|
90
52
|
|
|
91
|
-
|
|
53
|
+
#### Returns
|
|
92
54
|
|
|
93
55
|
`string`
|
|
94
56
|
|
|
95
|
-
The trimmed
|
|
96
|
-
|
|
97
|
-
#### Call Signature
|
|
98
|
-
|
|
99
|
-
> `static` **trimLeadingSlashes**\<`T`\>(`value`): `T`
|
|
100
|
-
|
|
101
|
-
Overload for null/undefined passthrough.
|
|
102
|
-
|
|
103
|
-
##### Type Parameters
|
|
104
|
-
|
|
105
|
-
###### T
|
|
106
|
-
|
|
107
|
-
`T` *extends* `undefined` \| `null`
|
|
108
|
-
|
|
109
|
-
##### Parameters
|
|
110
|
-
|
|
111
|
-
###### value
|
|
112
|
-
|
|
113
|
-
`T`
|
|
114
|
-
|
|
115
|
-
The null or undefined value.
|
|
116
|
-
|
|
117
|
-
##### Returns
|
|
118
|
-
|
|
119
|
-
`T`
|
|
57
|
+
The trimmed string or the original.
|
|
120
58
|
|
|
121
59
|
***
|
|
122
60
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/core",
|
|
3
|
-
"version": "0.0.2-next.
|
|
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.
|
|
17
|
+
"@twin.org/nameof": "0.0.2-next.19",
|
|
18
18
|
"intl-messageformat": "10.7.16",
|
|
19
19
|
"rfc6902": "5.1.2"
|
|
20
20
|
},
|