tzii.js
Version:
Maya Tz'utujil word utilities for translation and conjugation
2 lines (1 loc) • 3.99 kB
JavaScript
(function(i,t){typeof exports=="object"&&typeof module<"u"?module.exports=t():typeof define=="function"&&define.amd?define(t):(i=typeof globalThis<"u"?globalThis:i||self,i.tziijs=t())})(this,function(){"use strict";var I=Object.defineProperty;var $=i=>{throw TypeError(i)};var q=(i,t,o)=>t in i?I(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o;var c=(i,t,o)=>q(i,typeof t!="symbol"?t+"":t,o),b=(i,t,o)=>t.has(i)||$("Cannot "+o);var x=(i,t,o)=>(b(i,t,"read from private field"),o?o.call(i):t.get(i)),g=(i,t,o)=>t.has(i)?$("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,o),j=(i,t,o,h)=>(b(i,t,"write to private field"),h?h.call(i,o):t.set(i,o),o),p=(i,t,o)=>(b(i,t,"access private method"),o);var f,d,W,w,u,P,v;const i={1:["eem","i"],2:["axik","aaj","ixik","iij"],3:["ooj","an"],4:["b'a'xik","b'a'xiik","b'a'"],5:["areem","ari"],6:["irsaxik","irsaaj"]},t=["nin","nat","noq","nix","nee","xin","xat","xoq","xix","xee","xkin","xkat","xti","xkoq","xkix","xkee","n","x"],o={thirdSingularFuture:"xti",future:"xk",present:"n",past:"x"},h={"first person singular":"in","second person singular":"at","first person plural":"oq","second person plural":"ix","third person plural":"ee","third person singular":""};class m{constructor(e){g(this,d);c(this,"original","");g(this,f,"");c(this,"root","");c(this,"ending","");c(this,"class",0);c(this,"tense","");c(this,"person","");this.original=e,j(this,f,e.toLowerCase()),this.class=p(this,d,W).call(this,e);const{tense:n,person:s}=p(this,d,w).call(this);this.tense=n,this.person=s}}f=new WeakMap,d=new WeakSet,W=function(){let e=x(this,f),n=0;e.endsWith("na")&&(this.tense="future",e=e.slice(0,-2).trim());for(let s of Object.keys(i)){let r=i[s];for(let l of r)if(e.endsWith(l)){n=Number(s),this.ending=l,j(this,f,e.slice(0,-l.length));break}}return n},w=function(){let e="";for(let r of t)if(x(this,f).startsWith(r)){e=x(this,f).slice(0,r.length),this.root=x(this,f).slice(r.length);break}if(!e){if(this.root=x(this,f),this.class===3){const r=this.root.split(""),l=["a","e","i","o","u"];for(let a=r.length-1;a>=0;a--){const k=r[a];if(l.includes(k)&&this.root[a-1]===k){this.root=this.root.slice(0,a)+this.root.slice(a+1);break}}}return{tense:"infinitive",person:""}}let n="",s="";for(let r of Object.keys(o))if(e.startsWith(o[r])){if(r==="thirdSingularFuture")return{tense:"future",person:"third person singular"};{n=r;let l=e.slice(o[r].length);s=Object.keys(h).find(a=>h[a]===l);break}}return{tense:n,person:s}};class y{constructor(e){g(this,u);this.verb=e}conjugateAll(e="list"){const n=e==="list"?[]:{};for(let s of["past","present","future"]){e==="object"&&(n[s]={});for(let r of["singular","plural"]){e==="object"&&(n[s][r]={});for(let l of["first person","second person","third person"])e==="list"?n.push({title:`${l} ${r} ${s}`,person:l,tense:s,number:r,word:this.conjugateWord(s,l,r)}):e==="object"&&(n[s][r][l]=this.conjugateWord(s,l,r))}}return e==="list"?n.push({title:"infinitive",word:this.conjugateWord("infinitive")}):n.infinitive=this.conjugateWord("infinitive"),n}conjugateWord(e,n,s){return e==="infinitive"?`${this.verb.root}${p(this,u,v).call(this,e)}`:`${p(this,u,P).call(this,e,n,s)}${this.verb.root}${p(this,u,v).call(this)}`}isPrefixValid(e){return!!t.includes(e)}}return u=new WeakSet,P=function(e,n,s){let r="";if(r+=o[e],r+=h[`${n} ${s}`],e==="future"&&n==="third person"&&s==="singular"&&(r="xti"),!this.isPrefixValid(r))throw new Error(`Invalid prefix: ${r}`);return r},v=function(e){let n="";if([1,3,5,6].includes(this.verb.class)){const s=e==="infinitive"?0:1;n+=i[this.verb.class][s]}else if(this.verb.class===2){if(["axik","aaj"].includes(this.verb.ending)){const s=e==="infinitive"?0:1;n+=i[this.verb.class][s]}else if(["ixik","iij"].includes(this.verb.ending)){const s=e==="infinitive"?2:3;n+=i[this.verb.class][s]}}else if(this.verb.class===4){const s=e==="infinitive"?0:2;n+=i[this.verb.class][s]}return e==="future"&&(n+=" na"),n},{Verb:m,Conjugator:y}});