diff --git a/aimenet-web/lib/aime-card.ts b/aimenet-web/lib/aime-card.ts new file mode 100644 index 0000000..0e24ba6 --- /dev/null +++ b/aimenet-web/lib/aime-card.ts @@ -0,0 +1,20 @@ +/** + * Generates a random Aime card id. + */ +export function generateAimeCardId(): string { + let id: string; + + do { + id = Math.floor(Math.random() * 1e20).toString().padStart(20, '0'); + } while (id[0] === '3'); // https://gitea.tendokyu.moe/Dniel97/segatools/src/commit/37c26ecadb2ce4d2cb3a61ce96c2c931ba2fc346/aimeio/aimeio.c#L191 + + return id; +} + +/** + * Validates the provided card id by known parameters + * @param id The card id to validate + */ +export function validateAimeCardId(id: string): boolean { + return id[0] !== '3' && /^[0-9A-F]{20}$/i.test(id); +} \ No newline at end of file