-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8158802
commit cec9757
Showing
8 changed files
with
43 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
declare const stringWidth: { | ||
/** | ||
Get the visual width of a string - the number of columns required to display it. | ||
/** | ||
Get the visual width of a string - the number of columns required to display it. | ||
Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width. | ||
Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width. | ||
@example | ||
``` | ||
import stringWidth = require('string-width'); | ||
@example | ||
``` | ||
import stringWidth from 'string-width'; | ||
stringWidth('a'); | ||
//=> 1 | ||
stringWidth('a'); | ||
//=> 1 | ||
stringWidth('古'); | ||
//=> 2 | ||
stringWidth('古'); | ||
//=> 2 | ||
stringWidth('\u001B[1m古\u001B[22m'); | ||
//=> 2 | ||
``` | ||
*/ | ||
(string: string): number; | ||
|
||
// TODO: remove this in the next major version, refactor the whole definition to: | ||
// declare function stringWidth(string: string): number; | ||
// export = stringWidth; | ||
default: typeof stringWidth; | ||
} | ||
|
||
export = stringWidth; | ||
stringWidth('\u001B[1m古\u001B[22m'); | ||
//=> 2 | ||
``` | ||
*/ | ||
export default function stringWidth(string: string): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {expectType} from 'tsd'; | ||
import stringWidth = require('.'); | ||
import stringWidth from './index.js'; | ||
|
||
expectType<number>(stringWidth('古')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters