token.ts (427B)
1 import { TOKEN_REGEX } from "#core/domain/constants.ts"; 2 import { DomainError } from "#core/domain/error.ts"; 3 4 export class Token { 5 constructor(readonly value: string) { 6 if (!TOKEN_REGEX.test(value)) { 7 throw new InvalidToken(value); 8 } 9 } 10 11 toString() { 12 return this.value; 13 } 14 } 15 16 export class InvalidToken extends DomainError { 17 constructor(readonly candidate: string) { 18 super("Invalid token"); 19 } 20 }