Skip to content
forked from WaniKani/WanaKana

Javascript library for detecting and transliterating Hiragana <--> Katakana <--> Romaji

License

Notifications You must be signed in to change notification settings

chooban/WanaKana

 
 

Repository files navigation

ワナカナ <--> WanaKana <--> わなかな

Javascript utility library for detecting and transliterating Hiragana, Katakana, and Romaji

Demo

Visit the website to see WanaKana in action.

Usage

Browser

Use the minified (UMD) bundle (with legacy browser polyfills)

https://unpkg.com/wanakana

<head>
  <meta charset="UTF-8">
  <script src="https://unpkg.com/wanakana"></script>
</head>
<body>
  <input type="text" id="wanakana-input" />
  <script>
    var textInput = document.getElementById('wanakana-input');
    wanakana.bind(textInput, /* options */); // uses IMEMode with toKana() as default
    // to remove event listeners: wanakana.unbind(textInput);
  </script>
</body>

Node

Install

npm install wanakana
import * as wanakana from 'wanakana';
// or
import { toKana, isRomaji } from 'wanakana';

Documentation

Extended API reference

Quick Reference

/*** DOM HELPERS ***/
// Automatically converts text using an eventListener on input
// Sets option: { IMEMode: true } with toKana() as converter by default
wanakana.bind(domElement [, options]);

// Removes event listener
wanakana.unbind(domElement);

/*** TEXT CHECKING UTILITIES ***/
wanakana.isJapanese('泣き虫。!〜2¥zenkaku')
// => true

wanakana.isKana('あーア')
// => true

wanakana.isHiragana('すげー')
// => true

wanakana.isKatakana('ゲーム')
// => true

wanakana.isKanji('切腹')
// => true
wanakana.isKanji('勢い')
// => false

wanakana.isRomaji('Tōkyō and Ōsaka')
// => true

wanakana.toKana('ONAJI buttsuuji')
// => 'オナジ ぶっつうじ'
wanakana.toKana('座禅‘zazen’スタイル')
// => '座禅「ざぜん」スタイル'
wanakana.toKana('batsuge-mu')
// => 'ばつげーむ'
wanakana.toKana('wanakana', { customKanaMapping: { na: 'に', ka: 'bana' }) });
// => 'わにbanaに'

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'
wanakana.toRomaji('つじぎり', { customRomajiMapping: { : 'zi', : 'tu', : 'li' }) };
// => 'tuzigili'

/*** EXTRA UTILITIES ***/
wanakana.stripOkurigana('お祝い')
// => 'お祝'
wanakana.stripOkurigana('踏み込む')
// => '踏み込'
wanakana.stripOkurigana('お腹', { leading: true });
// => '腹'
wanakana.stripOkurigana('ふみこむ', { matchKanji: '踏み込む' });
// => 'ふみこ'
wanakana.stripOkurigana('おみまい', { matchKanji: 'お祝い', leading: true });
// => 'みまい'

wanakana.tokenize('ふふフフ')
// => ['ふふ', 'フフ']
wanakana.tokenize('hello 田中さん')
// => ['hello', ' ', '田中', 'さん']
wanakana.tokenize('I said 私はすごく悲しい', { compact: true })
// => [ 'I said ', '私はすごく悲しい']

Important

Only the browser build via unpkg or wanakana/umd/*.js includes full polyfills for older browsers.

Contributing

Please see CONTRIBUTING.md

Contributors

Credits

Project sponsored by Tofugu & WaniKani

Ports

The following are ports created by the community:

About

Javascript library for detecting and transliterating Hiragana <--> Katakana <--> Romaji

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 91.8%
  • CSS 4.4%
  • HTML 3.8%