npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

kuroshiro

0.1.0 • Public • Published

kuroshiro.js

kuroshiro.js

Build Status Coverage Status npm version Bower version dependencies

kuroshiro.js is a japanese language utility mainly for converting Kanji-mixed sentence to Hiragana, Katakana or Romaji with furigana and okurigana modes supported. This project is inspired by kuromoji and wanakana.

Demo

You can check the demo here.

Usage

Node.js

Install with npm package manager:

npm install kuroshiro

Load the library:

var kuroshiro = require("kuroshiro");

Have fun:

kuroshiro.init(function (err) {
    // kuroshiro is ready
    var result = kuroshiro.convert('感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!');    
    console.log(result);
});

Browser

Install with Bower package manager:

bower install kuroshiro

In your HTML:

<script src="url/to/kuroshiro.js"></script>

Have fun with scripts below:

kuroshiro.init(function (err) {
  // kuroshiro is ready
  var result = kuroshiro.convert('感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!');    
  console.log(result);
});

API

init([options], [callback])

Initiate kuroshiro.js. You should call this function once before calling other functions.

Arguments

  • options - Optional An object with options. You can set dicPath (Dictionary Path) here.
  • callback - Optional A callback which is called when kuroshiro.js has been initiated, or an error occurs.

Examples

kuroshiro.init(function (err) {
    // kuroshiro.js is ready
    // do something
});

convert(str, [options])

Convert given string to target syllabary with options available

Arguments

  • str - A String to be converted.
  • options - Optional kuroshiro has several convert options as below.
Options Type Default Description
to String 'hiragana' Target syllabary [hiragana,katakana,romaji]
mode String 'normal' Convert mode [normal,spaced,okurigana,furigana]
delimiter_start String '(' Delimiter(Start)
delimiter_end String ')' Delimiter(End)

Examples

kuroshiro.convert('感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!', {mode:'okurigana', to:'hiragana'});
// output: 感(かん)じ取(と)れたら手(て)を繋(つな)ごう、重(かさ)なるのは人生(じんせい)のライン and レミリア最高(さいこう)!

toHiragana(str, [options])

Convert given string to hiragana with options just like function convert() with to option excluded.

toKatakana(str, [options])

Convert given string to katakana with options just like function convert() with to option excluded.

toRomaji(str, [options])

Convert given string to romaji with options just like function convert() with to option excluded.

toKana(input)

Convert Romaji to Kana using wanakana.

isHiragana(input)

Check if input is hiragana using wanakana.

isKatakana(input)

Check if input is katakana using wanakana.

isRomaji(input)

Check if input is romaji using wanakana.

isKanji(input)

Check if input is kanji.

hasHiragana(input)

Check if input has hiragana.

hasKatakana(input)

Check if input has katakana.

hasKanji(input)

Check if input has kanji.

License

MIT

install

npm i kuroshiro

Downloadsweekly downloads

160

version

0.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability