Skip to content

Commit d0d3ccb

Browse files
committedJul 18, 2017
Meta tweaks
1 parent 2af7be5 commit d0d3ccb

File tree

4 files changed

+65
-62
lines changed

4 files changed

+65
-62
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
yarn.lock

‎.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

‎index.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ module.exports = str => {
77
return 0;
88
}
99

10-
let width = 0;
11-
1210
str = stripAnsi(str);
1311

12+
let width = 0;
13+
1414
for (let i = 0; i < str.length; i++) {
1515
const code = str.codePointAt(i);
1616

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) {
1924
continue;
2025
}
2126

@@ -24,11 +29,7 @@ module.exports = str => {
2429
i++;
2530
}
2631

27-
if (isFullwidthCodePoint(code)) {
28-
width += 2;
29-
} else {
30-
width++;
31-
}
32+
width += isFullwidthCodePoint(code) ? 2 : 1;
3233
}
3334

3435
return width;

‎package.json

+53-53
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
{
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+
}
5555
}

0 commit comments

Comments
 (0)
Please sign in to comment.