SHARE
TWEET

Untitled

a guest Apr 19th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. convert() {
  2.     var numerals = {
  3.       persian : ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"],
  4.       arabic  : ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"]
  5.     };
  6.  
  7.     function fromEnglish(str, lang){
  8.       var i, len = str.length, result = "";
  9.  
  10.       for( i = 0; i < len; i++ )
  11.           result += numerals[lang][str[i]];
  12.  
  13.       return result;
  14.     }
  15.  
  16.     return {
  17.       toNormal : function(str){
  18.           var num, i, len = str.length, result = "";
  19.  
  20.           for( i = 0; i < len; i++ ){
  21.               num = numerals["persian"].indexOf(str[i]);
  22.               num = num != -1 ? num : numerals["arabic"].indexOf(str[i]);
  23.               if( num == -1 ) num = str[i];
  24.               result += num;
  25.           }
  26.            
  27.           return result;
  28.       },
  29.  
  30.       toPersian : function(str, lang){
  31.           return fromEnglish(str, "persian");
  32.       },
  33.  
  34.       toArabic : function(str){
  35.           return fromEnglish(str, "arabic");
  36.       }
  37.     }
  38.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top