10 lines
335 B
TypeScript
10 lines
335 B
TypeScript
const PERSIAN = '۰۱۲۳۴۵۶۷۸۹';
|
|
const ARABIC = '٠١٢٣٤٥٦٧٨٩';
|
|
export const normalizeDigits = (str: string) =>
|
|
str.replace(/[\u06F0-\u06F9\u0660-\u0669]/g, (d) => {
|
|
const iP = PERSIAN.indexOf(d);
|
|
if (iP !== -1) return String(iP);
|
|
const iA = ARABIC.indexOf(d);
|
|
return iA !== -1 ? String(iA) : d;
|
|
});
|