-
Notifications
You must be signed in to change notification settings - Fork 1
/
hangul.min.js
8 lines (8 loc) · 3.14 KB
/
hangul.min.js
1
2
3
4
5
6
7
8
/**
* hangul.js
* http://github.com/clee704/hangul-js
* @version 1.1.2
* @copyright Copyright 2013, Choongmin Lee
* @license MIT license
*/
var hangul=function(t){"use strict";if(!Array.prototype.indexOf){Array.prototype.indexOf=function(t){if(this===void 0||this===null)throw new TypeError;var r=Object(this);var e=r.length>>>0;if(e===0)return-1;var n=0;if(arguments.length>0){n=Number(arguments[1]);if(n!==n){n=0}else if(n!==0&&n!==Infinity&&n!==-Infinity){n=(n>0||-1)*Math.floor(Math.abs(n))}}if(n>=e)return-1;var i=n>=0?n:Math.max(e-Math.abs(n),0);for(;i<e;i++){if(i in r&&r[i]===t)return i}return-1}}function r(){var t;this.items={};for(t=0;t<arguments.length;t++){this.add(arguments[t])}}r.prototype.has=function(t){return t in this.items};r.prototype.add=function(t){this.items[t]=1};function e(r,n){this.items={};this.inverse=n||new e(t,this);if(r){this.addAll(r)}}e.prototype.add=function(t,r){this.items[t]=r;this.inverse.items[r]=t};e.prototype.addAll=function(t){var r;for(r in t){this.add(r,t[r])}};e.prototype.hasKey=function(t){return t in this.items};e.prototype.hasValue=function(t){return t in this.inverse.items};e.prototype.get=function(t){return this.items[t]};var n=u(12593,12643);var i=u(12593,12622,[2,4,5,9,10,11,12,13,14,15,19]);var a=u(12623,12643);var o=u(12593,12622,[7,18,24]);function u(t,r,n){var i=new e,a=r-t+1;for(var o=0,u=0;o<a;o++){if(!n||n.indexOf(o)<0){i.add(u++,String.fromCharCode(o+t))}}return i}function s(t){var r=t&&t.charAt&&t.charAt(0);return n.hasValue(r)||h(r)}function h(t){var r=t&&t.charCodeAt&&t.charCodeAt(0);return 44032<=r&&r<=55203}function c(t){return n.hasValue(t&&t.charAt&&t.charAt(0))}function f(t){return i.hasValue(t&&t.charAt&&t.charAt(0))}function l(t){return a.hasValue(t&&t.charAt&&t.charAt(0))}function d(t){return o.hasValue(t&&t.charAt&&t.charAt(0))}function v(t){var r=t&&t.charCodeAt&&t.charCodeAt(0);return i.get(Math.floor((r-44032)/28/21))}function A(t){var r=t&&t.charCodeAt&&t.charCodeAt(0);return a.get(Math.floor((r-44032)/28)%21)}function m(r){var e=r&&r.charCodeAt&&r.charCodeAt(0),n=(e-44032)%28;return n>0?o.get(n-1):n===0?"":t}function p(r){var e=r&&r.charAt&&r.charAt(0);if(!h(e)){return t}var n=[v(e),A(e),m(e)];if(n[2]===""){n.pop()}return n}function g(r,e,n){var u=i.inverse.get(r),s=a.inverse.get(e),c=n===t||n===""?0:o.inverse.get(n)+1,f=String.fromCharCode(44032+(u*21+s)*28+c);return h(f)?f:t}var y=new e({"ㄳ":"ㄱㅅ","ㄵ":"ㄴㅈ","ㄶ":"ㄴㅎ","ㄺ":"ㄹㄱ","ㄻ":"ㄹㅁ","ㄼ":"ㄹㅂ","ㄽ":"ㄹㅅ","ㄾ":"ㄹㅌ","ㄿ":"ㄹㅍ","ㅀ":"ㄹㅎ","ㅄ":"ㅂㅅ","ㄲ":"ㄱㄱ","ㄸ":"ㄷㄷ","ㅃ":"ㅂㅂ","ㅆ":"ㅅㅅ","ㅉ":"ㅈㅈ","ㅘ":"ㅗㅏ","ㅙ":"ㅗㅐ","ㅚ":"ㅗㅣ","ㅝ":"ㅜㅓ","ㅞ":"ㅜㅔ","ㅟ":"ㅜㅣ","ㅢ":"ㅡㅣ"});function C(t,r){return y.inverse.get(t+r)}function M(r){var e=y.get(r);return e===t?e:[e.charAt(0),e.charAt(1)]}var b=new r("ㅣ","ㅑ","ㅒ","ㅕ","ㅖ","ㅛ","ㅠ");function w(t){return b.has(t&&t.charAt&&t.charAt(0))}return{Set:r,Map:e,jamo:n,initials:i,medials:a,finals:o,isHangul:s,isSyllable:h,isJamo:c,isInitial:f,isMedial:l,isFinal:d,getInitial:v,getMedial:A,getFinal:m,decompose:p,compose:g,composeDoubleJamo:C,decomposeDoubleJamo:M,isIotizedVowel:w}}();