npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

kuroshiro-enhance

v2.2.0

Published

kuroshiro is a Japanese language library for converting Japanese sentence to Hiragana, Katakana or Romaji with furigana and okurigana modes supported.

Readme

kuroshiro-enhance

npm version License

kuroshiro-enhance is a fork of the original kuroshiro for converting Japanese text to Hiragana, Katakana, or Romaji. It supports furigana, okurigana, multiple analyzers, and structured ruby output for custom rendering.

Demo: gene891212.github.io/kuroshiro-enhance

kuroshiro-enhance demo showing furigana output with Katakana ruby annotations

Highlights

Compared with the original kuroshiro, this fork adds structured ruby output and optional Katakana ruby annotations for custom furigana rendering.

| Feature | kuroshiro (original) | kuroshiro-enhance | | ------- | -------------------- | ----------------- | | Basic conversion (Hiragana / Katakana / Romaji) | ✓ | ✓ | | Furigana and okurigana modes | ✓ | ✓ | | Katakana ruby annotations | - | ✓ (includeKatakana) | | Structured ruby output | - | ✓ (furigana_segments) |

Table of Contents

Quick Start

Prerequisite: Node.js >= 18 is required for Node.js usage and local development.

Install the library and an analyzer plugin:

npm install kuroshiro-enhance kuroshiro-analyzer-kuromoji
# or
pnpm add kuroshiro-enhance kuroshiro-analyzer-kuromoji
# or
yarn add kuroshiro-enhance kuroshiro-analyzer-kuromoji

Recommended default analyzer: kuroshiro-analyzer-kuromoji.

Convert Japanese text with the Kuromoji analyzer. furigana mode returns an HTML string; render it as HTML in your UI if you want browser ruby display.

import Kuroshiro from "kuroshiro-enhance";
import KuromojiAnalyzer from "kuroshiro-analyzer-kuromoji";

const kuroshiro = new Kuroshiro();
await kuroshiro.init(new KuromojiAnalyzer());

const result = await kuroshiro.convert("感じ取れたら手を繋ごう", {
  to: "hiragana",
  mode: "furigana",
  includeKatakana: true,
});

console.log(result);
// <ruby>感<rp>(</rp><rt>かん</rt><rp>)</rp></ruby>じ<ruby>取<rp>(</rp><rt>と</rt><rp>)</rp></ruby>れたら<ruby>手<rp>(</rp><rt>て</rt><rp>)</rp></ruby>を<ruby>繋<rp>(</rp><rt>つな</rt><rp>)</rp></ruby>ごう

Use mode: "furigana_segments" when you need structured ruby data instead of HTML. It returns a flat array of segments that you can render with a single map, with no index bookkeeping:

const result = await kuroshiro.convert("古びたテディベア", {
  to: "hiragana",
  mode: "furigana_segments",
  includeKatakana: true,
});

console.log(result);
// [
//   { text: "古", ruby: "ふる" },
//   { text: "びた" },
//   { text: "テ", ruby: "て" },
//   { text: "デ", ruby: "で" },
//   ...
// ]

Rendering is a one-liner (React shown here); newlines come through as their own { text: "\n" } segments:

result.map((seg, i) =>
  seg.text === "\n" ? <br key={i} />
  : seg.ruby ? <ruby key={i}>{seg.text}<rt>{seg.ruby}</rt></ruby>
  : seg.text,
);

mode: "furigana_map" still works but is deprecated and will be removed in the next major version. See the convert options below for migration.

Usage

Browser

kuroshiro.min.js does not include analyzer plugins or dictionary files. In the browser, load both kuroshiro and an analyzer bundle, then pass the analyzer a dictPath.

Using CDN bundles:

<script src="https://unpkg.com/kuroshiro-enhance@latest/dist/kuroshiro.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/kuroshiro-analyzer-kuromoji.min.js"></script>

Using a local build:

npm install
npm run build

Then load the generated bundle and an analyzer bundle in your HTML:

<script src="dist/kuroshiro.min.js"></script>
<script src="url/to/kuroshiro-analyzer-kuromoji.min.js"></script>

Initialize kuroshiro with an analyzer instance:

const KuroshiroClass = window.Kuroshiro.default || window.Kuroshiro;
const kuroshiro = new KuroshiroClass();

