japanese-furigana-normalize
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Japanese Furigana Normalize

npm

This package provides a utility function to normalize Japanese readings containing furigana. It is particularly useful for creating Yomitan dictionaries and ensuring the readings are properly aligned with the kanji characters.

Purpose

Let's say you have a term such as 喫茶ステラと死神の蝶 and its reading かふぇすてらとしにがみのちょう. The term contains the katakana ステラ, but the reading is in hiragana. So if you were to put this into a Yomitan dictionary, you would want to normalize the reading to かふぇステラとしにがみのちょう so that there is no unnecessary furigana on top of the katakana characters. This package handles this as well as other cases to ensure the readings are properly handled by Yomitan.

chrome_喫茶ステラと死神の蝶_-Yomitan_Search-_Google_Chrome_2024-02-09_15-41-31 chrome_Yomitan_Search_-喫茶ステラと死神の蝶-_Yomitan_Search_2024-02-09_15-45-00
chrome_アイザック・ニュートン_-Yomitan_Search-_Google_Chrome_2024-02-09_15-52-05 chrome_Yomitan_Search_-アイザック・ニュートン-_Yomitan_Search_2024-02-09_15-52-27
Before normalization After normalization

Installation

npm install japanese-furigana-normalize

Usage

The primary function provided by this package is normalizeReading(term: string, reading: string), which takes two parameters:

  • term: The term or phrase.
  • reading: The corresponding reading in hiragana.

The function normalizes the reading to match and align with the kanji characters present in the term.

For example:

import { normalizeReading } from 'japanese-furigana-normalize';

const term = '喫茶ステラと死神の蝶'; // Kanji term
const reading = 'かふぇすてらとしにがみのちょう'; // Hiragana reading
const normalizedReading = normalizeReading(term, reading);
console.log(normalizedReading); // Output: かふぇステラとしにがみのちょう

For more examples, you can refer to the normalizeReading.test.ts file.

Package Sidebar

Install

npm i japanese-furigana-normalize

Weekly Downloads

8

Version

1.0.3

License

MIT

Unpacked Size

39.6 kB

Total Files

38

Last publish

Collaborators

  • marvn