guid.ts 832 B

1234567891011121314151617181920212223242526272829
  1. /***
  2. * @module node-opcua-guid
  3. */
  4. const regexGUID = /^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/;
  5. /**
  6. * checks if provided string is a valid Guid
  7. * a valid GUID has the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX
  8. * when X is a hexadecimal digit
  9. *
  10. * @method isValidGuid
  11. * @param guid - the GUID to test for validaty
  12. * @return - true if the string is a valid GUID.
  13. */
  14. export function isValidGuid(guid: string): boolean {
  15. return regexGUID.test(guid);
  16. }
  17. // 1 2 3
  18. // 012345678901234567890123456789012345
  19. export const emptyGuid = "00000000-0000-0000-0000-000000000000";
  20. export function normalizeGuid(guid: Guid |null | undefined): Guid {
  21. return guid ? guid.toUpperCase() : emptyGuid;
  22. }
  23. export type Guid = string;