@twin.org/core 0.0.1-next.32 → 0.0.1-next.34

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.
@@ -3412,6 +3412,32 @@ class RandomHelper {
3412
3412
  }
3413
3413
  }
3414
3414
 
3415
+ // Copyright 2024 IOTA Stiftung.
3416
+ // SPDX-License-Identifier: Apache-2.0.
3417
+ /**
3418
+ * Class to help with uint8 arrays.
3419
+ */
3420
+ class Uint8ArrayHelper {
3421
+ /**
3422
+ * Concatenate multiple arrays.
3423
+ * @param arrays The array to concatenate.
3424
+ * @returns The combined array.
3425
+ */
3426
+ static concat(arrays) {
3427
+ let totalLength = 0;
3428
+ for (const array of arrays) {
3429
+ totalLength += array.length;
3430
+ }
3431
+ const concatBytes = new Uint8Array(totalLength);
3432
+ let offset = 0;
3433
+ for (const array of arrays) {
3434
+ concatBytes.set(array, offset);
3435
+ offset += array.length;
3436
+ }
3437
+ return concatBytes;
3438
+ }
3439
+ }
3440
+
3415
3441
  // Copyright 2024 IOTA Stiftung.
3416
3442
  // SPDX-License-Identifier: Apache-2.0.
3417
3443
  /**
@@ -3962,11 +3988,10 @@ class Compression {
3962
3988
  Guards.uint8Array(Compression._CLASS_NAME, "bytes", bytes);
3963
3989
  Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
3964
3990
  const blob = new Blob([bytes]);
3965
- const ds = new CompressionStream(type);
3966
- const compressedStream = blob.stream().pipeThrough(ds);
3967
- const compressedBlob = await new Response(compressedStream).blob();
3968
- const ab = await compressedBlob.arrayBuffer();
3969
- const compressedBytes = new Uint8Array(ab);
3991
+ const compressionStream = new CompressionStream(type);
3992
+ const compressionPipe = blob.stream().pipeThrough(compressionStream);
3993
+ const compressedBlob = await new Response(compressionPipe).blob();
3994
+ const compressedBytes = await compressedBlob.bytes();
3970
3995
  // GZIP header contains a byte which specifies the OS the
3971
3996
  // compression was performed on. We set this to 3 (Unix) to ensure
3972
3997
  // that we produce consistent results.
@@ -3985,11 +4010,10 @@ class Compression {
3985
4010
  Guards.uint8Array(Compression._CLASS_NAME, "compressedBytes", compressedBytes);
3986
4011
  Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
3987
4012
  const blob = new Blob([compressedBytes]);
3988
- const ds = new DecompressionStream(type);
3989
- const decompressedStream = blob.stream().pipeThrough(ds);
3990
- const decompressedBlob = await new Response(decompressedStream).blob();
3991
- const ab = await decompressedBlob.arrayBuffer();
3992
- return new Uint8Array(ab);
4013
+ const decompressionStream = new DecompressionStream(type);
4014
+ const decompressionPipe = blob.stream().pipeThrough(decompressionStream);
4015
+ const decompressedBlob = await new Response(decompressionPipe).blob();
4016
+ return decompressedBlob.bytes();
3993
4017
  }
3994
4018
  }
3995
4019
 
@@ -4799,6 +4823,7 @@ exports.NotSupportedError = NotSupportedError;
4799
4823
  exports.ObjectHelper = ObjectHelper;
4800
4824
  exports.RandomHelper = RandomHelper;
4801
4825
  exports.StringHelper = StringHelper;
4826
+ exports.Uint8ArrayHelper = Uint8ArrayHelper;
4802
4827
  exports.UnauthorizedError = UnauthorizedError;
4803
4828
  exports.UnprocessableError = UnprocessableError;
4804
4829
  exports.Url = Url;
@@ -3410,6 +3410,32 @@ class RandomHelper {
3410
3410
  }
3411
3411
  }
3412
3412
 
3413
+ // Copyright 2024 IOTA Stiftung.
3414
+ // SPDX-License-Identifier: Apache-2.0.
3415
+ /**
3416
+ * Class to help with uint8 arrays.
3417
+ */
3418
+ class Uint8ArrayHelper {
3419
+ /**
3420
+ * Concatenate multiple arrays.
3421
+ * @param arrays The array to concatenate.
3422
+ * @returns The combined array.
3423
+ */
3424
+ static concat(arrays) {
3425
+ let totalLength = 0;
3426
+ for (const array of arrays) {
3427
+ totalLength += array.length;
3428
+ }
3429
+ const concatBytes = new Uint8Array(totalLength);
3430
+ let offset = 0;
3431
+ for (const array of arrays) {
3432
+ concatBytes.set(array, offset);
3433
+ offset += array.length;
3434
+ }
3435
+ return concatBytes;
3436
+ }
3437
+ }
3438
+
3413
3439
  // Copyright 2024 IOTA Stiftung.
3414
3440
  // SPDX-License-Identifier: Apache-2.0.
