jquery-korean-pron
Version:
A simple pronunciation conversion library for Korean.
8 lines • 1.04 kB
JavaScript
/*!
* jQuery Korean Pronunciation Conversion Library v0.1.0
* https://github.com/kawoou/jquery-korean-pron
*
* Copyright 2019
* Released under the MIT license
*/
window.jQuery.pronKorean=function(e){for(var a,r,l=["g","kk","n","d","tt","r","m","b","pp","s","ss","","j","jj","ch","k","t","p","h"],p=["a","ae","ya","yae","eo","e","yeo","ye","o","wa","wae","oe","yo","u","weo","we","wi","yu","eu","yi","i"],c=["","G","kk","ks","n","nj","nh","D","L","lk","lm","lp","ls","lt","lp","lh","m","B","ps","s","ss","ng","j","cc","k","t","p","h"],o="",g=e.length,s=0;s<g;++s)if(a=e.charCodeAt(s),44032<=(r=a)&&r<=55203){var n=a-44032,w=n%28,y=(n-w)/28%21;o+=l[parseInt((n-w)/28/21)]+p[y]+c[w]}else o+=e[s];return o.replace(/G([aeoiuyw])/g,"g$1").replace(/G/g,"k").replace(/B([aeoiuyw])/g,"b$1").replace(/B/g,"p").replace(/D([aeoiuyw])/g,"d$1").replace(/D/g,"t").replace(/(L[rl]|rr)/g,"ll").replace(/L([aeoiuyw])/g,"r$1").replace(/L/g,"l").replace(/weo/g,"wo").replace(/yi/g,"ui").replace(/kk(\s|,|\.)/g,"k$1").replace(/(j|ss|s|cc)(\s|,|\.)/g,"t$2")};