Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tabulation returns with zero #45

Open
seachicken opened this issue Oct 17, 2022 · 2 comments
Open

tabulation returns with zero #45

seachicken opened this issue Oct 17, 2022 · 2 comments

Comments

@seachicken
Copy link
Contributor

Tabs have a display width in many outputs, but they return zeros, which is not intuitive.
stringWidth('\t') // -> 0
Incidentally, a function slightly similar to this library is Excel's LENB function, which counts tabs as 1.

@sindresorhus
Copy link
Owner

This will be fixed by #35.

@seachicken
Copy link
Contributor Author

Intl.Segmenter seems useful 😃

const segmenter = new Intl.Segmenter('en', {granularity: 'grapheme'});
console.log([...segmenter.segment('ax\u0300\t')]);
/** output:
(3) [{…}, {…}, {…}]
 0: {segment: 'a', index: 0, input: 'ax̀\t'}
 1: {segment: 'x̀', index: 1, input: 'ax̀\t'}
 2: {segment: '\t', index: 3, input: 'ax̀\t'}
 length: 3
**/

My understanding is that we can segment with it, but do you still need to determine with this library if tabs (0x9) count?

if (codePoint <= 0x1F || (codePoint >= 0x7F && codePoint <= 0x9F)) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants