"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { toRomaji: () => toRomaji }); module.exports = __toCommonJS(src_exports); var import_normal_jp = require("@birchill/normal-jp"); var replacements = [ ["\u3042", "a"], ["\u3044", "i"], ["\u3046", "u"], ["\u3048", "e"], ["\u304A", "o"], ["\u304B", "ka"], ["\u304D", "ki"], ["\u304F", "ku"], ["\u3051", "ke"], ["\u3053", "ko"], ["\u304D\u3083", "kya"], ["\u304D\u3085", "kyu"], ["\u304D\u3087", "kyo"], ["\u3055", "sa"], ["\u3057", "shi"], ["\u3059", "su"], ["\u305B", "se"], ["\u305D", "so"], ["\u3057\u3083", "sha"], ["\u3057\u3085", "shu"], ["\u3057\u3087", "sho"], ["\u305F", "ta"], ["\u3061", "chi"], ["\u3064", "tsu"], ["\u3066", "te"], ["\u3068", "to"], ["\u3061\u3083", "cha"], ["\u3061\u3085", "chu"], ["\u3061\u3087", "cho"], ["\u306A", "na"], ["\u306B", "ni"], ["\u306C", "nu"], ["\u306D", "ne"], ["\u306E", "no"], ["\u306B\u3083", "nya"], ["\u306B\u3085", "nyu"], ["\u306B\u3087", "nyo"], ["\u306F", "ha"], ["\u3072", "hi"], ["\u3075", "fu"], ["\u3078", "he"], ["\u307B", "ho"], ["\u3072\u3083", "hya"], ["\u3072\u3085", "hyu"], ["\u3072\u3087", "hyo"], ["\u307E", "ma"], ["\u307F", "mi"], ["\u3080", "mu"], ["\u3081", "me"], ["\u3082", "mo"], ["\u307F\u3083", "mya"], ["\u307F\u3085", "myu"], ["\u307F\u3087", "myo"], ["\u3084", "ya"], ["\u3086", "yu"], ["\u3088", "yo"], ["\u3089", "ra"], ["\u308A", "ri"], ["\u308B", "ru"], ["\u308C", "re"], ["\u308D", "ro"], ["\u308A\u3083", "rya"], ["\u308A\u3085", "ryu"], ["\u308A\u3087", "ryo"], ["\u308F", "wa"], ["\u3090", "i"], ["\u3091", "e"], ["\u3092", "o"], ["\u3093", "n"], ["\u304C", "ga"], ["\u304E", "gi"], ["\u3050", "gu"], ["\u3052", "ge"], ["\u3054", "go"], ["\u304E\u3083", "gya"], ["\u304E\u3085", "gyu"], ["\u304E\u3087", "gyo"], ["\u3056", "za"], ["\u3058", "ji"], ["\u305A", "zu"], ["\u305C", "ze"], ["\u305E", "zo"], ["\u3058\u3083", "ja"], ["\u3058\u3085", "ju"], ["\u3058\u3087", "jo"], ["\u3060", "da"], ["\u3062", "ji"], ["\u3065", "zu"], ["\u3067", "de"], ["\u3069", "do"], ["\u3062\u3083", "ja"], ["\u3062\u3085", "ju"], ["\u3062\u3087", "jo"], ["\u3070", "ba"], ["\u3073", "bi"], ["\u3076", "bu"], ["\u3079", "be"], ["\u307C", "bo"], ["\u3073\u3083", "bya"], ["\u3073\u3085", "byu"], ["\u3073\u3087", "byo"], ["\u3071", "pa"], ["\u3074", "pi"], ["\u3077", "pu"], ["\u307A", "pe"], ["\u307D", "po"], ["\u3074\u3083", "pya"], ["\u3074\u3085", "pyu"], ["\u3074\u3087", "pyo"], // The following almost always appear in katakana, but well, people do crazy // stuff so let's handle them in hiragana too (and it makes handling this // easier too since we can just blindly convert everything to hiragana as // a pre-processing step). ["\u3044\u3043", "yi"], ["\u3044\u3047", "ye"], ["\u3046\u3041", "wa"], ["\u3046\u3043", "wi"], ["\u3046\u3045", "wu"], ["\u3046\u3047", "we"], ["\u3046\u3049", "wo"], ["\u3046\u3085", "wyu"], ["\u3094\u3041", "va"], ["\u3094\u3043", "vi"], ["\u3094", "vu"], ["\u3094\u3047", "ve"], ["\u3094\u3049", "vo"], ["\u3094\u3083", "vya"], ["\u3094\u3085", "vyu"], ["\u3094\u3043\u3047", "vye"], ["\u3094\u3087", "vyo"], ["\u304D\u3047", "kye"], ["\u304E\u3047", "gye"], ["\u304F\u3041", "kwa"], ["\u304F\u3043", "kwi"], ["\u304F\u3047", "kwe"], ["\u304F\u3049", "kwo"], ["\u304F\u308E", "kwa"], ["\u3050\u3041", "gwa"], ["\u3050\u3043", "gwi"], ["\u3050\u3047", "gwe"], ["\u3050\u3049", "gwo"], ["\u3050\u308E", "gwa"], ["\u3057\u3047", "she"], ["\u3058\u3047", "je"], ["\u3059\u3043", "si"], ["\u305A\u3043", "zi"], ["\u3061\u3047", "che"], ["\u3064\u3041", "tsa"], ["\u3064\u3043", "tsi"], ["\u3064\u3047", "tse"], ["\u3064\u3049", "tso"], ["\u3064\u3085", "tsyu"], ["\u3066\u3043", "ti"], ["\u3068\u3045", "tu"], ["\u3066\u3085", "tyu"], ["\u3067\u3043", "di"], ["\u3069\u3045", "du"], ["\u3067\u3085", "dyu"], ["\u306B\u3047", "nye"], ["\u3072\u3047", "hye"], ["\u3073\u3047", "bye"], ["\u3074\u3047", "pye"], ["\u3075\u3041", "fa"], ["\u3075\u3043", "fi"], ["\u3075\u3047", "fe"], ["\u3075\u3049", "fo"], ["\u3075\u3083", "fya"], ["\u3075\u3085", "fyu"], ["\u3075\u3043\u3047", "fye"], ["\u3075\u3087", "fyo"], ["\u307B\u3045", "hu"], ["\u307F\u3047", "mye"], ["\u308A\u3047", "rye"], ["\u3089\u309C", "la"], ["\u308A\u309C", "li"], ["\u308B\u309C", "lu"], ["\u308C\u309C", "le"], ["\u308D\u309C", "lo"], ["\u308A\u309C\u3083", "lya"], ["\u308A\u309C\u3085", "lyu"], ["\u308A\u309C\u3047", "lye"], ["\u308A\u309C\u3087", "lyo"], // These ones don't have hiragana equivalents, but these are basically for // マニアック anyway. ["\u30F7", "va"], ["\u30F8", "vi"], ["\u30F9", "ve"], ["\u30FA", "vo"], ["\u30FC", "-"], // Seriously maniac territory here ["\u309F", "yori"], ["\u30FF", "koto"] ]; var maxReplacementLength; var replacementMap; function toRomaji(kana) { if (!maxReplacementLength) { maxReplacementLength = Math.max(...replacements.map(([a]) => a.length)); } if (!replacementMap) { replacementMap = new Map(replacements); } const hiragana = (0, import_normal_jp.kanaToHiragana)(kana); let result = ""; let explosiveness = 0; const explode = () => { if (explosiveness) { result += "'".repeat(explosiveness); explosiveness = 0; } }; let i = 0; while (i < hiragana.length) { const firstCharCode = hiragana.charCodeAt(i); if (firstCharCode === 12387) { explosiveness++; i++; continue; } if (firstCharCode < 12353) { explode(); result += hiragana.substring(i, i + 1); i++; continue; } let substringLength = Math.max(maxReplacementLength, hiragana.length - i); while (substringLength) { const substring = hiragana.substring(i, i + substringLength); const replacement = replacementMap.get(substring); if (replacement) { if (explosiveness) { const initial = replacement[0] === "c" ? "t" : replacement[0]; result += initial.repeat(explosiveness); explosiveness = 0; } if (replacement.length === 1 && result && result[result.length - 1] === "n" && ["a", "e", "i", "o", "u"].includes(replacement)) { result += "-"; } result += replacement; break; } substringLength--; } if (!substringLength) { explode(); result += hiragana.substring(i, i + 1); substringLength = 1; } i += substringLength; } explode(); return result; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { toRomaji }); //# sourceMappingURL=index.cjs.map