mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-10-12 01:18:10 +03:00
19 lines
567 B
TypeScript
19 lines
567 B
TypeScript
import {encodeAccessCode} from "./card-encoding";
|
|
|
|
export const CARD_ID_REGEX = /^(?:[0-9]{4} ?){5}$/i;
|
|
export const AMNET_COMPANY_ID = 597;
|
|
|
|
export function generateCardNumber(): string {
|
|
// serial between 5000 and 99999999999
|
|
const serial = Math.floor(Math.random() * 99999994999) + 5000;
|
|
return encodeAccessCode(AMNET_COMPANY_ID, serial, 0);
|
|
}
|
|
|
|
/**
|
|
* Validates the provided card id by known parameters
|
|
* @param id The card id to validate
|
|
*/
|
|
export function validateCardId(id: string): boolean {
|
|
return id[0] !== '3' && CARD_ID_REGEX.test(id);
|
|
}
|