Visit the website to see WanaKana in action.
yarn add wanakana
# alternatively: npm install wanakana
<input type="text" id="wanakana-input" autocapitalize="none" />
<script src="node_modules/wanakana/lib/wanakana.min.js"></script>
<script>
const textInput = document.querySelector('#wanakana-input');
wanakana.bind(textInput); // uses IMEMode toKana() as default
</script>
/* UMD/CommonJS */
const wanakana = require('wanakana');
/* ES modules */
import wanakana from 'wanakana';
// with destructuring
import { toKana, isRomaji } from 'wanakana';
// or directly reference single methods for smaller builds:
import isKanji from 'wanakana/isKanji';
/*** DEFAULT OPTIONS ***/
{
// Use obsolete kana characters, such as ゐ and ゑ.
useObsoleteKana: false,
// Pass through romaji when using toKatakana() or toHiragana()
passRomaji: false,
// Convert katakana to uppercase when using toRomaji()
upcaseKatakana: false,
// Convert characters from a text input while being typed.
IMEMode: false, // alternatives are: true, 'toHiragana', or 'toKatakana'
}
/*** DOM HELPERS ***/
// Automatically converts text using an eventListener on input
// bind() uses option: { IMEMode: true } with `toKana()` by default
// Alternatives are: 'toHiragana' or 'toKatakana' to enforce kana type
wanakana.bind(domElement [, options]);
// Removes event listener
wanakana.unbind(domElement);
/*** TEXT CHECKING UTILITIES ***/
wanakana.isJapanese('泣き虫。!〜2¥')
// => true
wanakana.isKana('あーア')
// => true
wanakana.isHiragana('げーむ')
// => true
wanakana.isKatakana('ゲーム')
// => true
wanakana.isKanji('切腹')
// => true
wanakana.isMixed('お腹A')
// => true
wanakana.isRomaji('Tōkyō and Ōsaka')
// => true
/*
* toKana notes:
* Lowercase -> Hiragana.
* Uppercase -> Katakana.
* Non-romaji and _English_ punctuation is passed through: 123 @#$%
* Limited Japanese equivalent punctuation is converted:
* !?.:/,~-‘’“”[](){}
* !?。:・、〜ー「」『』[](){}
*/
wanakana.toKana('ONAJI buttsuuji')
// => 'オナジ ぶっつうじ'
wanakana.toKana('座禅‘zazen’スタイル')
// => '座禅「ざぜん」スタイル'
wanakana.toKana('batsuge-mu')
// => 'ばつげーむ'
wanakana.toHiragana('toukyou, オオサカ')
// => 'とうきょう、 おおさか'
wanakana.toHiragana('only カナ', { passRomaji: true })
// => 'only かな'
wanakana.toHiragana('wi', { useObsoleteKana: true })
// => 'ゐ'
wanakana.toKatakana('toukyou, おおさか')
// => 'トウキョウ、 オオサカ'
wanakana.toKatakana('only かな', { passRomaji: true })
// => 'only カナ'
wanakana.toKatakana('wi', { useObsoleteKana: true })
// => 'ヰ'
wanakana.toRomaji('ひらがな カタカナ')
// => 'hiragana katakana'
wanakana.toRomaji('ひらがな カタカナ', { upcaseKatakana: true })
// => 'hiragana KATAKANA'
/*** EXTRA UTILITIES ***/
wanakana.stripOkurigana('お祝い')
// => 'お祝'
wanakana.stripOkurigana('踏み込む')
// => '踏み込'
wanakana.stripOkurigana('踏み込む', { all: true })
// => '踏込'
wanakana.tokenize('ふふフフ')
// => ['ふふ', 'フフ']
wanakana.tokenize('感じ')
// => ['感', 'じ']
wanakana.tokenize('I said "私は悲しい"')
// => ['I said "','私', 'は', '悲', 'しい', '"']
Please see CONTRIBUTING.md
- Mims H. Wright – Author
- Duncan Bay – Author
- James McNamee – Contributor
Project sponsored by Tofugu & WaniKani
The following are ports created by the community:
- Java (MasterKale/WanaKanaJava)