Define UUID

This commit is contained in:
danbulant 2020-02-16 17:48:23 +01:00
parent 59d0ca8ec1
commit ff4bf49cee

20
client/src/defs/uuid.ts Normal file
View file

@ -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");
}
}