Created
April 9, 2019 11:07
-
-
Save a-m-dev/c36e3cd812a25e57e96e52a59dd7fa07 to your computer and use it in GitHub Desktop.
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
convert() { | |
var numerals = { | |
persian : ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"], | |
arabic : ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"] | |
}; | |
function fromEnglish(str, lang){ | |
var i, len = str.length, result = ""; | |
for( i = 0; i < len; i++ ) | |
result += numerals[lang][str[i]]; | |
return result; | |
} | |
return { | |
toNormal : function(str){ | |
var num, i, len = str.length, result = ""; | |
for( i = 0; i < len; i++ ){ | |
num = numerals["persian"].indexOf(str[i]); | |
num = num != -1 ? num : numerals["arabic"].indexOf(str[i]); | |
if( num == -1 ) num = str[i]; | |
result += num; | |
} | |
return result; | |
}, | |
toPersian : function(str, lang){ | |
return fromEnglish(str, "persian"); | |
}, | |
toArabic : function(str){ | |
return fromEnglish(str, "arabic"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
call it like
this.convert().toNormal(12312312۱۲۳۱۲۳۱۲۳2314123۲۳۴۲۳۴)