const PERSIAN_ZERO = 0x06f0;
const ARABIC_INDIC_ZERO = 0x0660;

/**
 * Normalise Persian and Arabic-Indic digits to ASCII. Non-digits pass through.
 *
 * Both blocks, not just the Persian one the frontend handles: ASR output can carry either,
 * sometimes mixed with ASCII in a single transcript.
 */
export function toLatinDigits(value: string): string {
  return value.replace(/[۰-۹٠-٩]/g, (ch) => {
    const code = ch.charCodeAt(0);
    const base = code >= PERSIAN_ZERO ? PERSIAN_ZERO : ARABIC_INDIC_ZERO;
    return String(code - base);
  });
}
