WanaKana functions accept an optional DefaultOptions object to customize conversion behavior. These options are merged with the library's defaults.
Available Options
| Option | Type | Default | Description |
|---|
useObsoleteKana | boolean | false | Set to true to include obsolete characters like ゐ and ゑ in conversions. |
passRomaji | boolean | false | Set to true to leave romaji characters untouched when using toKatakana() or toHiragana() on mixed-script strings. |
convertLongVowelMark | boolean | true | Set to false to prevent the conversion of the katakana prolonged sound mark ー into extended vowels (e.g., in toHiragana()). |
upcaseKatakana | boolean | false | Set to true to convert katakana to uppercase when using toRomaji(). |
IMEMode | boolean or 'toHiragana' or 'toKatakana' | false | Enables handling for conversions while they are being typed (IME input). |
romanization | 'hepburn' | 'hepburn' | Selects the romanization map for toRomaji(). Currently only supports 'hepburn'. |
customKanaMapping | Record<string, string> | undefined | A custom mapping object that is merged with the default kana conversion. |
customRomajiMapping | Record<string, string> | undefined | A custom mapping object that is merged with the default romaji conversion. |
// Example: Using obsolete kana
toHiragana('we', { useObsoleteKana: true }); // => 'ゑ'
// Example: Passing romaji through
toHiragana('only convert the katakana: ヒラガナ', { passRomaji: true }); // => "only convert the katakana: ひらがな"
// Example: Preventing long vowel conversion
toHiragana('ラーメン', { convertLongVowelMark: false }); // => 'らーめん'
// Example: Uppercasing katakana in romaji
toRomaji('ひらがな カタカナ', { upcaseKatakana: true }); // => "hiragana KATAKANA"
// Example: Custom kana mapping
toKana('wanakana', { customKanaMapping: { na: 'に', ka: 'Bana' } }); // => 'わにBanaに'
// Example: Custom romaji mapping
toRomaji('つじぎり', { customRomajiMapping: { じ: 'zi', つ: 'tu', り: 'li' } }); // => 'tuzigili'