@twin.org/core 0.0.1-next.26 → 0.0.1-next.27
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 +31 -0
- package/dist/esm/index.mjs +31 -0
- package/dist/types/utils/coerce.d.ts +14 -0
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/Coerce.md +52 -0
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -3009,6 +3009,18 @@ class Coerce {
|
|
|
3009
3009
|
return value.getTime();
|
|
3010
3010
|
}
|
|
3011
3011
|
}
|
|
3012
|
+
/**
|
|
3013
|
+
* Coerce the value to an integer.
|
|
3014
|
+
* @param value The value to coerce.
|
|
3015
|
+
* @throws TypeError If the value can not be coerced.
|
|
3016
|
+
* @returns The value if it can be coerced.
|
|
3017
|
+
*/
|
|
3018
|
+
static integer(value) {
|
|
3019
|
+
const num = Coerce.number(value);
|
|
3020
|
+
if (!Is.undefined(num)) {
|
|
3021
|
+
return Math.trunc(num);
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3012
3024
|
/**
|
|
3013
3025
|
* Coerce the value to a bigint.
|
|
3014
3026
|
* @param value The value to coerce.
|
|
@@ -3155,6 +3167,25 @@ class Coerce {
|
|
|
3155
3167
|
catch { }
|
|
3156
3168
|
}
|
|
3157
3169
|
}
|
|
3170
|
+
/**
|
|
3171
|
+
* Coerce the value to a Uint8Array.
|
|
3172
|
+
* @param value The value to coerce.
|
|
3173
|
+
* @throws TypeError If the value can not be coerced.
|
|
3174
|
+
* @returns The value if it can be coerced.
|
|
3175
|
+
*/
|
|
3176
|
+
static uint8Array(value) {
|
|
3177
|
+
if (Is.undefined(value)) {
|
|
3178
|
+
return value;
|
|
3179
|
+
}
|
|
3180
|
+
if (Is.string(value)) {
|
|
3181
|
+
if (Is.stringHex(value.toLowerCase(), true)) {
|
|
3182
|
+
return Converter.hexToBytes(value.toLowerCase());
|
|
3183
|
+
}
|
|
3184
|
+
if (Is.stringBase64(value)) {
|
|
3185
|
+
return Converter.base64ToBytes(value);
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3158
3189
|
}
|
|
3159
3190
|
|
|
3160
3191
|
// Copyright 2024 IOTA Stiftung.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -3007,6 +3007,18 @@ class Coerce {
|
|
|
3007
3007
|
return value.getTime();
|
|
3008
3008
|
}
|
|
3009
3009
|
}
|
|
3010
|
+
/**
|
|
3011
|
+
* Coerce the value to an integer.
|
|
3012
|
+
* @param value The value to coerce.
|
|
3013
|
+
* @throws TypeError If the value can not be coerced.
|
|
3014
|
+
* @returns The value if it can be coerced.
|
|
3015
|
+
*/
|
|
3016
|
+
static integer(value) {
|
|
3017
|
+
const num = Coerce.number(value);
|
|
3018
|
+
if (!Is.undefined(num)) {
|
|
3019
|
+
return Math.trunc(num);
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3010
3022
|
/**
|
|
3011
3023
|
* Coerce the value to a bigint.
|
|
3012
3024
|
* @param value The value to coerce.
|
|
@@ -3153,6 +3165,25 @@ class Coerce {
|
|
|
3153
3165
|
catch { }
|
|
3154
3166
|
}
|
|
3155
3167
|
}
|
|
3168
|
+
/**
|
|
3169
|
+
* Coerce the value to a Uint8Array.
|
|
3170
|
+
* @param value The value to coerce.
|
|
3171
|
+
* @throws TypeError If the value can not be coerced.
|
|
3172
|
+
* @returns The value if it can be coerced.
|
|
3173
|
+
*/
|
|
3174
|
+
static uint8Array(value) {
|
|
3175
|
+
if (Is.undefined(value)) {
|
|
3176
|
+
return value;
|
|
3177
|
+
}
|
|
3178
|
+
if (Is.string(value)) {
|
|
3179
|
+
if (Is.stringHex(value.toLowerCase(), true)) {
|
|
3180
|
+
return Converter.hexToBytes(value.toLowerCase());
|
|
3181
|
+
}
|
|
3182
|
+
if (Is.stringBase64(value)) {
|
|
3183
|
+
return Converter.base64ToBytes(value);
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
3186
|
+
}
|
|
3156
3187
|
}
|
|
3157
3188
|
|
|
3158
3189
|
// Copyright 2024 IOTA Stiftung.
|
|
@@ -16,6 +16,13 @@ export declare class Coerce {
|
|
|
16
16
|
* @returns The value if it can be coerced.
|
|
17
17
|
*/
|
|
18
18
|
static number(value: unknown): number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Coerce the value to an integer.
|
|
21
|
+
* @param value The value to coerce.
|
|
22
|
+
* @throws TypeError If the value can not be coerced.
|
|
23
|
+
* @returns The value if it can be coerced.
|
|
24
|
+
*/
|
|
25
|
+
static integer(value: unknown): number | undefined;
|
|
19
26
|
/**
|
|
20
27
|
* Coerce the value to a bigint.
|
|
21
28
|
* @param value The value to coerce.
|
|
@@ -58,4 +65,11 @@ export declare class Coerce {
|
|
|
58
65
|
* @returns The value if it can be coerced.
|
|
59
66
|
*/
|
|
60
67
|
static object<T = unknown>(value: unknown): T | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Coerce the value to a Uint8Array.
|
|
70
|
+
* @param value The value to coerce.
|
|
71
|
+
* @throws TypeError If the value can not be coerced.
|
|
72
|
+
* @returns The value if it can be coerced.
|
|
73
|
+
*/
|
|
74
|
+
static uint8Array(value: unknown): Uint8Array | undefined;
|
|
61
75
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -66,6 +66,32 @@ TypeError If the value can not be coerced.
|
|
|
66
66
|
|
|
67
67
|
***
|
|
68
68
|
|
|
69
|
+
### integer()
|
|
70
|
+
|
|
71
|
+
> `static` **integer**(`value`): `undefined` \| `number`
|
|
72
|
+
|
|
73
|
+
Coerce the value to an integer.
|
|
74
|
+
|
|
75
|
+
#### Parameters
|
|
76
|
+
|
|
77
|
+
##### value
|
|
78
|
+
|
|
79
|
+
`unknown`
|
|
80
|
+
|
|
81
|
+
The value to coerce.
|
|
82
|
+
|
|
83
|
+
#### Returns
|
|
84
|
+
|
|
85
|
+
`undefined` \| `number`
|
|
86
|
+
|
|
87
|
+
The value if it can be coerced.
|
|
88
|
+
|
|
89
|
+
#### Throws
|
|
90
|
+
|
|
91
|
+
TypeError If the value can not be coerced.
|
|
92
|
+
|
|
93
|
+
***
|
|
94
|
+
|
|
69
95
|
### bigint()
|
|
70
96
|
|
|
71
97
|
> `static` **bigint**(`value`): `undefined` \| `bigint`
|
|
@@ -223,3 +249,29 @@ The value if it can be coerced.
|
|
|
223
249
|
#### Throws
|
|
224
250
|
|
|
225
251
|
TypeError If the value can not be coerced.
|
|
252
|
+
|
|
253
|
+
***
|
|
254
|
+
|
|
255
|
+
### uint8Array()
|
|
256
|
+
|
|
257
|
+
> `static` **uint8Array**(`value`): `undefined` \| `Uint8Array`
|
|
258
|
+
|
|
259
|
+
Coerce the value to a Uint8Array.
|
|
260
|
+
|
|
261
|
+
#### Parameters
|
|
262
|
+
|
|
263
|
+
##### value
|
|
264
|
+
|
|
265
|
+
`unknown`
|
|
266
|
+
|
|
267
|
+
The value to coerce.
|
|
268
|
+
|
|
269
|
+
#### Returns
|
|
270
|
+
|
|
271
|
+
`undefined` \| `Uint8Array`
|
|
272
|
+
|
|
273
|
+
The value if it can be coerced.
|
|
274
|
+
|
|
275
|
+
#### Throws
|
|
276
|
+
|
|
277
|
+
TypeError If the value can not be coerced.
|