3415
3441
  /**
@@ -3960,11 +3986,10 @@ class Compression {
3960
3986
  Guards.uint8Array(Compression._CLASS_NAME, "bytes", bytes);
3961
3987
  Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
3962
3988
  const blob = new Blob([bytes]);
3963
- const ds = new CompressionStream(type);
3964
- const compressedStream = blob.stream().pipeThrough(ds);
3965
- const compressedBlob = await new Response(compressedStream).blob();
3966
- const ab = await compressedBlob.arrayBuffer();
3967
- const compressedBytes = new Uint8Array(ab);
3989
+ const compressionStream = new CompressionStream(type);
3990
+ const compressionPipe = blob.stream().pipeThrough(compressionStream);
3991
+ const compressedBlob = await new Response(compressionPipe).blob();
3992
+ const compressedBytes = await compressedBlob.bytes();
3968
3993
  // GZIP header contains a byte which specifies the OS the
3969
3994
  // compression was performed on. We set this to 3 (Unix) to ensure
3970
3995
  // that we produce consistent results.
@@ -3983,11 +4008,10 @@ class Compression {
3983
4008
  Guards.uint8Array(Compression._CLASS_NAME, "compressedBytes", compressedBytes);
3984
4009
  Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
3985
4010
  const blob = new Blob([compressedBytes]);
3986
- const ds = new DecompressionStream(type);
3987
- const decompressedStream = blob.stream().pipeThrough(ds);
3988
- const decompressedBlob = await new Response(decompressedStream).blob();
3989
- const ab = await decompressedBlob.arrayBuffer();
3990
- return new Uint8Array(ab);
4011
+ const decompressionStream = new DecompressionStream(type);
4012
+ const decompressionPipe = blob.stream().pipeThrough(decompressionStream);
4013
+ const decompressedBlob = await new Response(decompressionPipe).blob();
4014
+ return decompressedBlob.bytes();
3991
4015
  }
3992
4016
  }
3993
4017
 
@@ -4764,4 +4788,4 @@ class Validation {
4764
4788
  }
4765
4789
  }
4766
4790
 
4767
- export { AlreadyExistsError, ArrayHelper, AsyncCache, Base32, Base58, Base64, Base64Url, BaseError, BitString, Coerce, CoerceType, ComponentFactory, Compression, CompressionType, ConflictError, Converter, EnvHelper, ErrorHelper, Factory, FilenameHelper, GeneralError, GuardError, Guards, HexHelper, I18n, Is, JsonHelper, NotFoundError, NotImplementedError, NotSupportedError, ObjectHelper, RandomHelper, StringHelper, UnauthorizedError, UnprocessableError, Url, Urn, Validation, ValidationError };
4791
+ export { AlreadyExistsError, ArrayHelper, AsyncCache, Base32, Base58, Base64, Base64Url, BaseError, BitString, Coerce, CoerceType, ComponentFactory, Compression, CompressionType, ConflictError, Converter, EnvHelper, ErrorHelper, Factory, FilenameHelper, GeneralError, GuardError, Guards, HexHelper, I18n, Is, JsonHelper, NotFoundError, NotImplementedError, NotSupportedError, ObjectHelper, RandomHelper, StringHelper, Uint8ArrayHelper, UnauthorizedError, UnprocessableError, Url, Urn, Validation, ValidationError };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Class to help with uint8 arrays.
3
+ */
4
+ export declare class Uint8ArrayHelper {
5
+ /**
6
+ * Concatenate multiple arrays.
7
+ * @param arrays The array to concatenate.
8
+ * @returns The combined array.
9
+ */
10
+ static concat(arrays: Uint8Array[]): Uint8Array;
11
+ }
@@ -24,6 +24,7 @@ export * from "./helpers/jsonHelper";
24
24
  export * from "./helpers/objectHelper";
25
25
  export * from "./helpers/randomHelper";
26
26
  export * from "./helpers/stringHelper";
27
+ export * from "./helpers/uint8ArrayHelper";
27
28
  export * from "./models/coerceType";
28
29
  export * from "./models/compressionType";
29
30
  export * from "./models/IComponent";
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/core - Changelog
2
2
 
3
- ## 0.0.1-next.32
3
+ ## 0.0.1-next.34
4
4
 
5
5
  - Initial Release
@@ -0,0 +1,35 @@
1
+ # Class: Uint8ArrayHelper
2
+
3
+ Class to help with uint8 arrays.
4
+
5
+ ## Constructors
6
+
7
+ ### new Uint8ArrayHelper()
8
+
9
+ > **new Uint8ArrayHelper**(): [`Uint8ArrayHelper`](Uint8ArrayHelper.md)
10
+
11
+ #### Returns
12
+
13
+ [`Uint8ArrayHelper`](Uint8ArrayHelper.md)
14
+
15
+ ## Methods
16
+
17
+ ### concat()
18
+
19
+ > `static` **concat**(`arrays`): `Uint8Array`
20
+
21
+ Concatenate multiple arrays.
22
+
23
+ #### Parameters
24
+
25
+ ##### arrays
26
+
27
+ `Uint8Array`[]
28
+
29
+ The array to concatenate.
30
+
31
+ #### Returns
32
+
33
+ `Uint8Array`
34
+
35
+ The combined array.
@@ -27,6 +27,7 @@
27
27
  - [ObjectHelper](classes/ObjectHelper.md)
28
28
  - [RandomHelper](classes/RandomHelper.md)
29
29
  - [StringHelper](classes/StringHelper.md)
30
+ - [Uint8ArrayHelper](classes/Uint8ArrayHelper.md)
30
31
  - [BitString](classes/BitString.md)
31
32
  - [Url](classes/Url.md)
32
33
  - [Urn](classes/Urn.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/core",
3
- "version": "0.0.1-next.32",
3
+ "version": "0.0.1-next.34",
4
4
  "description": "Helper methods/classes for data type checking/validation/guarding/error handling",
5
5
  "repository": {
6
6
  "type": "git",