File tree 4 files changed +65
-62
lines changed
4 files changed +65
-62
lines changed Original file line number Diff line number Diff line change 1
1
node_modules
2
+ yarn.lock
Original file line number Diff line number Diff line change
1
+ package-lock = false
Original file line number Diff line number Diff line change @@ -7,15 +7,20 @@ module.exports = str => {
7
7
return 0 ;
8
8
}
9
9
10
- let width = 0 ;
11
-
12
10
str = stripAnsi ( str ) ;
13
11
12
+ let width = 0 ;
13
+
14
14
for ( let i = 0 ; i < str . length ; i ++ ) {
15
15
const code = str . codePointAt ( i ) ;
16
16
17
- // Ignore control characters & combining characters
18
- if ( code <= 0x1F || ( code >= 0x7F && code <= 0x9F ) || ( code >= 0x300 && code <= 0x36F ) ) {
17
+ // Ignore control characters
18
+ if ( code <= 0x1F || ( code >= 0x7F && code <= 0x9F ) ) {
19
+ continue ;
20
+ }
21
+
22
+ // Ignore combining characters
23
+ if ( code >= 0x300 && code <= 0x36F ) {
19
24
continue ;
20
25
}
21
26
@@ -24,11 +29,7 @@ module.exports = str => {
24
29
i ++ ;
25
30
}
26
31
27
- if ( isFullwidthCodePoint ( code ) ) {
28
- width += 2 ;
29
- } else {
30
- width ++ ;
31
- }
32
+ width += isFullwidthCodePoint ( code ) ? 2 : 1 ;
32
33
}
33
34
34
35
return width ;
Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " string-width" ,
3
- "version" : " 2.1.0" ,
4
- "description" : " Get the visual width of a string - the number of columns required to display it" ,
5
- "license" : " MIT" ,
6
- "repository" : " sindresorhus/string-width" ,
7
- "author" : {
8
- "name" : " Sindre Sorhus" ,
9
- "email" : " sindresorhus@gmail.com" ,
10
- "url" : " sindresorhus.com"
11
- },
12
- "engines" : {
13
- "node" : " >=4"
14
- },
15
- "scripts" : {
16
- "test" : " xo && ava"
17
- },
18
- "files" : [
19
- " index.js"
20
- ],
21
- "keywords" : [
22
- " string" ,
23
- " str" ,
24
- " character" ,
25
- " char" ,
26
- " unicode" ,
27
- " width" ,
28
- " visual" ,
29
- " column" ,
30
- " columns" ,
31
- " fullwidth" ,
32
- " full-width" ,
33
- " full" ,
34
- " ansi" ,
35
- " escape" ,
36
- " codes" ,
37
- " cli" ,
38
- " command-line" ,
39
- " terminal" ,
40
- " console" ,
41
- " cjk" ,
42
- " chinese" ,
43
- " japanese" ,
44
- " korean" ,
45
- " fixed-width"
46
- ],
47
- "dependencies" : {
48
- "is-fullwidth-code-point" : " ^2.0.0" ,
49
- "strip-ansi" : " ^4.0.0"
50
- },
51
- "devDependencies" : {
52
- "ava" : " *" ,
53
- "xo" : " *"
54
- }
2
+ "name" : " string-width" ,
3
+ "version" : " 2.1.0" ,
4
+ "description" : " Get the visual width of a string - the number of columns required to display it" ,
5
+ "license" : " MIT" ,
6
+ "repository" : " sindresorhus/string-width" ,
7
+ "author" : {
8
+ "name" : " Sindre Sorhus" ,
9
+ "email" : " sindresorhus@gmail.com" ,
10
+ "url" : " sindresorhus.com"
11
+ },
12
+ "engines" : {
13
+ "node" : " >=4"
14
+ },
15
+ "scripts" : {
16
+ "test" : " xo && ava"
17
+ },
18
+ "files" : [
19
+ " index.js"
20
+ ],
21
+ "keywords" : [
22
+ " string" ,
23
+ " str" ,
24
+ " character" ,
25
+ " char" ,
26
+ " unicode" ,
27
+ " width" ,
28
+ " visual" ,
29
+ " column" ,
30
+ " columns" ,
31
+ " fullwidth" ,
32
+ " full-width" ,
33
+ " full" ,
34
+ " ansi" ,
35
+ " escape" ,
36
+ " codes" ,
37
+ " cli" ,
38
+ " command-line" ,
39
+ " terminal" ,
40
+ " console" ,
41
+ " cjk" ,
42
+ " chinese" ,
43
+ " japanese" ,
44
+ " korean" ,
45
+ " fixed-width"
46
+ ],
47
+ "dependencies" : {
48
+ "is-fullwidth-code-point" : " ^2.0.0" ,
49
+ "strip-ansi" : " ^4.0.0"
50
+ },
51
+ "devDependencies" : {
52
+ "ava" : " *" ,
53
+ "xo" : " *"
54
+ }
55
55
}
You can’t perform that action at this time.
0 commit comments