utilium 2.0.0 → 2.1.0

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/string.d.ts CHANGED
@@ -17,3 +17,8 @@ export declare function encodeUTF8(input: string): Uint8Array;
17
17
  export declare function decodeUTF8(input?: Uint8Array): string;
18
18
  export declare function encodeASCII(input: string): Uint8Array;
19
19
  export declare function decodeASCII(input: Uint8Array): string;
20
+ export type UUID = `${string}-${string}-${string}-${string}-${string}`;
21
+ export declare function decodeUUID(uuid: Uint8Array): UUID;
22
+ export declare function encodeUUID(uuid: UUID): Uint8Array;
23
+ export declare function stringifyUUID(uuid: bigint): UUID;
24
+ export declare function parseUUID(uuid: UUID): bigint;
package/dist/string.js CHANGED
@@ -38,3 +38,24 @@ export function decodeASCII(input) {
38
38
  }
39
39
  return output;
40
40
  }
41
+ export function decodeUUID(uuid) {
42
+ const hex = Array.from(uuid)
43
+ .map(b => b.toString(16).padStart(2, '0'))
44
+ .join('');
45
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
46
+ }
47
+ export function encodeUUID(uuid) {
48
+ const hex = uuid.replace(/-/g, '');
49
+ const data = new Uint8Array(16);
50
+ for (let i = 0; i < 16; i++) {
51
+ data[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
52
+ }
53
+ return data;
54
+ }
55
+ export function stringifyUUID(uuid) {
56
+ const hex = uuid.toString(16).padStart(32, '0');
57
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
58
+ }
59
+ export function parseUUID(uuid) {
60
+ return BigInt(`0x${uuid.replace(/-/g, '')}`);
61
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Typescript utilities",
5
5
  "funding": {
6
6
  "type": "individual",