hangulx
Version:
Providing various utilities for Hangul
301 lines (300 loc) • 10.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Vowel = void 0;
var VOWEL_1 = require("./constants/VOWEL");
var basic_vowels_1 = require("./constants/vowel/basic-vowels");
var complex_vowels_1 = require("./constants/vowel/complex-vowels");
var falling_diphthong_1 = require("./constants/vowel/falling-diphthong");
var rising_j_diphthong_1 = require("./constants/vowel/rising-j-diphthong");
var rising_w_diphthong_1 = require("./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 (falling_diphthong_1.fallingDiphthongDisassembleMap.has(char)) {
var disassembled = falling_diphthong_1.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 (rising_j_diphthong_1.risingJDiphthongDisassembleMap.has(char)) {
var disassembled = rising_j_diphthong_1.risingJDiphthongDisassembleMap.get(char);
if (typeof disassembled !== 'undefined') {
results.push.apply(results, Array.from(disassembled));
continue;
}
}
if (rising_w_diphthong_1.risingWDiphthongDisassembleMap.has(char)) {
var disassembled = rising_w_diphthong_1.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_1.VOWEL.START_CHAR_CODE && charCode <= VOWEL_1.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 basic_vowels_1.basicVowelCharCodeSet.has(charCode);
};
Vowel.isBasicVowel = function (char) {
return basic_vowels_1.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 complex_vowels_1.complexVowelCharCodeSet.has(charCode);
};
Vowel.isComplexVowel = function (char) {
return complex_vowels_1.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 falling_diphthong_1.fallingDiphthongCharCodeSet.has(charCode);
};
Vowel.isFallingDiphthong = function (char) {
return falling_diphthong_1.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 rising_j_diphthong_1.risingJDiphthongCharCodeSet.has(charCode);
};
Vowel.isRisingJDiphthong = function (char) {
return rising_j_diphthong_1.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 rising_w_diphthong_1.risingWDiphthongCharCodeSet.has(charCode);
};
Vowel.isRisingWDiphthong = function (char) {
return rising_w_diphthong_1.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;
}());
exports.Vowel = Vowel;