Skip to content

Instantly share code, notes, and snippets.

@sijad
Last active June 7, 2024 04:52
Show Gist options
  • Save sijad/bfaec774101a3181cceba06e98f2c19b to your computer and use it in GitHub Desktop.
Save sijad/bfaec774101a3181cceba06e98f2c19b to your computer and use it in GitHub Desktop.
convert Persian and Arabic numbers to English
function convertToEnglishNumbers(input) {
let o = '';
for (const c of input) {
const n = c.codePointAt(0);
if (n >= 1632 && n <= 1641) {
o += n - 1632;
} else if (n >= 1776 && n <= 1785) {
o += n - 1776;
} else {
o += c;
}
}
return o
}
console.log(
convertToEnglishNumbers(
"'۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', '٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'",
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment