npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

kuroshiro

0.2.1 • Public • Published

kuroshiro.js

kuroshiro.js

Build Status Coverage Status npm version Bower version

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:

// when using JavaScript
const kuroshiro = require("kuroshiro");
// when using TypeScript
import * as kuroshiro from '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

install

npm i kuroshiro

Downloadsweekly downloads

146

version

0.2.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability