echamudi / japanese-toolkit

Monorepo for Kanji, Furigana, Japanese DB, and others
44 stars 3 forks source link

"Halfwidth and Fullwidth Forms" character support #45

Open e-e opened 1 year ago

e-e commented 1 year ago

I just want to say this collection of packages is really great.

I ran into an issue with the following:

fit("RIP", "アールアイピー")

w: currentObj.w + chunk.w,
                        ^

TypeError: Cannot read properties of undefined (reading 'w')

I haven't dug too far into the code, but wondering if this is intended to be supported? Using the kyarakuta package, the characters are in the "Halfwidth and Fullwidth Forms", "Fullwidth ASCII variants" sub-block.

I would be willing to try adding support for this. My first thought would be that for input text that contains only the Halfwidth/Fullwidth characters, the reading would just apply to the entire string. But if you have any suggestions/ideas that would be helpful!

echamudi commented 1 year ago

Hey, thanks for checking the package!

Unfortunately, it's a known bug. I've added this bug in the end of the test file during the development. I had plans to fix it, but I haven't got a chance to further develop this package.

Yeah, the ideal partition would be R[アール] I[アイ] P[ピー]. But if those correlations are not inside the kanji package, then the next best guess should be just simply RIP[アールアイピー].

Interestingly, this input console.log(fit('私はRIPです', 'わたしはアールアイピーです')); actually outputs 私[わたし]は RIP[アールアイピー]です. So, a little tweak in the code will fix this issue I guess.

I'd be happy to merge your PR for this bug fix!