Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kanawana

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kanawana

Utility library for transliterating between Japanese and English writing systems.

  • 2.2.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19
increased by533.33%
Maintainers
1
Weekly downloads
 
Created
Source
NPM package Build Status Test Coverage

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

Javascript utility library for checking and converting between Kanji, Hiragana, Katakana, and Romaji

Demo

kaniwani.github.io/KanaWana/demo

Documentation

kaniwani.github.io/KanaWana/docs

Install

npm install kanawana
# or yarn add kanawana

Quick Use

HTML:

<input type="text" id="kanawana-input" />
<script src="node_modules/kanawana/browser/kanawana.min.js"></script>
<script>
  const textInput = document.querySelector('#kanawana-input');
  kanawana.bind(textInput); // IME Mode
</script>

JavaScript:

// UMD/CommonJS/node
const kw = require('kanawana');
// ES modules

import kw from 'kanawana';
// or single methods
import { toKana } from 'kanawana';
// or directly reference single methods for smaller builds:
import isKanji from 'kanawana/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,
}

/*** DOM HELPERS ***/

// Automatically converts to kana using an eventListener on input
// Uses { IMEMode:true } by default (first example on the demo page)
kw.bind(domElement [, options]);

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


/*** TEXT CHECKING UTILITIES ***/

kw.isJapanese('泣き虫。!〜') // Full-width punctuation allowed
// => true
kw.isJapanese('泣き虫.!~') // Half-width / Latin punctuation fails
// => false

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

kw.isHiragana('げーむ')
// => true

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

kw.isKanji('切腹')
// => true

kw.isMixed('お腹A')
// => true

kw.isRomaji('Tōkyō and Ōsaka') // allows basic Hepburn romanisation
// => true

/* kana conversion notes:
 * Lowercase -> Hiragana, uppercase -> Katakana.
 * Non-romaji and _English_ punctuation is passed through: 123 @#$%
 * Japanese equivalent punctuation is converted:
 * !?.:/,~-‘’“”[](){}
 * !?。:・、〜ー「」『』[](){}
 */
kw.toKana('ONAJI buttsuuji')
// => 'オナジ ぶっつうじ'
kw.toKana('座禅‘zazen’スタイル')
// => '座禅「ざぜん」スタイル'
kw.toKana('batsuge-mu')
// => 'ばつげーむ'

kw.toHiragana('toukyou, オオサカ')
// => 'とうきょう、 おおさか'
kw.toHiragana('only カナ', { passRomaji: true })
// => 'only かな'
kw.toHiragana('wi', { useObsoleteKana: true })
// => 'ゐ'

kw.toKatakana('toukyou, おおさか')
// => 'トウキョウ、 オオサカ'
kw.toKatakana('only かな', { passRomaji: true })
// => 'only カナ'
kw.toKatakana('wi', { useObsoleteKana: true })
// => 'ヰ'

kw.toRomaji('ひらがな カタカナ')
// => "hiragana katakana"
kw.toRomaji('ひらがな カタカナ', { upcaseKatakana: true })
// => "hiragana KATAKANA"


/*** EXTRA UTILITIES ***/

kw.stripOkurigana('お祝い')
// => 'お祝'
kw.stripOkurigana('踏み込む')
// => '踏み込'
kw.stripOkurigana('踏み込む', { all: true })
// => '踏込'

kw.tokenize('ふふフフ')
// => ['ふふ', 'フフ']
kw.tokenize('感じ')
// => ['感', 'じ']
kw.tokenize('I said "私は悲しい"')
// => ['I said "','私', 'は', '悲', 'しい', '"']

Credits

Adapted from the WanaKana Project sponsored by Tofugu & WaniKani

License

This project is licensed under the MIT license, Copyright (c) 2013 WaniKani Community Github. For more information see LICENSE file.

Keywords

FAQs

Package last updated on 21 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc