sindresorhus / string-width

Get the visual width of a string - the number of columns required to display it
MIT License
476 stars 31 forks source link

Japanese half-width kana dakuten(゙) and han-dakuten(゚) are not counted. #55

Open sinbino opened 8 months ago

sinbino commented 8 months ago

Japanese half-width kana dakuten(゙) and han-dakuten(゚) are not counted.

import stringWidth from 'string-width'
console.log(stringWidth('バ')) // => 1
console.log(stringWidth('パ')) // => 1

Since dakuten(゙) and han-dakuten(゚) actually have width, these results should be 2.

fabiospampinato commented 7 months ago

@sindresorhus FWIW with my approach of stripping \p{M} characters these test cases seem to pass instead.

fabiospampinato commented 7 months ago

It's interesting actually because if Intl.Segmenter is the best way to do this, and Intl.Segmenter sees that as a single segment, what else is missing that would allow us to account for this use case correctly? And once we know what the other missing ingredients are what useful thing is Intl.Segmenter actually doing for us here? 🤔

Like from this example it seems like we don't actually care about "graphemes", and that seems the most granular thing that Intl.Segmenter can segment.