A lightweight JavaScript library to convert between Roumaji script and Japanese Kana.
- Convert Roumaji ↔ Hiragana/Katakana
- Convert Hiragana ↔ Katakana
- Support basic punctuation and digits
- Support both Hepburn romanization system and Nihon-Shiki (view notes on transliteration for more details)
npm install @tortaruga/kanajiImport the functions:
import {
toHiragana,
toKatakana,
toRoumaji,
hiraganaToKatakana,
katakanaToHiragana
} from '@tortaruga/kanaji';All functions take a string as input.
- Latin inputs support basic punctuation and digits.
- Japanese inputs support full-width punctuation and digits only.
The following punctuation and digits are supported in Roumaji input:
Digits: 0 1 2 3 4 5 6 7 8 9
Punctuation: , . - ! ?
The following full-width punctuation and digits are supported in Kana input:
Digits: 0 1 2 3 4 5 6 7 8 9
Punctuation: 、 。 - ! ?
toHiragana('Ohisashiburi desu!') // Output: おひさしぶりです!
toKatakana('resutoran') // Output: レストランtoRoumaji('にほんご を はなします か?'); // Output: nihongo wo hanashimasu ka?
toRoumaji('エート。。。'); // Output: eeto... hiraganaToKatakana('ありがとう'); // Output: アリガトウ
katakanaToHiragana('アリガトウ'); // Output: ありがとう This library supports both the Hepburn and Nihon-shiki romanization systems, with a few practical exceptions to reduce ambiguity:
-
Because the converter doesn't include a grammar parser,
はis always romanized as "ha" (never "wa"), including when used as a particle; to produceはwhen converting from roumaji, use "ha" ("wa" maps toわ). -
へis always romanized as "he" (never "e"), including when used as a particle; to produceへwhen converting from roumaji, use "he" ("e" maps toエ). -
the particle
をis always romanized as "wo" (never "o"); to produceをwhen converting from roumaji, use "wo" ("o" maps toお). -
Japanese text typically does not include spaces. Since the converter cannot recognize word boundaries, the romanized output will also omit spaces (unless provided in the kana input).
-
Only valid Japanese syllables will be converted. For foreign words, the converter cannot automatically adapt them into appropriate Japanese phonetic equivalents. You’ll need to manually adjust the input to match valid syllables (e.g., use "Makudonarudo" for "McDonald's").
-
When entering roumaji, use "ei" for long
esounds and "ou" for longosounds. -
Other long vowels are doubled: "aa", "ii", "uu". This avoids the need for macrons (e.g., ā, ī, ū, ē, ō), which are less convenient to type.
-
じ / ジis romanized as "ji", while ぢ / ヂ is romanized as "di". -
ず / ズis romanized as "zu", while づ / ヅ is romanized as "du".