mirror of
https://github.com/danbulant/ester_os
synced 2026-06-14 03:41:07 +00:00
Define UUID
This commit is contained in:
parent
59d0ca8ec1
commit
ff4bf49cee
1 changed files with 20 additions and 0 deletions
20
client/src/defs/uuid.ts
Normal file
20
client/src/defs/uuid.ts
Normal 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");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue