Last active
December 26, 2016 19:24
-
-
Save msudgh/a794fdfc0359831dc5a06c9558ce1eea to your computer and use it in GitHub Desktop.
Converting English & Farsi digits
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 toFarsiDigit(number) { | |
const regex = /[0-9]/g | |
let result = number.replace(regex, function (w) { | |
return String.fromCharCode(w.charCodeAt(0) + 1728) | |
}) | |
return result | |
} | |
function toEnglishDigit(number) { | |
const regex = /[\u0660-\u0669\u06F0-\u06F9]/g | |
let result = number.replace(regex, function (w) { | |
return String.fromCharCode(w.charCodeAt(0) - 1728) | |
}) | |
return result | |
} | |
exports.toEnglishDigit = toEnglishDigit | |
exports.toFarsiDigit = toFarsiDigit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment