From ff4bf49cee5476ee159a38375104b82c44f24dda Mon Sep 17 00:00:00 2001 From: danbulant Date: Sun, 16 Feb 2020 17:48:23 +0100 Subject: [PATCH] Define UUID --- client/src/defs/uuid.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 client/src/defs/uuid.ts diff --git a/client/src/defs/uuid.ts b/client/src/defs/uuid.ts new file mode 100644 index 0000000..b025f9f --- /dev/null +++ b/client/src/defs/uuid.ts @@ -0,0 +1,20 @@ +import {InvalidUUID} from '../errors/index'; + +export default class UUID { + constructor(private content:string){ + this.update(content); + } + update(content: string){ + if (/[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}/.test(content)){ + this.content = content; + return; + } + throw new InvalidUUID(); + } + toString(){ + return this.content as string; + } + toNumber(){ + throw new Error("Cannot convert UUID to INT"); + } +} \ No newline at end of file