idUtils: uuid underscore prefix stripping

This commit is contained in:
Enrico Ros
2025-10-03 16:33:07 -07:00
parent f5e34e8096
commit 39736fbd27
+13
View File
@@ -82,6 +82,19 @@ export function isValidUuidFast(value: string): boolean {
return value.length === 36 && value[8] === '-' && value[13] === '-' && value[18] === '-' && value[23] === '-';
}
/**
* Removes a legacy prefix (e.g., 'conv_', 'persona_') from a UUID-like string.
* Returns the UUID if valid after prefix removal, otherwise returns false.
*/
export function stripLegacyUuidPrefix(value: string): string | false {
if (!value) return false;
const uIdx = value.indexOf('_');
const candidate = uIdx > 0 ? value.slice(uIdx + 1) : value;
return isValidUuidFast(candidate) ? candidate : false;
}
/**
* Generates a UUID v4 using the Web Crypto API
* @returns A standard UUID v4 string (e.g., '123e4567-e89b-12d3-a456-426614174000')