arabicfmt
Version:
Arabic-first formatting for numbers, currency, dates and bidirectional text across all 22 Arab League countries — with correct handling of the 2025–2026 Unicode currency-symbol transition (Saudi Riyal U+20C1, UAE Dirham U+20C3, Omani Rial U+20C4).
27 lines (25 loc) • 732 B
JavaScript
// src/number/numerals.ts
var cc = String.fromCharCode;
var ARABIC_INDIC_DIGITS = Array.from(
{ length: 10 },
(_, i) => cc(1632 + i)
);
var EXTENDED_ARABIC_INDIC_DIGITS = Array.from(
{ length: 10 },
(_, i) => cc(1776 + i)
);
function toArabicDigits(input) {
return input.replace(/[0-9]/g, (d) => ARABIC_INDIC_DIGITS[Number(d)]);
}
var EASTERN_DIGITS = new RegExp(
`[${cc(1632)}-${cc(1641)}${cc(1776)}-${cc(1785)}]`,
"g"
);
function toLatinDigits(input) {
return input.replace(EASTERN_DIGITS, (ch) => {
const code = ch.charCodeAt(0);
const base = code >= 1776 ? 1776 : 1632;
return String(code - base);
});
}
export { ARABIC_INDIC_DIGITS, EXTENDED_ARABIC_INDIC_DIGITS, toArabicDigits, toLatinDigits };