1
0
Fork 0
fahrPool/web/lib/orte-fahrzeuge/fin.ts

25 lines
1.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// FIN nach ISO 3779: 17 Zeichen, Grossbuchstaben und Ziffern ohne I, O, Q.
// Gleiches Muster wie die DB-Constraints fahrzeuge_fin_format /
// auftraege_start_fin_format (Migration 20261009090000_fahrzeug_fin.sql).
const FIN_MUSTER = /^[A-HJ-NPR-Z0-9]{17}$/;
const FIN_ZEICHENFOLGEN = /[A-HJ-NPR-Z0-9]+/g;
export const FIN_FEHLER = "Die FIN muss 17 Zeichen lang sein (A–Z, 0–9, ohne I, O, Q).";
export function normalisiereFin(raw: string): string {
return raw.trim().toUpperCase();
}
export function istGueltigeFin(fin: string): boolean {
return FIN_MUSTER.test(fin);
}
// Barcode-Etiketten koennen Praefixe oder Zusatzdaten enthalten. Gesucht wird
// die erste zusammenhaengende Folge zulaessiger Zeichen mit GENAU 17 Zeichen;
// laengere Folgen werden verworfen statt abgeschnitten, um keine falsche FIN
// zu raten.
export function finAusScan(rawScan: string): string | null {
const folgen = rawScan.toUpperCase().match(FIN_ZEICHENFOLGEN) ?? [];
return folgen.find((folge) => folge.length === 17) ?? null;
}