Skip to content

Instantly share code, notes, and snippets.

@msudgh
Last active December 26, 2016 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msudgh/a794fdfc0359831dc5a06c9558ce1eea to your computer and use it in GitHub Desktop.
Save msudgh/a794fdfc0359831dc5a06c9558ce1eea to your computer and use it in GitHub Desktop.
Converting English & Farsi digits
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