@spotxyz/hangul-romanization
Version:
Romanizes Hangul (Korean) characters
33 lines (32 loc) • 1.63 kB
JavaScript
;
/**
* @license MIT Copyright 2016 Daniel Imms (http://www.growingwiththeweb.com)
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.convert = void 0;
const revisedRomanizationOfKorean_1 = require("./conversionSystems/revisedRomanizationOfKorean");
const UNICODE_OFFSET = 44032;
const UNICODE_MAX = 55215;
function convertCharacter(char) {
const charCode = char.charCodeAt(0);
const isHangul = charCode >= UNICODE_OFFSET && charCode < UNICODE_MAX;
if (isHangul) {
let unicodeOffset = charCode - UNICODE_OFFSET;
const trailerOffset = unicodeOffset % revisedRomanizationOfKorean_1.REVISED_ROMANIZATION_OF_KOREAN.consonants.final.length;
unicodeOffset -= trailerOffset;
unicodeOffset /= revisedRomanizationOfKorean_1.REVISED_ROMANIZATION_OF_KOREAN.consonants.final.length;
const vowelOffset = unicodeOffset % revisedRomanizationOfKorean_1.REVISED_ROMANIZATION_OF_KOREAN.vowels.length;
unicodeOffset -= vowelOffset;
unicodeOffset /= revisedRomanizationOfKorean_1.REVISED_ROMANIZATION_OF_KOREAN.vowels.length;
const leadOffset = unicodeOffset;
const result = revisedRomanizationOfKorean_1.REVISED_ROMANIZATION_OF_KOREAN.consonants.initial[leadOffset]
+ revisedRomanizationOfKorean_1.REVISED_ROMANIZATION_OF_KOREAN.vowels[vowelOffset]
+ revisedRomanizationOfKorean_1.REVISED_ROMANIZATION_OF_KOREAN.consonants.final[trailerOffset];
return result;
}
return char;
}
function convert(text) {
return text.split('').map(convertCharacter).join('');
}
exports.convert = convert;