kuroshiro
  .init(new KuromojiAnalyzer({ dictPath: "url/to/dictFiles" }))
  .then(function () {
    return kuroshiro.convert(
      "感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!",
      { to: "hiragana" },
    );
  })
  .then(function (result) {
    console.log(result);
  });

Node.js CommonJS

const Kuroshiro = require("kuroshiro-enhance").default;
const KuromojiAnalyzer = require("kuroshiro-analyzer-kuromoji");

(async () => {
  const kuroshiro = new Kuroshiro();
  await kuroshiro.init(new KuromojiAnalyzer());

  const result = await kuroshiro.convert(
    "感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!",
    { to: "hiragana" },
  );

  console.log(result);
})();

Analyzer Plugins

You should check the environment compatibility of each analyzer before you start working with them.

| Analyzer | Node.js Support | Browser Support | Plugin Repo | Developer | | ------------- | --------------- | --------------- | -------------------------------------------------------------------------------------------- | ------------------------------------- | | Kuromoji | ✓ | ✓ | kuroshiro-analyzer-kuromoji | Hexen Qi | | Mecab | ✓ | ✗ | kuroshiro-analyzer-mecab | Hexen Qi | | Yahoo Web API | ✓ | ✗ | kuroshiro-analyzer-yahoo-webapi | Hexen Qi |

API

Constructor

Examples

const kuroshiro = new Kuroshiro();

Instance Methods

init(analyzer)

Initialize kuroshiro with an analyzer instance. You can use one of the Analyzer Plugins listed above, or provide a custom analyzer that implements the same interface.

Arguments

  • analyzer - An instance of analyzer.

Examples

await kuroshiro.init(new KuromojiAnalyzer());

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, furigana_segments, furigana_map†] | | includeKatakana | boolean | false | In furigana, furigana_segments and furigana_map modes, also add ruby annotations to Katakana characters when true. | | romajiSystem* | String | "hepburn" | Romanization system [nippon, passport, hepburn] | | delimiter_start | String | "(" | Delimiter(Start) | | delimiter_end | String | ")" | Delimiter(End) |

*: Param romajiSystem is only applied when the value of param to is romaji. For more about it, check Romanization System

†: furigana_map is deprecated and will be removed in the next major version. Use furigana_segments instead — it returns easier-to-render data and covers the same cases. Calling furigana_map logs a one-time deprecation warning per instance.

Examples

// normal
await kuroshiro.convert(
  "感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!",
  { to: "hiragana" },
);
// result:かんじとれたらてをつなごう、かさなるのはじんせいのライン and レミリアさいこう!
// spaced
await kuroshiro.convert(
  "感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!",
  { to: "hiragana", mode: "spaced" },
);
// result:かんじとれ たら て を つなご う 、 かさなる の は じんせい の ライン   and   レミ リア さいこう !
// okurigana
await kuroshiro.convert(
  "感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!",
  { to: "hiragana", mode: "okurigana" },
);
// result: 感(かん)じ取(と)れたら手(て)を繋(つな)ごう、重(かさ)なるのは人生(じんせい)のライン and レミリア最高(さいこう)!
// furigana
await kuroshiro.convert(
  "感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!",
  { to: "hiragana", mode: "furigana" },
);
// result: <ruby>感<rp>(</rp><rt>かん</rt><rp>)</rp></ruby>じ<ruby>取<rp>(</rp><rt>と</rt><rp>)</rp></ruby>れたら<ruby>手<rp>(</rp><rt>て</rt><rp>)</rp></ruby>を<ruby>繋<rp>(</rp><rt>つな</rt><rp>)</rp></ruby>ごう、<ruby>重<rp>(</rp><rt>かさ</rt><rp>)</rp></ruby>なるのは<ruby>人生<rp>(</rp><rt>じんせい</rt><rp>)</rp></ruby>のライン and レミリア<ruby>最高<rp>(</rp><rt>さいこう</rt><rp>)</rp></ruby>!
// furigana_segments
await kuroshiro.convert("古びたテディベア", {
  to: "hiragana",
  mode: "furigana_segments",
  includeKatakana: true,
});
// result:
[
  { "text": "古", "ruby": "ふる" },
  { "text": "びた" },
  { "text": "テ", "ruby": "て" },
  { "text": "デ", "ruby": "で" },
  { "text": "ィ", "ruby": "ぃ" },
  { "text": "ベ", "ruby": "べ" },
  { "text": "ア", "ruby": "あ" }
]

