mirror of
https://github.com/Chewbaccalakis/rfid-database.git
synced 2026-09-10 00:11:56 -07:00
Add Next.js app with SQLite/Drizzle storage for sites and LF/HF tag dumps, multi-user Auth.js (credentials + optional OIDC), personal API tokens in Settings, versioned /api/v1 for UI and future CLI use, MCT/Proxmark/JSON import-export, PWA offline shell, Vitest tests, and GitHub Actions CI.
28 lines
792 B
TypeScript
28 lines
792 B
TypeScript
/**
|
|
* Normalize RFID UIDs to uppercase hex without separators.
|
|
* Accepts common forms: "04:A1:B2:C3", "04 A1 B2 C3", "04a1b2c3".
|
|
*/
|
|
export function normalizeUid(input: string): string {
|
|
const cleaned = input.replace(/[^0-9a-fA-F]/g, "").toUpperCase();
|
|
if (cleaned.length < 4 || cleaned.length % 2 !== 0) {
|
|
throw new Error(
|
|
`Invalid UID "${input}": expected even-length hex of at least 2 bytes`
|
|
);
|
|
}
|
|
return cleaned;
|
|
}
|
|
|
|
/** Display form with colon separators: 04:A1:B2:C3 */
|
|
export function formatUid(uid: string): string {
|
|
const normalized = normalizeUid(uid);
|
|
return normalized.match(/.{1,2}/g)?.join(":") ?? normalized;
|
|
}
|
|
|
|
export function tryNormalizeUid(input: string): string | null {
|
|
try {
|
|
return normalizeUid(input);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|