hangulx
Version:
Providing various utilities for Hangul
298 lines (297 loc) • 10.1 kB
JavaScript
import { VOWEL } from "./constants/VOWEL";
import { basicVowelCharCodeSet, basicVowelSet } from "./constants/vowel/basic-vowels";
import { complexVowelCharCodeSet, complexVowelSet } from "./constants/vowel/complex-vowels";
import { fallingDiphthongCharCodeSet, fallingDiphthongDisassembleMap, fallingDiphthongSet } from "./constants/vowel/falling-diphthong";
import { risingJDiphthongCharCodeSet, risingJDiphthongDisassembleMap, risingJDiphthongSet } from "./constants/vowel/rising-j-diphthong";
import { risingWDiphthongCharCodeSet, risingWDiphthongDisassembleMap, risingWDiphthongSet } from "./constants/vowel/rising-w-diphthong";
var Vowel = /** @class */ (function () {
function Vowel() {
}
Vowel.disassembleFallingDiphthong = function (str) {
var results = [];
var length = str.length;
for (var i = 0; i < length; ++i) {
var char = str.charAt(i);
if (fallingDiphthongDisassembleMap.has(char)) {
var disassembled = fallingDiphthongDisassembleMap.get(char);
if (typeof disassembled !== 'undefined') {
results.push.apply(results, Array.from(disassembled));
continue;
}
}
results.push(char);
}
return results;
};
Vowel.disassembleFallingDiphthongToString = function (str) {
return this.disassembleFallingDiphthong(str).join('');
};
Vowel.disassembleRisingDiphthong = function (str) {
var results = [];
var length = str.length;
for (var i = 0; i < length; ++i) {
var char = str.charAt(i);
if (risingJDiphthongDisassembleMap.has(char)) {
var disassembled = risingJDiphthongDisassembleMap.get(char);
if (typeof disassembled !== 'undefined') {
results.push.apply(results, Array.from(disassembled));
continue;
}
}
if (risingWDiphthongDisassembleMap.has(char)) {
var disassembled = risingWDiphthongDisassembleMap.get(char);
if (typeof disassembled !== 'undefined') {
results.push.apply(results, Array.from(disassembled));
continue;
}
}
results.push(char);
}
return results;
};
Vowel.disassembleRisingDiphthongToString = function (str) {
return this.disassembleRisingDiphthong(str).join('');
};
Vowel.isVowelCharCode = function (charCode) {
return charCode >= VOWEL.START_CHAR_CODE && charCode <= VOWEL.END_CHAR_CODE;
};
/**
* 주어진 문자가 모음인지 확인합니다.
*
* Checks if the given character is a vowel.
*
* @param char - 검사할 단일 문자
* @param char - The single character to check
* @returns 모음이면 true, 아니면 false
* @returns true if the character is a vowel, otherwise false
*/
Vowel.isVowel = function (char) {
return this.isVowelCharCode(char.charCodeAt(0));
};
/**
* 주어진 문자열의 모든 문자가 모음인지 확인합니다.
*
* Checks if all characters in the given string are vowels.
*
* @param str - 검사할 문자열
* @param str - The string to check
* @returns 문자열의 모든 문자가 모음이면 true, 아니면 false
* @returns true if all characters in the string are vowels, otherwise false
*/
Vowel.isVowelAll = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (!this.isVowelCharCode(str.charCodeAt(i))) {
return false;
}
}
return true;
};
/**
* 주어진 문자열에 하나 이상의 모음이 포함되어 있는지 확인합니다.
*
* Checks if the given string contains at least one vowel.
*
* @param str - 검사할 문자열
* @param str - The string to check
* @returns 모음이 하나라도 있으면 true, 없으면 false
* @returns true if there is at least one vowel, otherwise false
*/
Vowel.hasVowel = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (this.isVowelCharCode(str.charCodeAt(i))) {
return true;
}
}
return false;
};
Vowel.isBasicVowelCharCode = function (charCode) {
return basicVowelCharCodeSet.has(charCode);
};
Vowel.isBasicVowel = function (char) {
return basicVowelSet.has(char);
};
Vowel.isBasicVowelAll = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (!this.isBasicVowelCharCode(str.charCodeAt(i))) {
return false;
}
}
return true;
};
Vowel.hasBasicVowel = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (this.isBasicVowelCharCode(str.charCodeAt(i))) {
return true;
}
}
return false;
};
Vowel.isComplexVowelCharCode = function (charCode) {
return complexVowelCharCodeSet.has(charCode);
};
Vowel.isComplexVowel = function (char) {
return complexVowelSet.has(char);
};
Vowel.isComplexVowelAll = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (!this.isComplexVowelCharCode(str.charCodeAt(i))) {
return false;
}
}
return true;
};
Vowel.hasComplexVowel = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (this.isComplexVowelCharCode(str.charCodeAt(i))) {
return true;
}
}
return false;
};
Vowel.isFallingDiphthongCode = function (charCode) {
return fallingDiphthongCharCodeSet.has(charCode);
};
Vowel.isFallingDiphthong = function (char) {
return fallingDiphthongSet.has(char);
};
Vowel.isFallingDiphthongAll = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (!this.isFallingDiphthongCode(str.charCodeAt(i))) {
return false;
}
}
return true;
};
Vowel.hasFallingDiphthong = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (this.isFallingDiphthongCode(str.charCodeAt(i))) {
return true;
}
}
return false;
};
Vowel.isRisingJDiphthongCode = function (charCode) {
return risingJDiphthongCharCodeSet.has(charCode);
};
Vowel.isRisingJDiphthong = function (char) {
return risingJDiphthongSet.has(char);
};
Vowel.isRisingJDiphthongAll = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (!this.isRisingJDiphthongCode(str.charCodeAt(i))) {
return false;
}
}
return true;
};
Vowel.hasRisingJDiphthong = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (this.isRisingJDiphthongCode(str.charCodeAt(i))) {
return true;
}
}
return false;
};
Vowel.isRisingWDiphthongCode = function (charCode) {
return risingWDiphthongCharCodeSet.has(charCode);
};
Vowel.isRisingWDiphthong = function (char) {
return risingWDiphthongSet.has(char);
};
Vowel.isRisingWDiphthongAll = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (!this.isRisingWDiphthongCode(str.charCodeAt(i))) {
return false;
}
}
return true;
};
Vowel.hasRisingWDiphthong = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (this.isRisingWDiphthongCode(str.charCodeAt(i))) {
return true;
}
}
return false;
};
Vowel.isRisingDiphthongCode = function (charCode) {
return this.isRisingJDiphthongCode(charCode) || this.isRisingWDiphthongCode(charCode);
};
Vowel.isRisingDiphthong = function (char) {
return this.isRisingJDiphthong(char) || this.isRisingWDiphthong(char);
};
Vowel.isRisingDiphthongAll = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (!this.isRisingJDiphthongCode(str.charCodeAt(i)) && !this.isRisingWDiphthongCode(str.charCodeAt(i))) {
return false;
}
}
return true;
};
Vowel.hasRisingDiphthong = function (str) {
var length = str.length;
if (length === 0) {
return false;
}
for (var i = 0; i < length; ++i) {
if (this.isRisingJDiphthongCode(str.charCodeAt(i)) || this.isRisingWDiphthongCode(str.charCodeAt(i))) {
return true;
}
}
return false;
};
return Vowel;
}());
export { Vowel };