gdc-common-utils-ts 1.4.1 → 1.4.6
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/normalize-subject-uuid.d.ts +1 -0
- package/dist/utils/normalize-subject-uuid.js +24 -0
- package/dist/utils/normalize-uuid.d.ts +1 -0
- package/dist/utils/normalize-uuid.js +35 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeSubjectUuid(input: string | undefined): string | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Normalizes a subject identifier to a canonical UUID (hexadecimal, lowercase, no dashes)
|
|
2
|
+
// Accepts: urn:uuid:<uuid>, <ResourceType>/<uuid>, <uuid> (with or without dashes), base58 (optional)
|
|
3
|
+
// Returns: canonical hex string (no dashes, lowercase) or undefined if not valid
|
|
4
|
+
export function normalizeSubjectUuid(input) {
|
|
5
|
+
if (!input)
|
|
6
|
+
return undefined;
|
|
7
|
+
let s = String(input).trim();
|
|
8
|
+
// urn:uuid:<uuid>
|
|
9
|
+
if (s.startsWith('urn:uuid:'))
|
|
10
|
+
s = s.slice(9);
|
|
11
|
+
// <ResourceType>/<uuid>
|
|
12
|
+
const slashIdx = s.indexOf('/');
|
|
13
|
+
if (slashIdx >= 0)
|
|
14
|
+
s = s.slice(slashIdx + 1);
|
|
15
|
+
// Remove dashes
|
|
16
|
+
s = s.replace(/-/g, '');
|
|
17
|
+
// Lowercase
|
|
18
|
+
s = s.toLowerCase();
|
|
19
|
+
// Validate: must be 32 hex chars
|
|
20
|
+
if (/^[0-9a-f]{32}$/.test(s))
|
|
21
|
+
return s;
|
|
22
|
+
// Optionally: add base58 or other formats here
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeUuid(input: string | undefined): string | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Normalizes a subject identifier to a canonical UUID (hexadecimal, lowercase, no dashes)
|
|
2
|
+
// Accepts: urn:uuid:<uuid>, <ResourceType>/<uuid>, <uuid> (with or without dashes), base58 (optional)
|
|
3
|
+
// Returns: canonical hex string (no dashes, lowercase) or undefined if not valid
|
|
4
|
+
import { decodeMultibase58btcToHex } from './multibase58.js';
|
|
5
|
+
export function normalizeUuid(input) {
|
|
6
|
+
if (!input)
|
|
7
|
+
return undefined;
|
|
8
|
+
let s = String(input).trim();
|
|
9
|
+
// urn:uuid:<...>
|
|
10
|
+
if (s.startsWith('urn:uuid:'))
|
|
11
|
+
s = s.slice(9);
|
|
12
|
+
// <ResourceType>/<...>
|
|
13
|
+
const slashIdx = s.indexOf('/');
|
|
14
|
+
if (slashIdx >= 0)
|
|
15
|
+
s = s.slice(slashIdx + 1);
|
|
16
|
+
// Si es multibase58btc (z...)
|
|
17
|
+
if (s.startsWith('z')) {
|
|
18
|
+
try {
|
|
19
|
+
const hex = decodeMultibase58btcToHex(s);
|
|
20
|
+
if (/^[0-9a-f]{32}$/.test(hex))
|
|
21
|
+
return hex;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
// no válido, ignorar
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Remove dashes
|
|
28
|
+
s = s.replace(/-/g, '');
|
|
29
|
+
// Lowercase
|
|
30
|
+
s = s.toLowerCase();
|
|
31
|
+
// Validate: must be 32 hex chars
|
|
32
|
+
if (/^[0-9a-f]{32}$/.test(s))
|
|
33
|
+
return s;
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|