feat:#4 extracted token regex test

This commit is contained in:
Elmar Kresse
2024-05-20 13:41:16 +02:00
parent eb21c22d17
commit 1f1d5300e2
2 changed files with 20 additions and 20 deletions

View File

@@ -0,0 +1,19 @@
const tokenRegex = /^[a-z0-9]{15}$/;
const tokenUriRegex = /[?&]token=([a-z0-9]{15})(?:&|$)/;
export const isToken = (token: string): boolean => {
return tokenRegex.test(token) || tokenUriRegex.test(token);
};
export function extractToken(token: string): string {
if (tokenRegex.test(token)) {
return token;
}
const match = tokenUriRegex.exec(token);
if (match) {
return match[1];
}
throw new Error("Invalid token");
}