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 🙏

© 2024 – Pkg Stats / Ryan Hefner

furigana

v0.19.3

Published

Fit kana text into Japanese writing

Downloads

1,016

Readme

Furigana

Fit kana text into Japanese writing.



Demo

API

function fit(writingText: string, readingText: string): string | null;
  • writingText: The japanese writing. Currently, it only accepts kanji, kana, and numbers.

  • readingText: The reading of the inputted writing. Currently, it only accepts kana.

Examples

const { fit } = require('furigana');

console.log(fit('行っています', 'いっています'));
// 行[い]っています

console.log(fit('行っています', 'おこなっています'));
// 行[おこな]っています

console.log(fit('轟駅にいっています', 'どめきえきにいっています'));
// 轟[どめき] 駅[えき]にいっています

The function will guess the reading placement if the reading is not in the dictionary.

console.log(fit('一社長と四十物谷さんは武漢市に住んでいます', 'にのまえしゃちょうとあいものやさんはうーはんしにすんでいます'));
// 一[にのまえ] 社[しゃ] 長[ちょう]と 四[あ] 十[い] 物[もの] 谷[や]さんは 武[う] 漢[ーはん] 市[し]に 住[す]んでいます

console.log(fit('一社長と十先生', 'にのまえしゃちょうとつなしせんせい'));
// 一[にのまえ] 社[しゃ] 長[ちょう]と 十[つなし] 先[せん] 生[せい]

Pass { type: 'object' } for getting tokens instead of string:

console.log(fit('九段下', 'くだんした', { type: 'object' }));
// Output:
[
     { w: '九', r: 'く' },
     { w: '段', r: 'だん' },
     { w: '下', r: 'した' },
];

console.log(fit('勿来駅', 'なこそえき', { type: 'object' }));
// Output:
[
     { w: '勿来', r: 'なこそ' },
     { w: '駅', r: 'えき' },
];

Another input example with many of the readings don't exist in the dictionary:

fit(
    '安居院と生明と安栖と馬酔木と東奥と旦来と流井と行町と五百蔵',
    'あぐいとあざみとあずまいとあせびとあちおくとあっそとあらいとあるきまちといおろい',
    { type: 'object' },
)
// Output:
[
  { w: '安', r: 'あ' },
  { w: '居', r: 'ぐ' },
  { w: '院', r: 'い' }, // Guessed
  { w: 'と', r: 'と' },
  { w: '生', r: 'あざ' }, // Guessed
  { w: '明', r: 'み' },
  { w: 'と', r: 'と' },
  { w: '安', r: 'あ' },
  { w: '栖', r: 'ずまい' }, // Guessed
  { w: 'と', r: 'と' },
  { w: '馬酔木', r: 'あせび' }, // Guessed
  { w: 'と', r: 'と' },
  { w: '東', r: 'あち' }, // Guessed
  { w: '奥', r: 'おく'},
  { w: 'と', r: 'と' },
  { w: '旦来', r: 'あっそ' }, // Guessed
  { w: 'と', r: 'と' },
  { w: '流', r: 'あら' }, // Guessed
  { w: '井', r: 'い' },
  { w: 'と', r: 'と' },
  { w: '行', r: 'あるき' }, // Guessed
  { w: '町', r: 'まち' },
  { w: 'と', r: 'と' },
  { w: '五', r: 'い' },
  { w: '百', r: 'お' },
  { w: '蔵', r: 'ろい' } // Guessed
]

Use Case

This tool can be used when you have a list of Japanese writing and reading pairs and you want to link the readings to each character of the writings.

For example, the furigana column in the following table is generated from the strings in kanji and reading column by using this furigana tool.

Acknowledgements

  • This repo contains reading definitions from KANJIDIC.

    Copyright The Electronic Dictionary Research and Development Group

    Creative Commons Attribution-ShareAlike Licence (V3.0)

License

Copyright © 2020 Ezzat Chamudi

Furigana code is licensed under MPL-2.0. Images, logos, docs, and articles in this project are released under CC-BY-SA-4.0.

Libraries, dependencies, and tools used in this project are tied with their licenses.