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

Add ambiguousIsNarrow option #34

Merged
merged 7 commits into from
Jan 9, 2022
Merged

Conversation

seachicken
Copy link
Contributor

Resolves #1

I switched to this library which can resolve ambiguous characters.
In East Asian legacy character encodings (e.g. Japanese environment), ambiguous characters are resolved as full-width by default. We can set the option to make them half-width characters.

Comment on lines -33 to -35
// Surrogates
if (codePoint > 0xFFFF) {
index++;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surrogate pairs have already been solved here

index.js Outdated
@@ -1,8 +1,8 @@
import stripAnsi from 'strip-ansi';
import isFullwidthCodePoint from 'is-fullwidth-code-point';
import eaw from 'eastasianwidth';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import eaw from 'eastasianwidth';
import eastAsianWidth from 'eastasianwidth';

index.d.ts Outdated
@@ -17,4 +17,8 @@ stringWidth('\u001B[1m古\u001B[22m');
//=> 2
```
*/
export default function stringWidth(string: string): number;
export interface Options {
ambiguousIsNarrow: boolean;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sindresorhus sindresorhus changed the title Add ambiguousIsNarrow option Add ambiguousIsNarrow option Dec 31, 2021
index.d.ts Outdated Show resolved Hide resolved
index.js Outdated
width += 2;
break;
case 'A':
width += options.ambiguousIsNarrow ? 1 : 2;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options.ambiguousIsNarrow ? 1 : 2 should be moved out of the loop, into a variable.

@sindresorhus sindresorhus merged commit 8438ea2 into sindresorhus:main Jan 9, 2022
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

Successfully merging this pull request may close these issues.

Add option to let users decide if ambiguous width characters should be 1 or 2 in width
2 participants