-
Notifications
You must be signed in to change notification settings - Fork 96
/
hangul.min.js
3 lines (2 loc) · 5.99 KB
/
hangul.min.js
1
2
3
/*! hangul-js 2019-12-10 */
!function(){"use strict";var r,d,g,l,t,e,h=["ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"],p=["ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ",["ㅗ","ㅏ"],["ㅗ","ㅐ"],["ㅗ","ㅣ"],"ㅛ","ㅜ",["ㅜ","ㅓ"],["ㅜ","ㅔ"],["ㅜ","ㅣ"],"ㅠ","ㅡ",["ㅡ","ㅣ"],"ㅣ"],C=["","ㄱ","ㄲ",["ㄱ","ㅅ"],"ㄴ",["ㄴ","ㅈ"],["ㄴ","ㅎ"],"ㄷ","ㄹ",["ㄹ","ㄱ"],["ㄹ","ㅁ"],["ㄹ","ㅂ"],["ㄹ","ㅅ"],["ㄹ","ㅌ"],["ㄹ","ㅍ"],["ㄹ","ㅎ"],"ㅁ","ㅂ",["ㅂ","ㅅ"],"ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"],A=44032;function n(n){for(var r=n.length,t={0:0},e=0;e<r;e++)n[e]&&(t[n[e].charCodeAt(0)]=e);return t}function o(n){for(var r,t,e=n.length,o={},i=0;i<e;i++)r=n[i][0].charCodeAt(0),t=n[i][1].charCodeAt(0),void 0===o[r]&&(o[r]={}),o[r][t]=n[i][2].charCodeAt(0);return o}function v(n){return void 0!==r[n]}function y(n){return void 0!==d[n]}function m(n){return void 0!==g[n]}function u(n){return void 0!==l[n]}function j(n){return 44032<=n&&n<=55203}function b(n,r){return!(!e[n]||!e[n][r])&&e[n][r]}function S(n,r){return!(!t[n]||!t[n][r])&&t[n][r]}r=n(["ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄸ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅃ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"]),d=n(["ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"]),g=n(["ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ","ㅘ","ㅙ","ㅚ","ㅛ","ㅜ","ㅝ","ㅞ","ㅟ","ㅠ","ㅡ","ㅢ","ㅣ"]),l=n(["","ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"]),t=o([["ㄱ","ㅅ","ㄳ"],["ㄴ","ㅈ","ㄵ"],["ㄴ","ㅎ","ㄶ"],["ㄹ","ㄱ","ㄺ"],["ㄹ","ㅁ","ㄻ"],["ㄹ","ㅂ","ㄼ"],["ㄹ","ㅅ","ㄽ"],["ㄹ","ㅌ","ㄾ"],["ㄹ","ㅍ","ㄿ"],["ㄹ","ㅎ","ㅀ"],["ㅂ","ㅅ","ㅄ"]]),e=o([["ㅗ","ㅏ","ㅘ"],["ㅗ","ㅐ","ㅙ"],["ㅗ","ㅣ","ㅚ"],["ㅜ","ㅓ","ㅝ"],["ㅜ","ㅔ","ㅞ"],["ㅜ","ㅣ","ㅟ"],["ㅡ","ㅣ","ㅢ"]]);function w(n,r){if(null===n)throw new Error("Arguments cannot be null");"object"==typeof n&&(n=n.join(""));for(var t,e,o,i,u,f=[],c=n.length,a=0;a<c;a++){var s=[];j(i=n.charCodeAt(a))?(e=((i-=A)-(o=i%28))/28%21,t=parseInt((i-o)/28/21),s.push(h[t]),"object"==typeof p[e]?s=s.concat(p[e]):s.push(p[e]),0<o&&("object"==typeof C[o]?s=s.concat(C[o]):s.push(C[o]))):v(i)?"string"==typeof(u=y(i)?h[d[i]]:C[l[i]])?s.push(u):s=s.concat(u):m(i)?"string"==typeof(u=p[g[i]])?s.push(u):s=s.concat(u):s.push(n.charAt(a)),r?f.push(s):f=f.concat(s)}return f}function i(n){return"string"!=typeof n?"":(n=w(n)).join("")}function f(c){"string"==typeof c&&(c=w(c));var n,r,a=[],t=c.length,e=0,s=-1,h=!1;function o(n){var r,t,e,o,i=0,u="";if(h=!1,!(n<s+1))for(var f=1;;f++){if(1===f){if(m(r=c[s+f].charCodeAt(0)))return s+f+1<=n&&m(t=c[s+f+1].charCodeAt(0))?a.push(String.fromCharCode(b(r,t))):a.push(c[s+f]),void(s=n);if(!y(r))return a.push(c[s+f]),void(s=n);u=c[s+f]}else if(2===f){if(y(t=c[s+f].charCodeAt(0)))return r=S(r,t),u=String.fromCharCode(r),a.push(u),void(s=n);u=String.fromCharCode(28*(21*d[r]+g[t])+A)}else 3===f?(b(t,e=c[s+f].charCodeAt(0))?t=b(t,e):i=e,u=String.fromCharCode(28*(21*d[r]+g[t])+l[i]+A)):4===f?(i=S(i,o=c[s+f].charCodeAt(0))?S(i,o):o,u=String.fromCharCode(28*(21*d[r]+g[t])+l[i]+A)):5===f&&(i=S(i,o=c[s+f].charCodeAt(0)),u=String.fromCharCode(28*(21*d[r]+g[t])+l[i]+A));if(n<=s+f)return a.push(u),void(s=n)}}for(var i=0;i<t;i++)y(n=c[i].charCodeAt(0))||m(n)||u(n)?(0===e?y(n)?e=1:m(n)&&(e=4):1==e?m(n)?e=2:S(r,n)?e=5:o(i-1):2==e?u(n)?e=3:m(n)?b(r,n)||(o(i-1),e=4):(o(i-1),e=1):3==e?u(n)?!h&&S(r,n)?h=!0:(o(i-1),e=1):y(n)?(o(i-1),e=1):m(n)&&(o(i-2),e=2):4==e?m(n)?b(r,n)?(o(i),e=0):o(i-1):(o(i-1),e=1):5==e&&(e=m(n)?(o(i-2),2):(o(i-1),1)),r=n):(o(i-1),o(i),e=0);return o(i-1),a.join("")}function c(n){this.string=n,this.disassembled=w(n).join("")}c.prototype.search=function(n){return w(n).join("").indexOf(this.disassembled)};var a={disassemble:w,d:w,disassembleToString:i,ds:i,assemble:f,a:f,search:function(n,r){var t=w(n).join(""),e=w(r).join("");return t.indexOf(e)},rangeSearch:function(n,r){var t,e=w(n).join(""),o=w(r).join(""),i=w(n,!0),u=new RegExp(o,"gi"),f=[];if(!r.length)return[];for(;t=u.exec(e);)f.push(t.index);return f.map(function(n){return[function(n){for(var r=0,t=0;r<i.length;++r)if(n<(t+=i[r].length))return r}(n),function(n){for(var r=0,t=0;r<i.length;++r)if(t+=i[r].length,n+o.length<=t)return r}(n)]})},Searcher:c,endsWithConsonant:function(n){"object"==typeof n&&(n=n.join(""));var r=n.charCodeAt(n.length-1);if(j(r)){if(0<(r-=A)%28)return!0}else if(v(r))return!0;return!1},endsWith:function(n,r){return w(n).pop()===r},isHangul:function(n){return"string"==typeof n&&(n=n.charCodeAt(0)),j(n)},isComplete:function(n){return"string"==typeof n&&(n=n.charCodeAt(0)),j(n)},isConsonant:function(n){return"string"==typeof n&&(n=n.charCodeAt(0)),v(n)},isVowel:function(n){return"string"==typeof n&&(n=n.charCodeAt(0)),m(n)},isCho:function(n){return"string"==typeof n&&(n=n.charCodeAt(0)),y(n)},isJong:function(n){return"string"==typeof n&&(n=n.charCodeAt(0)),u(n)},isHangulAll:function(n){if("string"!=typeof n)return!1;for(var r=0;r<n.length;r++)if(!j(n.charCodeAt(r)))return!1;return!0},isCompleteAll:function(n){if("string"!=typeof n)return!1;for(var r=0;r<n.length;r++)if(!j(n.charCodeAt(r)))return!1;return!0},isConsonantAll:function(n){if("string"!=typeof n)return!1;for(var r=0;r<n.length;r++)if(!v(n.charCodeAt(r)))return!1;return!0},isVowelAll:function(n){if("string"!=typeof n)return!1;for(var r=0;r<n.length;r++)if(!m(n.charCodeAt(r)))return!1;return!0},isChoAll:function(n){if("string"!=typeof n)return!1;for(var r=0;r<n.length;r++)if(!y(n.charCodeAt(r)))return!1;return!0},isJongAll:function(n){if("string"!=typeof n)return!1;for(var r=0;r<n.length;r++)if(!u(n.charCodeAt(r)))return!1;return!0}};"function"==typeof define&&define.amd?define(function(){return a}):"undefined"!=typeof module?module.exports=a:window.Hangul=a}();