tvdstaaij / kuroshiro.js

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

Read this in other languages: English, 简体中文.

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 (IPA 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

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

About

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

License:MIT License


Languages

Language:JavaScript 99.5%Language:HTML 0.5%