Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

urn-uuid.ts 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { URISchemeHandler, URIComponents, URIOptions } from "../uri";
  2. import { URNComponents } from "./urn";
  3. import { SCHEMES } from "../uri";
  4. export interface UUIDComponents extends URNComponents {
  5. uuid?: string;
  6. }
  7. const UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
  8. const UUID_PARSE = /^[0-9A-Fa-f\-]{36}/;
  9. //RFC 4122
  10. const handler:URISchemeHandler<UUIDComponents, URIOptions, URNComponents> = {
  11. scheme : "urn:uuid",
  12. parse : function (urnComponents:URNComponents, options:URIOptions):UUIDComponents {
  13. const uuidComponents = urnComponents as UUIDComponents;
  14. uuidComponents.uuid = uuidComponents.nss;
  15. uuidComponents.nss = undefined;
  16. if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
  17. uuidComponents.error = uuidComponents.error || "UUID is not valid.";
  18. }
  19. return uuidComponents;
  20. },
  21. serialize : function (uuidComponents:UUIDComponents, options:URIOptions):URNComponents {
  22. const urnComponents = uuidComponents as URNComponents;
  23. //normalize UUID
  24. urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
  25. return urnComponents;
  26. },
  27. };
  28. export default handler;