tohiragana
v1.0.0
Published
Convert Japanese (Kanji/Katakana) and English text to Hiragana. Zero API keys required.
Maintainers
Readme
tohiragana
Convert Japanese (Kanji / Katakana) and English text to Hiragana. Zero API keys required.
Installation
npm install tohiraganaQuick Start
const { ToHiragana } = require('tohiragana');
const converter = new ToHiragana();
await converter.init(); // Initialize the morphological analyzer (one-time)
// Japanese → Hiragana
await converter.fromJapanese('漢字を入力'); // => 'かんじをにゅうりょく'
await converter.fromJapanese('カタカナ'); // => 'かたかな'
// English → Japanese meaning → Hiragana
await converter.fromEnglishTranslate('Apple'); // => 'りんご'
// English pronunciation → Hiragana (synchronous, no init needed)
converter.fromEnglishPhonetic('Apple'); // => 'あっぷる'API Reference
new ToHiragana()
Creates a new converter instance.
converter.init(): Promise<void>
Initializes the internal morphological analyzer (kuromoji).
Must be called once before using fromJapanese() or fromEnglishTranslate().
converter.isReady: boolean
Returns true if init() has completed.
converter.fromJapanese(text): Promise<string>
Converts Japanese text (Kanji, Katakana, or mixed) to Hiragana.
await converter.fromJapanese('東京タワー'); // => 'とうきょうたわー'converter.fromEnglishTranslate(text): Promise<string>
Translates English text to Japanese and returns it in Hiragana. Uses the free Google Translate endpoint (no API key required).
await converter.fromEnglishTranslate('Good morning'); // => 'おはようございます'converter.fromEnglishPhonetic(text): string
Converts English text to its Japanese phonetic representation in Hiragana.
This is a synchronous method — no init() required.
converter.fromEnglishPhonetic('Coffee'); // => 'こっふぇえ'converter.convert(text, options?): Promise<string>
Auto-detect or specify conversion mode.
// Auto-detect (default)
await converter.convert('漢字'); // => 'かんじ'
await converter.convert('Hello'); // => translated to Japanese hiragana
// Explicit mode
await converter.convert('Apple', { mode: 'translate' }); // => 'りんご'
await converter.convert('Apple', { mode: 'phonetic' }); // => 'あっぷる'
await converter.convert('漢字', { mode: 'japanese' }); // => 'かんじ'Modes: 'auto' (default), 'japanese', 'translate', 'phonetic'
ToHiragana.katakanaToHiragana(str): string
Static utility. Converts all Katakana characters in a string to Hiragana.
ToHiragana.katakanaToHiragana('カタカナ'); // => 'かたかな'License
MIT
