UNPKG

tibetan-syllable-parser

Version:

A parser to deconstruct a single Unicode Tibetan syllable into its different parts.

3 lines (2 loc) 5.61 kB
const t=function(t){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};var i=t.replace(/ཱུ/g,"ཱུ").replace(/ཱི/g,"ཱི").replace(/ཱྀ/g,"ཱྀ");return{options:Object.assign({keepMainAsSuperscribed:!1},s),prefix:void 0,suffix:void 0,secondSuffix:void 0,syllable:i,aKikuI:!1,completionU:!1,simplifiedSyllable:function(){return this.syllable.replace(/[ྭཱཾ༵ྃྂ༸]/g,"")},length:function(){return this.simplifiedSyllable().length},at:function(t,s){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};var e,h=this.simplifiedSyllable();return(e=i.fromEnd?h.lastIndexOf(t):h.indexOf(t))>=0?h[e+s]:void 0},vowel:function(){var t=this.syllable.match(/[ིྀེཻོཽུ]/);return t?t[0]:void 0},superscribed:function(){var t=this.syllable.match(/[ྐྒྔྗྙྟྡྣྦྨྩྫྕྤྷ]/);return t?this.at(t[0],-1):void 0},subscribed:function(){var t=this.syllable.match(/[ྱྲླ]/);return t?t[0]:void 0},figureOutPrefixAndSuffixes:function(){this.figureOutPrefix(),this.figureOutSuffixes()},figureOutPrefix:function(){this.superscribed()?this.prefix=this.at(this.superscribed(),-1):this.prefix=this.at(this.root,-1)},figureOutSuffixes:function(){this.vowel()?this.suffix=this.at(this.vowel(),1):this.subscribed()?this.suffix=this.at(this.subscribed(),1):this.suffix=this.at(this.root,1),this.secondSuffix=this.at(this.suffix,1,{fromEnd:!0})},convertMainAsRegularChar:function(){switch(this.root){case"ྐ":this.root="ཀ";break;case"ྒ":this.root="ག";break;case"ྔ":this.root="ང";break;case"ྗ":this.root="ཇ";break;case"ྙ":this.root="ཉ";break;case"ྟ":this.root="ཏ";break;case"ྡ":this.root="ད";break;case"ྣ":this.root="ན";break;case"ྦ":this.root="བ";break;case"ྨ":this.root="མ";break;case"ྩ":this.root="ཙ";break;case"ྫ":this.root="ཛ";break;case"ྕ":this.root="ཅ";break;case"ྤ":this.root="པ";break;case"ྷ":this.root="ཧ"}},isAnExceptionNowHandled:function(){switch(this.syllable){case"དབ":return this.prefix="ད",this.root="བ",!0;case"དགས":return this.prefix="ད",this.root="ག",this.suffix="ས",!0;case"དྭགས":return this.root="ད",this.suffix="ག",this.secondSuffix="ས",!0;case"དམས":return this.prefix="ད",this.root="མ",this.suffix="ས",!0;case"འགས":return this.prefix="འ",this.root="ག",this.suffix="ས",!0;case"མངས":return this.prefix="མ",this.root="ང",this.suffix="ས",!0;default:return!1}},returnObject:function(){return{prefix:this.prefix,superscribed:this.superscribed(),root:this.root,subscribed:this.subscribed(),vowel:this.vowel(),suffix:this.suffix,secondSuffix:this.secondSuffix,wasur:this.wasur(),achung:this.achung(),anusvara:this.anusvara(),honorificMarker:this.honorificMarker(),chego:this.chego()}},secondLetterIsGaNgaBaMa:function(){return this.syllable[1].match(/[གངབམ]/)},handleDreldraAi:function(){this.length()>2&&this.syllable.match(/འི$/)&&(this.length()<=3?this.syllable=this.syllable.replace(/འི$/,""):this.syllable=this.syllable.replace(/འི$/,"འ"),this.aKikuI=!0)},handleEndingO:function(){this.length()>2&&this.syllable.match(/འོ$/)&&(this.syllable=this.syllable.replace(/འོ$/,"འ"),this.completionO=!0)},handleEndingU:function(){this.length()>2&&this.syllable.match(/འུ$/)&&(this.syllable=this.syllable.replace(/འུ$/,""),this.completionU=!0)},handleAndOrParticleAAng:function(){this.length()>2&&this.syllable.match(/འང$/)&&(this.syllable=this.syllable.replace(/འང$/,""),this.andOrParticleAAng=!0)},handleConcessiveParticleAAm:function(){this.length()>2&&this.syllable.match(/འམ$/)&&(this.syllable=this.syllable.replace(/འམ$/,""),this.concessiveParticleAAm=!0)},wasur:function(){var t=this.syllable.match("ྭ");if(t)return t[0]},achung:function(){var t=this.syllable.match(/[ཱྰ]/);if(t)return t[0]},anusvara:function(){var t=this.syllable.match(/[ཾྃྂ]/);if(t)return t[0]},honorificMarker:function(){var t=this.syllable.match("༵");if(t)return t[0]},chego:function(){var t=this.syllable.match("༸");if(t)return t[0]},parse:function(){return this.isAnExceptionNowHandled()||(this.handleDreldraAi(),this.handleEndingU(),this.handleEndingO(),this.handleAndOrParticleAAng(),this.handleConcessiveParticleAAm(),1==this.length()&&(this.root=this.simplifiedSyllable()[0]),this.vowel()&&(this.root=this.at(this.vowel(),-1)),this.wasur()?this.root=this.syllable[this.syllable.replace(/[ྲྱཱཾ༵ྃྂ]/g,"").indexOf(this.wasur())-1]:this.subscribed()?this.root=this.at(this.subscribed(),-1):this.superscribed()&&(this.root=this.at(this.superscribed(),1)),this.root||(2==this.length()?(this.root=this.syllable[0],this.suffix=this.syllable[1]):4==this.length()?(this.prefix=this.syllable[0],this.root=this.syllable[1],this.suffix=this.syllable[2],this.secondSuffix=this.syllable[3]):3==this.length()&&("ས"!=this.syllable[this.syllable.length-1]?this.root=this.syllable[1]:this.secondLetterIsGaNgaBaMa()?this.secondLetterIsGaNgaBaMa()?this.root=this.syllable[0]:alert("There has been an error:\n\nThe syllable "+this.syllable+" could not be parsed.\n\nAre you sure it's correct?"):this.root=this.syllable[1])),this.figureOutPrefixAndSuffixes(),this.aKikuI&&(this.suffix="འི"),this.andOrParticleAAng&&(this.suffix="འང"),this.concessiveParticleAAm&&(this.suffix="འམ"),this.completionU&&(this.suffix="འུ"),this.completionO&&(this.suffix="འོ"),this.superscribed()&&!this.options.keepMainAsSuperscribed&&this.convertMainAsRegularChar()),this.returnObject()}}};export{t as TibetanSyllableParser}; //# sourceMappingURL=bundle.esm.min.js.map