ilib
Version:
iLib is a cross-engine library of internationalization (i18n) classes written in pure JS
1 lines • 1.98 kB
JavaScript
var ilib=require("./ilib.js");var Utils=require("./Utils.js");var Locale=require("./Locale.js");var PhoneLocale=function(e){var a,c,n,o=true,i={},s;s=e&&e.locale||ilib.getLocale();this.parent.call(this,s);a=this.region;if(e){if(typeof e.mcc!=="undefined"){c=e.mcc}if(typeof e.countryCode!=="undefined"){n=e.countryCode}if(typeof e.sync!=="undefined"){o=e.sync==true}if(e.loadParams){i=e.loadParams}}Utils.loadData({name:"phoneloc.json",object:PhoneLocale,nonlocale:true,sync:o,loadParams:i,callback:ilib.bind(this,function(o){this.mappings=o;if(typeof c!=="undefined"){a=this.mappings.mcc2reg[c]}if(typeof n!=="undefined"){a=this.mappings.cc2reg[n]}if(!a){a="XX"}this.region=this._normPhoneReg(a);this._genSpec();if(e&&typeof e.onLoad==="function"){e.onLoad(this)}})})};PhoneLocale.prototype=new Locale;PhoneLocale.prototype.parent=Locale;PhoneLocale.prototype.constructor=PhoneLocale;PhoneLocale.prototype._mapMCCtoRegion=function(e){if(!e){return undefined}return this.mappings.mcc2reg&&this.mappings.mcc2reg[e]||"XX"};PhoneLocale.prototype._mapCCtoRegion=function(e){if(!e){return undefined}return this.mappings.cc2reg&&this.mappings.cc2reg[e]||"XX"};PhoneLocale.prototype._mapRegiontoCC=function(e){if(!e){return undefined}return this.mappings.reg2cc&&this.mappings.reg2cc[e]||"0"};PhoneLocale.prototype._mapAreatoRegion=function(e,a){if(!e){return undefined}if(e in this.mappings.area2reg){return this.mappings.area2reg[e][a]||this.mappings.area2reg[e]["default"]}else{return this.mappings.cc2reg[e]}};PhoneLocale.prototype._normPhoneReg=function(e){var a;switch(e){case"US":case"CA":case"AG":case"BS":case"BB":case"DM":case"DO":case"GD":case"JM":case"KN":case"LC":case"VC":case"TT":case"AI":case"BM":case"VG":case"KY":case"MS":case"TC":case"AS":case"VI":case"PR":case"MP":case"T:":case"GU":a="US";break;case"IT":case"SM":case"VA":a="IT";break;case"FR":case"GF":case"MQ":case"GP":case"BL":case"MF":case"RE":a="FR";break;default:a=e;break}return a};module.exports=PhoneLocale;