romanize-string
Version:
A fully typed, general-purpose utility for unidirectional string transliteration (non-Latin script => Latin script).
24 lines (23 loc) • 647 B
JavaScript
import { HANGUL_BLOCKS } from "../constants/unicode.js";
import { IntervalTree } from "./interval-tree.js";
export class HangulTree extends IntervalTree {
constructor() {
super();
Object.entries(HANGUL_BLOCKS).forEach(([block, { start, end }]) => {
super.insert(start, end, block);
});
}
isHangulChar(char) {
const code = char.charCodeAt(0);
return super.exists(code);
}
isHangul(str) {
for (const char of str) {
if (!this.isHangulChar(char)) {
return false;
}
}
return true;
}
}
export default HangulTree;