Each entry is a FuriganaSegment:

  • text: A slice of the original input. Concatenating every text reproduces the input exactly.
  • ruby: The reading for that slice. Present only on segments that carry ruby (kanji, or katakana when includeKatakana is true); absent on plain text.

Newlines are emitted as their own ruby-less segments ({ text: "\n" }) and never merged into surrounding text, so you can map them straight to <br>.

// furigana_map (deprecated — use furigana_segments)
await kuroshiro.convert("古びたテディベア", {
  to: "hiragana",
  mode: "furigana_map",
  includeKatakana: true,
});
// result:
{
  "text": "古びたテディベア",
  "ruby": [
    { "s": 0, "e": 1, "rt": "ふる" },
    { "s": 3, "e": 4, "rt": "て" },
    { "s": 4, "e": 5, "rt": "で" },
    { "s": 5, "e": 6, "rt": "ぃ" },
    { "s": 6, "e": 7, "rt": "べ" },
    { "s": 7, "e": 8, "rt": "あ" }
  ]
}

In furigana_map results:

  • text: The original text.
  • ruby: Ruby annotation spans for text.
  • s: Start character index.
  • e: End character index, exclusive.
  • rt: Ruby text, or reading.

Utils

Examples

const result = Kuroshiro.Util.isHiragana("あ");

isHiragana(char)

Check if input char is hiragana.

isKatakana(char)

Check if input char is katakana.

isKana(char)

Check if input char is kana.

isKanji(char)

Check if input char is kanji.

isJapanese(char)

Check if input char is Japanese.

hasHiragana(str)

Check if input string has hiragana.

hasKatakana(str)

Check if input string has katakana.

hasKana(str)

Check if input string has kana.

hasKanji(str)

Check if input string has kanji.

hasJapanese(str)

Check if input string has Japanese.

kanaToHiragana(str)

Convert input kana string to hiragana.

The misspelled legacy name kanaToHiragna is kept as a deprecated alias and will be removed in the next major version.

kanaToKatakana(str)

Convert input kana string to katakana.

kanaToRomaji(str, system)

Convert input kana string to romaji. Param system accepts "nippon", "passport", "hepburn" (Default: "hepburn").

Romanization System

kuroshiro supports three kinds of romanization systems.

nippon: Nippon-shiki romanization. See ISO 3602 Strict for the reference table.

passport: Passport-shiki romanization. See the Japanese romanization table published by the Ministry of Foreign Affairs of Japan.

hepburn: Hepburn romanization. See BS 4812 : 1972 for the reference standard.

There is a useful webpage for you to check the difference between these romanization systems.

Notice for Romaji Conversion

It is impossible to fully automatically convert furigana directly to romaji because furigana lacks some pronunciation information. The article なぜ フリガナでは ダメなのか? explains the ambiguity.

kuroshiro will not handle chōon when processing directly furigana (kana) -> romaji conversion with every romanization system (Except that Chōonpu will be handled)

For example, you'll get "kousi", "koushi", "koushi" respectively when converts kana "こうし" to romaji using nippon, passport, hepburn romanization system.

The kanji -> romaji conversion with/without furigana mode is unaffected by this logic.

Breaking Changes

See CHANGELOG.md for version history.

Deprecations (still working, removed in the next major)

  • furigana_map mode → use furigana_segments. It returns a flat FuriganaSegment[] that renders without index bookkeeping and handles newlines. Calling furigana_map logs a one-time warning per instance.
  • Kuroshiro.Util.kanaToHiragna → use kanaToHiragana (the old name was missing an "a").

v2.x

  • Node.js Environment Requirement: Kuroshiro now requires Node.js >= 18.0.0.
  • CommonJS Require Syntax: Since the codebase outputs CommonJS through .cjs exports, standard CommonJS imports should use .default: const Kuroshiro = require("kuroshiro-enhance").default;
  • TypeScript Strictness: Type definitions are now bundled, so TypeScript users may see compiler errors for invalid options or parameters.

v1.x

  • Separated morphological analyzer logic from phonetic notation logic, allowing different analyzers from Analyzer Plugins or custom analyzers.
  • Embraced ES8/ES2017 and async/await.
  • Switched to ES Modules instead of CommonJS.

Contributing

Please check CONTRIBUTING.

Credits

License

MIT License