UNPKG

thaiswap

Version:

Normalize character order and remove excessive characters.

2 lines (1 loc) 758 B
var getChLevel,levelRef,thaiSwap;levelRef={"ั":1,"ิ":1,"ี":1,"ึ":1,"ื":1,"ุ":-1,"ู":-1,"็":3,"่":2,"้":2,"๊":2,"๋":2,"์":2,"ํ":3,"๎":1},getChLevel=function(e){return levelRef[e]?levelRef[e]:0},thaiSwap=function(e){var t,a,l,i,o;for(t="",i=o=l=a=0;e.length>0;){switch(getChLevel(e[0])){case 0:l&&(t+=l,a?t+=a:o&&(t+=o),i&&(t+=i)),i=o=a=0,l=e[0];break;case-1:a=e[0];break;case 1:o&&3===getChLevel(o)&&(i=o),o=e[0];break;case 2:i=e[0];break;case 3:o?i=e[0]:o=e[0]}e=e.slice(1)}return l&&(t+=l,a?t+=a:o&&(t+=o),i&&(t+=i)),t},"object"==typeof module&&module&&"object"==typeof module.exports?module.exports=thaiSwap:(window.thaiSwap=thaiSwap,"function"==typeof define&&define.amd&&define("thaiSwap",[],function(){return thaiSwap}));