@twin.org/core 0.0.1-next.54 → 0.0.1-next.56

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.
@@ -2120,8 +2120,6 @@ class Factory {
2120
2120
  // eslint-disable-next-line @typescript-eslint/naming-convention
2121
2121
  const ComponentFactory = Factory.createFactory("component");
2122
2122
 
2123
- // Copyright 2024 IOTA Stiftung.
2124
- // SPDX-License-Identifier: Apache-2.0.
2125
2123
  /**
2126
2124
  * Class to help with arrays.
2127
2125
  */
@@ -2149,6 +2147,20 @@ class ArrayHelper {
2149
2147
  }
2150
2148
  return true;
2151
2149
  }
2150
+ /**
2151
+ * Convert an object or array to an array.
2152
+ * @param value The object or array to convert.
2153
+ * @returns The array.
2154
+ */
2155
+ static fromObjectOrArray(value) {
2156
+ if (Is.empty(value)) {
2157
+ return undefined;
2158
+ }
2159
+ if (Is.array(value)) {
2160
+ return value;
2161
+ }
2162
+ return [value];
2163
+ }
2152
2164
  }
2153
2165
 
2154
2166
  // Copyright 2024 IOTA Stiftung.
@@ -2118,8 +2118,6 @@ class Factory {
2118
2118
  // eslint-disable-next-line @typescript-eslint/naming-convention
2119
2119
  const ComponentFactory = Factory.createFactory("component");
2120
2120
 
2121
- // Copyright 2024 IOTA Stiftung.
2122
- // SPDX-License-Identifier: Apache-2.0.
2123
2121
  /**
2124
2122
  * Class to help with arrays.
2125
2123
  */
@@ -2147,6 +2145,20 @@ class ArrayHelper {
2147
2145
  }
2148
2146
  return true;
2149
2147
  }
2148
+ /**
2149
+ * Convert an object or array to an array.
2150
+ * @param value The object or array to convert.
2151
+ * @returns The array.
2152
+ */
2153
+ static fromObjectOrArray(value) {
2154
+ if (Is.empty(value)) {
2155
+ return undefined;
2156
+ }
2157
+ if (Is.array(value)) {
2158
+ return value;
2159
+ }
2160
+ return [value];
2161
+ }
2150
2162
  }
2151
2163
 
2152
2164
  // Copyright 2024 IOTA Stiftung.
@@ -1,3 +1,4 @@
1
+ import type { ObjectOrArray } from "../models/objectOrArray";
1
2
  /**
2
3
  * Class to help with arrays.
3
4
  */
@@ -9,4 +10,16 @@ export declare class ArrayHelper {
9
10
  * @returns True if both arrays are empty of have the same values.
10
11
  */
11
12
  static matches(arr1: unknown, arr2: unknown): boolean;
13
+ /**
14
+ * Convert an object or array to an array.
15
+ * @param value The object or array to convert.
16
+ * @returns The array.
17
+ */
18
+ static fromObjectOrArray<T = unknown>(value: undefined): undefined;
19
+ /**
20
+ * Convert an object or array to an array.
21
+ * @param value The object or array to convert.
22
+ * @returns The array.
23
+ */
24
+ static fromObjectOrArray<T = unknown>(value: ObjectOrArray<T>): T[];
12
25
  }
@@ -38,6 +38,7 @@ export * from "./models/ILocalesIndex";
38
38
  export * from "./models/IPatchOperation";
39
39
  export * from "./models/IUrlParts";
40
40
  export * from "./models/IValidationFailure";
41
+ export * from "./models/objectOrArray";
41
42
  export * from "./types/bitString";
42
43
  export * from "./types/url";
43
44
  export * from "./types/urn";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Object or array data type
3
+ */
4
+ export type ObjectOrArray<T = unknown> = T | T[];
package/docs/changelog.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @twin.org/core - Changelog
2
2
 
3
+ ## [0.0.1-next.56](https://github.com/twinfoundation/framework/compare/core-v0.0.1-next.55...core-v0.0.1-next.56) (2025-05-08)
4
+
5
+
6
+ ### Features
7
+
8
+ * add ObjectOrArray and ArrayHelper methods ([0ac9077](https://github.com/twinfoundation/framework/commit/0ac907764d64b38ad1b04b0e9c3027055b527559))
9
+
10
+ ## [0.0.1-next.55](https://github.com/twinfoundation/framework/compare/core-v0.0.1-next.54...core-v0.0.1-next.55) (2025-05-07)
11
+
12
+
13
+ ### Miscellaneous Chores
14
+
15
+ * **core:** Synchronize repo versions
16
+
3
17
  ## [0.0.1-next.54](https://github.com/twinfoundation/framework/compare/core-v0.0.1-next.53...core-v0.0.1-next.54) (2025-05-06)
4
18
 
5
19
 
@@ -39,3 +39,73 @@ The second array.
39
39
  `boolean`
40
40
 
41
41
  True if both arrays are empty of have the same values.
42
+
43
+ ***
44
+
45
+ ### fromObjectOrArray()
46
+
47
+ Convert an object or array to an array.
48
+
49
+ #### Param
50
+
51
+ The object or array to convert.
52
+
53
+ #### Call Signature
54
+
55
+ > `static` **fromObjectOrArray**\<`T`\>(`value`): `undefined`
56
+
57
+ Convert an object or array to an array.
58
+
59
+ ##### Type Parameters
60
+
61
+ ###### T
62
+
63
+ `T` = `unknown`
64
+
65
+ ##### Parameters
66
+
67
+ ###### value
68
+
69
+ `undefined`
70
+
71
+ The object or array to convert.
72
+
73
+ ##### Returns
74
+
75
+ `undefined`
76
+
77
+ The array.
78
+
79
+ ##### Param
80
+
81
+ The object or array to convert.
82
+
83
+ #### Call Signature
84
+
85
+ > `static` **fromObjectOrArray**\<`T`\>(`value`): `T`[]
86
+
87
+ Convert an object or array to an array.
88
+
89
+ ##### Type Parameters
90
+
91
+ ###### T
92
+
93
+ `T` = `unknown`
94
+
95
+ ##### Parameters
96
+
97
+ ###### value
98
+
99
+ [`ObjectOrArray`](../type-aliases/ObjectOrArray.md)\<`T`\>
100
+
101
+ The object or array to convert.
102
+
103
+ ##### Returns
104
+
105
+ `T`[]
106
+
107
+ The array.
108
+
109
+ ##### Param
110
+
111
+ The object or array to convert.
@@ -59,6 +59,7 @@
59
59
 
60
60
  - [CoerceType](type-aliases/CoerceType.md)
61
61
  - [CompressionType](type-aliases/CompressionType.md)
62
+ - [ObjectOrArray](type-aliases/ObjectOrArray.md)
62
63
 
63
64
  ## Variables
64
65
 
@@ -0,0 +1,11 @@
1
+ # Type Alias: ObjectOrArray\<T\>
2
+
3
+ > **ObjectOrArray**\<`T`\> = `T` \| `T`[]
4
+
5
+ Object or array data type
6
+
7
+ ## Type Parameters
8
+
9
+ ### T
10
+
11
+ `T` = `unknown`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/core",
3
- "version": "0.0.1-next.54",
3
+ "version": "0.0.1-next.56",
4
4
  "description": "Helper methods/classes for data type checking/validation/guarding/error handling",
5
5
  "repository": {
6
6
  "type": "git",