New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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

JS library that transliterates between japanese kana and roman letters.

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source
devDependency Status Build Status Test Coverage

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

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

Demo

kaniwani.github.io/KanaWana/

Documentation

kaniwani.github.io/KanaWana/docs

Install

npm install kanawana
# or yarn add kanawana

Quick Use

const kw = require('kanawana');
// Or directly import single methods using ES6 for smaller builds:
// import toKana from 'kanawana/core/toKana';

/*** 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 romaji to kana by 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) 2016 Duncan Bay. For more information see LICENSE.md.

Keywords

FAQs

Package last updated on 10 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