mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-09-28 17:58:10 +03:00
32 lines
733 B
TypeScript
32 lines
733 B
TypeScript
export const CARD_ID_REGEX = /^(?:[0-9]{4} ?){5}$/i;
|
|
|
|
/**
|
|
* Generates a random Aime card id.
|
|
*/
|
|
export function generateAimeCardId(): string {
|
|
let cardId = '';
|
|
|
|
while (true) {
|
|
// don't start with a 3
|
|
const firstDigit = Math.floor(Math.random() * 10);
|
|
|
|
if (firstDigit !== 3) {
|
|
cardId = firstDigit.toString();
|
|
break;
|
|
}
|
|
}
|
|
|
|
for (let i = 0; i < 19; i++) {
|
|
cardId += Math.floor(Math.random() * 10).toString();
|
|
}
|
|
|
|
return cardId;
|
|
}
|
|
|
|
/**
|
|
* 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' && CARD_ID_REGEX.test(id);
|
|
} |