Last active
June 7, 2024 04:52
-
-
Save sijad/bfaec774101a3181cceba06e98f2c19b to your computer and use it in GitHub Desktop.
convert Persian and Arabic numbers to English
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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