feat: remove token prefix util (#2191)

* feat: remove token prefix util

* fix: token substring

* fix: speed up unit tests
This commit is contained in:
Skillz4Killz
2022-05-08 11:34:33 -04:00
committed by GitHub
parent 602940e636
commit 8cb912730b
8 changed files with 75 additions and 50 deletions
+9
View File
@@ -0,0 +1,9 @@
/** Removes the Bot before the token. */
export function removeTokenPrefix(token?: string, type: "GATEWAY" | "REST" = "REST"): string {
// If no token is provided, throw an error
if (!token) throw new Error(`The ${type} was not given a token. Please provide a token and try again.`);
// If the token does not have a prefix just return token
if (!token.startsWith("Bot ")) return token;
// Remove the prefix and return only the token.
return token.substring(token.indexOf(" ") + 1);
}