@daun_jung/korean-romanizer
Version:
한글 로마자 변환 라이브러리 - TypeScript 버전
3 lines (2 loc) • 15.1 kB
JavaScript
"use strict";var N=Object.defineProperty;var ln=Object.getOwnPropertyDescriptor;var cn=Object.getOwnPropertyNames;var hn=Object.prototype.hasOwnProperty;var Cn=(a,n)=>{for(var s in n)N(a,s,{get:n[s],enumerable:!0})},pn=(a,n,s,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of cn(n))!hn.call(a,e)&&e!==s&&N(a,e,{get:()=>n[e],enumerable:!(o=ln(n,e))||o.enumerable});return a};var Vn=a=>pn(N({},"__esModule",{value:!0}),a);var An={};Cn(An,{ConsonantAssimilation:()=>A,KoreanRomanizer:()=>P,Type:()=>K,default:()=>Jn,romanize:()=>xn,romanizeWithAssimilation:()=>bn,romanizeWithType:()=>yn});module.exports=Vn(An);var A=(s=>(s.Progressive="Progressive",s.Regressive="Regressive",s))(A||{}),K=(C=>(C.Substantives="Substantives",C.Compound="Compound",C.District="District",C.Name="Name",C.NameTypical="NameTypical",C.Typical="Typical",C))(K||{});var h=class{constructor(n,s){this.value=n;this.defaultPronunciation=s}getPronunciation(n,s,o,e){if(n===null||!n.isKoreanCharacter())return this.defaultPronunciation;let t=this.getComplexPronunciation(n,s,o,e),C=n.getRomanizedString(null,s,o,e);return this.isNeedHyphen(C,t)?`-${t}`:t}getComplexPronunciation(n,s,o,e){return this.defaultPronunciation}isNeedHyphen(n,s){return!1}},_=class extends h{constructor(){super(0,"g")}getComplexPronunciation(n,s,o,e){let t=n.jongsung;return t===9||t===10||t===11||t===12||t===13||t===14||t===15?"kk":t===27?"k":this.defaultPronunciation}isNeedHyphen(n,s){return n.endsWith("n")}},E=class extends h{constructor(){super(2,"n")}getComplexPronunciation(n,s,o,e){let t=n.jongsung;return t===8||t===15?"l":this.defaultPronunciation}},R=class extends h{constructor(){super(3,"d")}getComplexPronunciation(n,s,o,e){let t=n.jongsung;return t===13?"tt":t===6||t===27?"t":this.defaultPronunciation}},z=class extends h{constructor(){super(5,"r")}getComplexPronunciation(n,s,o,e){let t=n.jongsung;return t===1||t===2||t===3||t===9||t===11||t===14||t===16||t===17||t===18||t===21||t===24||t===26?"n":t===4||t===7||t===5||t===6||t===19||t===20||t===22||t===23||t===27?o==="Progressive"?"n":"l":t===8||t===10||t===12||t===13||t===15||t===25?"l":this.defaultPronunciation}},S=class extends h{constructor(){super(7,"b")}getComplexPronunciation(n,s,o,e){return n.jongsung===13?"pp":this.defaultPronunciation}},$=class extends h{constructor(){super(11,"")}getComplexPronunciation(n,s,o,e){let t=n.jongsung;return t===1?e==="Compound"&&s.getJungsungObj().isInducePalatalization()?"n":"g":t===9?"g":t===2?"kk":t===3||t===12||t===18||t===19?"s":t===21?e==="Compound"&&s.getJungsungObj().isInducePalatalization()?"n":this.defaultPronunciation:t===4||t===6?"n":t===5||t===22?"j":t===7?s.getJungsungObj().isInducePalatalization()?"j":"d":t===8||t===15?e==="Compound"&&s.getJungsungObj().isInducePalatalization()?"l":"r":t===10||t===16?"m":t===11||t===17?"b":t===13||t===25?s.getJungsungObj().isInducePalatalization()?"ch":"t":t===14||t===26?"p":t===20?"ss":t===23?"ch":t===24?"k":this.defaultPronunciation}isNeedHyphen(n,s){return n.endsWith("ng")&&s.length===0}},W=class extends h{constructor(){super(12,"j")}getComplexPronunciation(n,s,o,e){return n.jongsung===27?"ch":this.defaultPronunciation}},U=class extends h{constructor(){super(16,"t")}getComplexPronunciation(n,s,o,e){let t=n.jongsung;return t===22||t===23?s.getJungsungObj().isInducePalatalization()?"ch":"t":this.defaultPronunciation}isNeedHyphen(n,s){return n.endsWith("t")}},H=class extends h{constructor(){super(17,"p")}isNeedHyphen(n,s){return n.endsWith("p")}},D=class extends h{constructor(){super(18,"h")}getComplexPronunciation(n,s,o,e){let t=n.jongsung;return t===1?e==="Substantives"?this.defaultPronunciation:"":t===2?"kk":t===7?e==="Substantives"?this.defaultPronunciation:s.getJungsungObj().isInducePalatalization()?"ch":"t":t===13||t===19||t===20||t===22||t===23||t===25?s.getJungsungObj().isInducePalatalization()?"ch":"t":t===9?"k":t===11?"p":t===12?"s":t===15?"r":t===17?e==="Substantives"?this.defaultPronunciation:"p":this.defaultPronunciation}isNeedHyphen(n,s){return s.length>0&&n.endsWith(String(s.charAt(0)))}};var L=class{constructor(n,s,o){this.value=n;this.defaultPronunciation=s;this.inducePalatalization=o}getPronunciation(n,s){let o=!1;if(n!=null&&n.isKoreanCharacter()&&n.jongsung===0&&s.chosung===11){let e=n.getJungsungObj().defaultPronunciation.charAt(n.getJungsungObj().defaultPronunciation.length-1),t=this.defaultPronunciation.charAt(0);e==="a"?(t==="a"||t==="e")&&(o=!0):e==="e"&&(t==="a"||t==="e"||t==="o"||t==="u")&&(o=!0)}return o?`-${this.defaultPronunciation}`:this.defaultPronunciation}isInducePalatalization(){return this.inducePalatalization}};var l=class{constructor(n,s){this.value=n;this.defaultPronunciation=s}getPronunciation(n,s,o){return n===null||!n.isKoreanCharacter()?this.defaultPronunciation:this.getComplexPronunciation(n,s,o)}getComplexPronunciation(n,s,o){return this.defaultPronunciation}},M=class extends l{constructor(){super(1,"k")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===1||e===15?"":e===11?o==="Compound"&&n.getJungsungObj().isInducePalatalization()?"ng":"":e===2||e===6||e===5?"ng":this.defaultPronunciation}},X=class extends l{constructor(){super(2,"k")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===1||e===15||e===11||e===18?"":e===2||e===6||e===5?"ng":this.defaultPronunciation}},F=class extends l{constructor(){super(3,"k")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===1||e===15?"":e===2||e===6||e===5?"ng":this.defaultPronunciation}},k=class extends l{constructor(){super(4,"n")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===5?s==="Regressive"?"l":"n":e===11?"":this.defaultPronunciation}},Y=class extends l{constructor(){super(5,"n")}getComplexPronunciation(n,s,o){return n.chosung===5?s==="Regressive"?"l":"n":this.defaultPronunciation}},B=class extends l{constructor(){super(6,"n")}getComplexPronunciation(n,s,o){return new k().getComplexPronunciation(n,s,o)}},w=class extends l{constructor(){super(7,"t")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===2||e===6?"n":e===4||e===11||e===16||e===18?o==="Substantives"?this.defaultPronunciation:"":e===5?s==="Regressive"?"l":"n":this.defaultPronunciation}},q=class extends l{constructor(){super(8,"l")}getComplexPronunciation(n,s,o){return n.chosung===11?o==="Compound"&&n.getJungsungObj().isInducePalatalization()?this.defaultPronunciation:"":this.defaultPronunciation}},g=class g{static getJongsung(n){if(!g.instances.has(n))switch(n){case 1:g.instances.set(n,new M);break;case 2:g.instances.set(n,new X);break;case 3:g.instances.set(n,new F);break;case 4:g.instances.set(n,new k);break;case 5:g.instances.set(n,new Y);break;case 6:g.instances.set(n,new B);break;case 7:g.instances.set(n,new w);break;case 8:g.instances.set(n,new q);break;case 9:g.instances.set(n,new G);break;case 10:g.instances.set(n,new v);break;case 11:g.instances.set(n,new nn);break;case 14:g.instances.set(n,new en);break;case 15:g.instances.set(n,new tn);break;case 16:g.instances.set(n,new sn);break;case 17:g.instances.set(n,new on);break;case 18:g.instances.set(n,new an);break;case 19:g.instances.set(n,new O);break;case 20:g.instances.set(n,new O);break;case 27:g.instances.set(n,new un);break;default:g.instances.set(n,new l(n,Pn[n]));break}return g.instances.get(n)}};g.instances=new Map;var Q=g,c=class c{static getChosung(n){if(!c.instances.has(n))switch(n){case 0:c.instances.set(n,new _);break;case 2:c.instances.set(n,new E);break;case 3:c.instances.set(n,new R);break;case 5:c.instances.set(n,new z);break;case 7:c.instances.set(n,new S);break;case 11:c.instances.set(n,new $);break;case 12:c.instances.set(n,new W);break;case 16:c.instances.set(n,new U);break;case 17:c.instances.set(n,new H);break;case 18:c.instances.set(n,new D);break;default:c.instances.set(n,new h(n,fn[n]));break}return c.instances.get(n)}};c.instances=new Map;var Z=c,fn={0:"g",1:"kk",2:"n",3:"d",4:"tt",5:"r",6:"m",7:"b",8:"pp",9:"s",10:"ss",11:"",12:"j",13:"jj",14:"ch",15:"k",16:"t",17:"p",18:"h"},mn={0:"a",1:"ae",2:"ya",3:"yae",4:"eo",5:"e",6:"yeo",7:"ye",8:"o",9:"wa",10:"wae",11:"oe",12:"yo",13:"u",14:"wo",15:"we",16:"wi",17:"yu",18:"eu",19:"ui",20:"i"},dn={0:!1,1:!1,2:!0,3:!0,4:!1,5:!1,6:!0,7:!0,8:!1,9:!1,10:!1,11:!1,12:!0,13:!1,14:!1,15:!1,16:!1,17:!0,18:!1,19:!1,20:!0},Pn={0:"",1:"k",2:"k",3:"k",4:"n",5:"n",6:"n",7:"t",8:"l",9:"k",10:"m",11:"l",12:"l",13:"l",14:"l",15:"l",16:"m",17:"p",18:"p",19:"t",20:"t",21:"ng",22:"t",23:"t",24:"k",25:"t",26:"p",27:"t"},m=class m{constructor(n){this.chosungObj=null;this.jungsungObj=null;this.jongsungObj=null;if(this.char=n,this.code=n.charCodeAt(0),this.isHangul=this.code>=m.KOREAN_LOWER_VALUE&&this.code<=m.KOREAN_UPPER_VALUE,this.isHangul){let s=this.code-m.KOREAN_LOWER_VALUE;this.jongsung=s%28,this.jungsung=Math.floor((s-this.jongsung)/28)%21,this.chosung=Math.floor((s-this.jongsung)/28/21)}else this.chosung=-1,this.jungsung=-1,this.jongsung=-1}isKoreanCharacter(){return this.isHangul}toString(){return this.char}getChosungObj(){return this.chosungObj===null&&(this.chosungObj=Z.getChosung(this.chosung)),this.chosungObj}getJungsungObj(){return this.jungsungObj===null&&(this.jungsungObj=new L(this.jungsung,mn[this.jungsung],dn[this.jungsung])),this.jungsungObj}getJongsungObj(){return this.jongsungObj===null&&(this.jongsungObj=Q.getJongsung(this.jongsung)),this.jongsungObj}getRomanizedString(n,s,o,e){if(!this.isHangul)return this.char;(e==="Name"||e==="NameTypical")&&(n=null,s=null);let t=this.getChosungObj().getPronunciation(n,this,o,e),C=this.getJungsungObj().getPronunciation(n,this),I=this.getJongsungObj().getPronunciation(s,o,e);return t+C+I}static isKoreanCharacter(n){if(n.length!==1)return!1;let s=n.charCodeAt(0);return s>=m.KOREAN_LOWER_VALUE&&s<=m.KOREAN_UPPER_VALUE}};m.KOREAN_LOWER_VALUE=44032,m.KOREAN_UPPER_VALUE=55203;var J=m,G=class extends l{constructor(){super(9,"k")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===0||e===1||e===11||e===18?"l":e===2||e===5||e===6?"ng":this.defaultPronunciation}},v=class extends l{constructor(){super(10,"m")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===5||e===6||e===11?"l":this.defaultPronunciation}},nn=class extends l{constructor(){super(11,"l")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===2||e===5?"m":e===3||e===4||e===7||e===9||e===10||e===12||e===13||e===14||e===15||e===16||e===18?"p":e===8?"":this.defaultPronunciation}},en=class extends l{constructor(){super(14,"l")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===2||e===5?"m":e===3||e===4||e===7||e===9||e===10||e===12||e===13||e===14||e===15||e===16||e===18?"p":e===8||e===17?"":this.defaultPronunciation}},tn=class extends l{constructor(){super(15,"l")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===18?"":e===11?o==="Compound"&&n.getJungsungObj().isInducePalatalization()?this.defaultPronunciation:"":this.defaultPronunciation}},sn=class extends l{constructor(){super(16,"m")}getComplexPronunciation(n,s,o){return n.chosung===11?"":this.defaultPronunciation}},on=class extends l{constructor(){super(17,"p")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===2||e===5||e===6?"m":e===8||e===11?"":e===18?o==="Substantives"?this.defaultPronunciation:"":this.defaultPronunciation}},an=class extends l{constructor(){super(18,"p")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===2||e===5||e===6?"m":e===8?"":this.defaultPronunciation}},O=class extends l{constructor(){super(19,"t")}getComplexPronunciation(n,s,o){return new w().getComplexPronunciation(n,s,o)}},un=class extends l{constructor(){super(27,"t")}getComplexPronunciation(n,s,o){let e=n.chosung;return e===0||e===1||e===3||e===4||e===11||e===12||e===13||e===14||e===15||e===16||e===17||e===18?"":e===2||e===6?"n":e===5?s==="Regressive"?"l":"n":this.defaultPronunciation}};var P;(jn=>{let a=/^(\s*)(강전|남궁|독고|동방|등정|망절|무본|사공|서문|선우|소봉|어금|장곡|제갈|황목|황보)(.{1,10})$/,n=/^(.{1,20}?)(특별자치도|특별자치시|특별시|광역시|대로|구|군|도|동|리|면|시|읍|가|길|로)(\s*)$/,s=/^(.{0,20}?)(\d+)(\s*)(가길|가|번길|로|단지|동)(\s*)$/,o=/^(.{0,20}?)(대?로)\s*(\d+[가번]?)(길)(\s*)$/,e={\uAC00:"Ka",\uAC04:"Kan",\uAC08:"Kal",\uAC10:"Kam",\uAC15:"Kang",\uAC15\uC804:"Kangjun",\uACAC:"Kyun",\uACBD:"Kyung",\uACC4:"Kye",\uACE0:"Ko",\uACF5:"Kong",\uACFD:"Kwak",\uAD6C:"Koo",\uAD6D:"Kook",\uAD70:"Kun",\uAD81:"Koong",\uAD89:"Kwok",\uAD8C:"Kwon",\uADFC:"Keun",\uAE08:"Keum",\uAE30:"Ki",\uAE38:"Kil",\uAE40:"Kim",\uB178:"Noh",\uB450:"Doo",\uB780:"Lan",\uB8B0:"Loi",\uB8E8:"Lu",\uB9DD\uC808:"Mangjul",\uBA85:"Myung",\uBB38:"Moon",\uBC15:"Park",\uBCC0:"Byun",\uBD80:"Boo",\uC120:"Sun",\uC120\uC6B0:"Sunwoo",\uC131:"Sung",\uC21C:"Soon",\uC2E0:"Shin",\uC2EC:"Shim",\uC544:"Ah",\uC5B4\uAE08:"Eokum",\uC624:"Oh",\uC6B0:"Woo",\uC6B4:"Woon",\uC720:"Yoo",\uC724:"Yoon",\uC774:"Lee",\uC784:"Lim",\uC815:"Jung",\uC870:"Cho",\uC8FC:"Joo",\uC900:"June",\uC999:"Chup",\uCD5C:"Choi",\uD3B8:"Pyun",\uD3C9:"Pyung",\uD48D:"Poong",\uD604:"Hyun",\uD615:"Hyung",\uD765:"Hong"};function t(r,u){if(r===null)throw new Error("String should not be null.");if(r.trim().length===0)return"";let i="Typical",p="Regressive";if(u!==void 0&&(typeof u=="object"?(i=u.type||"Typical",p=u.consonantAssimilation||"Regressive"):Object.values(K).includes(u)?i=u:Object.values(A).includes(u)&&(p=u)),r.indexOf(" ")>0&&(i==="Name"||i==="NameTypical")){let d=r.split(" "),y="";for(let f=0;f<d.length;f++)f>0&&(y+=" "),y+=t(d[f],{type:i,consonantAssimilation:p});return y}let V=r;switch(i){case"Name":case"NameTypical":V=C(r,i);break;case"District":V=I(r);break;case"Typical":break}let b="",x=null,j=null,rn=null,T=V.split("");for(let d=0;d<T.length;d++){let y=T[d];if(x=j,j=new J(y),rn=d<T.length-1?new J(T[d+1]):null,j.isKoreanCharacter()){let f=j.getRomanizedString(x,rn,p,i);x===null||!x.isKoreanCharacter()?i==="District"&&x!==null&&(x.toString()==="-"||!Number.isNaN(Number(x.toString())))?b+=f:b+=f.charAt(0).toUpperCase()+f.slice(1):b+=f}else b+=y}return b}jn.romanize=t;function C(r,u){let i=a.exec(r);if(u==="NameTypical"){if(i&&i.length>3)return`${i[1]+(e[i[2]]||i[2])} ${i[3]}`;let p=e[r.charAt(0)];return p?`${p} ${r.substring(1)}`:`${r.charAt(0)} ${r.substring(1)}`}return i&&i.length>3?`${i[1]+i[2]} ${i[3]}`:`${r.charAt(0)} ${r.substring(1)}`}function I(r){let u=o.exec(r);return u?`${u[1]}-${u[2]} ${u[3]}-${u[4]}${u[5]}`:(u=s.exec(r),u?`${u[1]+(u[1].endsWith(" ")?"":" ")+u[2]}-${u[4]}${u[5]}`:(u=n.exec(r),u?`${u[1]}-${u[2]}${u[3]}`:r))}function gn(r,u){if(r===null)throw new Error("String should not be null.");if(r.trim().length===0)return"";if(r.indexOf(" ")>0){let i=r.split(" "),p=[];for(let V=0;V<i.length;V++)(u==="Name"||u==="NameTypical")&&V<=1?p.push(gn(i[V],u)):u==="District"?p.push(t(i[V],{type:"District"})):p.push(t(i[V],{type:"Typical"}));return p.join(" ")}return t(r,{type:u})}jn.romanizeWithType=gn;function Kn(r,u){return t(r,{consonantAssimilation:u})}jn.romanizeWithAssimilation=Kn})(P||(P={}));var xn=P.romanize,yn=P.romanizeWithType,bn=P.romanizeWithAssimilation;var Jn=P;
//# sourceMappingURL=index.js.map