Skip to content

Commit 5b6b7ca

Browse files
committedDec 15, 2018
Require Node.js 6
1 parent 0bc308a commit 5b6b7ca

File tree

5 files changed

+32
-33
lines changed

5 files changed

+32
-33
lines changed
 

‎.gitattributes

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

‎.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: node_js
22
node_js:
3+
- '10'
34
- '8'
45
- '6'
5-
- '4'

‎index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ const stripAnsi = require('strip-ansi');
33
const isFullwidthCodePoint = require('is-fullwidth-code-point');
44
const emojiRegex = require('emoji-regex')();
55

6-
module.exports = str => {
7-
str = str.replace(emojiRegex, ' ');
6+
module.exports = input => {
7+
input = input.replace(emojiRegex, ' ');
88

9-
if (typeof str !== 'string' || str.length === 0) {
9+
if (typeof input !== 'string' || input.length === 0) {
1010
return 0;
1111
}
1212

13-
str = stripAnsi(str);
13+
input = stripAnsi(input);
1414

1515
let width = 0;
1616

17-
for (let i = 0; i < str.length; i++) {
18-
const code = str.codePointAt(i);
17+
for (let i = 0; i < input.length; i++) {
18+
const code = input.codePointAt(i);
1919

2020
// Ignore control characters
2121
if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {

‎package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=4"
13+
"node": ">=6"
1414
},
1515
"scripts": {
1616
"test": "xo && ava"
@@ -47,10 +47,10 @@
4747
"dependencies": {
4848
"emoji-regex": "^7.0.1",
4949
"is-fullwidth-code-point": "^2.0.0",
50-
"strip-ansi": "^4.0.0"
50+
"strip-ansi": "^5.0.0"
5151
},
5252
"devDependencies": {
53-
"ava": "*",
54-
"xo": "*"
53+
"ava": "^1.0.1",
54+
"xo": "^0.23.0"
5555
}
5656
}

‎test.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import test from 'ava';
2-
import m from '.';
2+
import stringWidth from '.';
33

44
test('main', t => {
5-
t.is(m('abcde'), 5);
6-
t.is(m('古池や'), 6);
7-
t.is(m('あいうabc'), 9);
8-
t.is(m('ノード.js'), 9);
9-
t.is(m('你好'), 4);
10-
t.is(m('안녕하세요'), 10);
11-
t.is(m('A\uD83C\uDE00BC'), 5, 'surrogate');
12-
t.is(m('\u001B[31m\u001B[39m'), 0);
13-
t.is(m('\u{231A}'), 2, '⌚ default emoji presentation character (Emoji_Presentation)');
14-
t.is(m('\u{2194}\u{FE0F}'), 2, '↔️ default text presentation character rendered as emoji');
15-
t.is(m('\u{1F469}'), 2, '👩 emoji modifier base (Emoji_Modifier_Base)');
16-
t.is(m('\u{1F469}\u{1F3FF}'), 2, '👩🏿 emoji modifier base followed by a modifier');
5+
t.is(stringWidth('abcde'), 5);
6+
t.is(stringWidth('古池や'), 6);
7+
t.is(stringWidth('あいうabc'), 9);
8+
t.is(stringWidth('ノード.js'), 9);
9+
t.is(stringWidth('你好'), 4);
10+
t.is(stringWidth('안녕하세요'), 10);
11+
t.is(stringWidth('A\uD83C\uDE00BC'), 5, 'surrogate');
12+
t.is(stringWidth('\u001B[31m\u001B[39m'), 0);
13+
t.is(stringWidth('\u{231A}'), 2, '⌚ default emoji presentation character (Emoji_Presentation)');
14+
t.is(stringWidth('\u{2194}\u{FE0F}'), 2, '↔️ default text presentation character rendered as emoji');
15+
t.is(stringWidth('\u{1F469}'), 2, '👩 emoji modifier base (Emoji_Modifier_Base)');
16+
t.is(stringWidth('\u{1F469}\u{1F3FF}'), 2, '👩🏿 emoji modifier base followed by a modifier');
1717
});
1818

1919
test('ignores control characters', t => {
20-
t.is(m(String.fromCharCode(0)), 0);
21-
t.is(m(String.fromCharCode(31)), 0);
22-
t.is(m(String.fromCharCode(127)), 0);
23-
t.is(m(String.fromCharCode(134)), 0);
24-
t.is(m(String.fromCharCode(159)), 0);
25-
t.is(m('\u001B'), 0);
20+
t.is(stringWidth(String.fromCharCode(0)), 0);
21+
t.is(stringWidth(String.fromCharCode(31)), 0);
22+
t.is(stringWidth(String.fromCharCode(127)), 0);
23+
t.is(stringWidth(String.fromCharCode(134)), 0);
24+
t.is(stringWidth(String.fromCharCode(159)), 0);
25+
t.is(stringWidth('\u001B'), 0);
2626
});
2727

2828
test('handles combining characters', t => {
29-
t.is(m('x\u0300'), 1);
29+
t.is(stringWidth('x\u0300'), 1);
3030
});

0 commit comments

Comments
 (0)
Please sign in to comment.