UNPKG

ilib

Version:

iLib is a cross-engine library of internationalization (i18n) classes written in pure JS

1 lines 1.88 kB
var ilib=require("../index.js"),Locale=require("./Locale.js"),IString=require("./IString.js"),CaseMapper=function(options){switch(this.up=!0,this.locale=new Locale(),options&&(void 0!==options.locale&&(this.locale="string"==typeof options.locale?new Locale(options.locale):options.locale),this.up=!options.direction||"toupper"===options.direction),this.mapData=this.up?{"ß":"SS","ΐ":"Ι","ά":"Α","έ":"Ε","ή":"Η","ί":"Ι","ΰ":"Υ","ϊ":"Ι","ϋ":"Υ","ό":"Ο","ύ":"Υ","ώ":"Ω","Ӏ":"Ӏ","ӏ":"Ӏ"}:{"Ӏ":"Ӏ"},this.locale.getLanguage()){case"az":case"tr":case"crh":case"kk":case"krc":case"tt":this._setUpMap("iı","İI")}"ie"!==ilib._getBrowser()&&"Edge"!==ilib._getBrowser()||(this.up&&(this.mapData["ς"]="Σ"),this._setUpMap("ⲁⲃⲅⲇⲉⲋⲍⲏⲑⲓⲕⲗⲙⲛⲝⲟⲡⲣⲥⲧⲩⲫⲭⲯⲱⳁⳉⳋ","ⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⳀⳈⳊ"),this._setUpMap("ⴀⴁⴂⴃⴄⴅⴆⴇⴈⴉⴊⴋⴌⴍⴎⴏⴐⴑⴒⴓⴔⴕⴖⴗⴘⴙⴚⴛⴜⴝⴞⴟⴠⴡⴢⴣⴤⴥ","ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ"))};CaseMapper.prototype={_charMapper:function(string){if(!string)return string;for(var c,code,ret="",it=("string"==typeof string?new IString(string):string.toString()).charIterator();it.hasNext();)c=it.next(),this.up||"Σ"!==c?this.mapData[c]?ret+=this.mapData[c]:ret+=this.up?c.toUpperCase():c.toLowerCase():it.hasNext()?ret=(ret+=(code=(c=it.next()).charCodeAt(0))<904&&902!==code||974<code?"ς":"σ")+c.toLowerCase():ret+="ς";return ret},_setUpMap:function(lower,upper){for(var from,to=this.up?(from=lower,upper):(from=upper,lower),i=0;i<upper.length;i++)this.mapData[from[i]]=to[i]},getLocale:function(){return this.locale},map:function(string){return this._charMapper(string)}},module.exports=CaseMapper;