-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Conversation
// Surrogates | ||
if (codePoint > 0xFFFF) { | ||
index++; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a proper doc comment.
https://github.com/sindresorhus/typescript-definition-style-guide
ambiguousIsNarrow
option
index.js
Outdated
width += 2; | ||
break; | ||
case 'A': | ||
width += options.ambiguousIsNarrow ? 1 : 2; |
There was a problem hiding this comment.
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.
Co-authored-by: Sindre Sorhus <[email protected]>
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.