Skip to content

Commit cf78036

Browse files
committedMar 3, 2019
Update dependencies and meta tweaks
1 parent c084e3e commit cf78036

File tree

3 files changed

+65
-66
lines changed

3 files changed

+65
-66
lines changed
 

‎index.js

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const exec = (string, columns, options = {}) => {
8383
if (options.trim !== false) {
8484
rows[rows.length - 1] = rows[rows.length - 1].trimLeft();
8585
}
86+
8687
let rowLength = stringWidth(rows[rows.length - 1]);
8788

8889
if (index !== 0) {
@@ -105,6 +106,7 @@ const exec = (string, columns, options = {}) => {
105106
if (breaksStartingNextLine < breaksStartingThisLine) {
106107
rows.push('');
107108
}
109+
108110
wrapWord(rows, word, columns);
109111
continue;
110112
}

‎package.json

+7-8
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@
4747
],
4848
"dependencies": {
4949
"ansi-styles": "^3.2.0",
50-
"string-width": "^2.1.1",
51-
"strip-ansi": "^4.0.0"
50+
"string-width": "^3.0.0",
51+
"strip-ansi": "^5.0.0"
5252
},
5353
"devDependencies": {
54-
"ava": "^0.25.0",
55-
"chalk": "^2.0.1",
56-
"coveralls": "^3.0.0",
54+
"ava": "^1.2.1",
55+
"chalk": "^2.4.2",
56+
"coveralls": "^3.0.3",
5757
"has-ansi": "^3.0.0",
58-
"nyc": "^13.0.1",
59-
"strip-ansi": "^4.0.0",
60-
"xo": "^0.22.0"
58+
"nyc": "^13.3.0",
59+
"xo": "^0.24.0"
6160
}
6261
}

‎test.js

+56-58
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import test from 'ava';
22
import chalk from 'chalk';
33
import hasAnsi from 'has-ansi';
44
import stripAnsi from 'strip-ansi';
5-
import m from '.';
5+
import wrapAnsi from '.';
66

77
chalk.enabled = true;
88

@@ -15,130 +15,128 @@ const fixture4 = '12345678\n';
1515
const fixture5 = '12345678\n ';
1616

1717
test('wraps string at 20 characters', t => {
18-
const res20 = m(fixture, 20);
18+
const result = wrapAnsi(fixture, 20);
1919

20-
t.is(res20, 'The quick brown \u001B[31mfox\u001B[39m\n\u001B[31mjumped over \u001B[39mthe lazy\n\u001B[32mdog and then ran\u001B[39m\n\u001B[32maway with the\u001B[39m\n\u001B[32municorn.\u001B[39m');
21-
t.true(stripAnsi(res20).split('\n').every(x => x.length <= 20));
20+
t.is(result, 'The quick brown \u001B[31mfox\u001B[39m\n\u001B[31mjumped over \u001B[39mthe lazy\n\u001B[32mdog and then ran\u001B[39m\n\u001B[32maway with the\u001B[39m\n\u001B[32municorn.\u001B[39m');
21+
t.true(stripAnsi(result).split('\n').every(line => line.length <= 20));
2222
});
2323

2424
test('wraps string at 30 characters', t => {
25-
const res30 = m(fixture, 30);
25+
const result = wrapAnsi(fixture, 30);
2626

27-
t.is(res30, 'The quick brown \u001B[31mfox jumped\u001B[39m\n\u001B[31mover \u001B[39mthe lazy \u001B[32mdog and then ran\u001B[39m\n\u001B[32maway with the unicorn.\u001B[39m');
28-
t.true(stripAnsi(res30).split('\n').every(x => x.length <= 30));
27+
t.is(result, 'The quick brown \u001B[31mfox jumped\u001B[39m\n\u001B[31mover \u001B[39mthe lazy \u001B[32mdog and then ran\u001B[39m\n\u001B[32maway with the unicorn.\u001B[39m');
28+
t.true(stripAnsi(result).split('\n').every(line => line.length <= 30));
2929
});
3030

3131
test('does not break strings longer than "cols" characters', t => {
32-
const res5 = m(fixture, 5, {hard: false});
32+
const result = wrapAnsi(fixture, 5, {hard: false});
3333

34-
t.is(res5, 'The\nquick\nbrown\n\u001B[31mfox\u001B[39m\n\u001B[31mjumped\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe\nlazy\n\u001B[32mdog\u001B[39m\n\u001B[32mand\u001B[39m\n\u001B[32mthen\u001B[39m\n\u001B[32mran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe\u001B[39m\n\u001B[32municorn.\u001B[39m');
35-
t.true(stripAnsi(res5).split('\n').filter(x => x.length > 5).length > 0);
34+
t.is(result, 'The\nquick\nbrown\n\u001B[31mfox\u001B[39m\n\u001B[31mjumped\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe\nlazy\n\u001B[32mdog\u001B[39m\n\u001B[32mand\u001B[39m\n\u001B[32mthen\u001B[39m\n\u001B[32mran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe\u001B[39m\n\u001B[32municorn.\u001B[39m');
35+
t.true(stripAnsi(result).split('\n').filter(line => line.length > 5).length > 0);
3636
});
3737

3838
test('handles colored string that wraps on to multiple lines', t => {
39-
const res = m(chalk.green('hello world') + ' hey!', 5, {hard: false});
40-
const lines = res.split('\n');
39+
const result = wrapAnsi(chalk.green('hello world') + ' hey!', 5, {hard: false});
40+
const lines = result.split('\n');
4141
t.true(hasAnsi(lines[0]));
4242
t.true(hasAnsi(lines[1]));
4343
t.false(hasAnsi(lines[2]));
4444
});
4545

4646
test('does not prepend newline if first string is greater than "cols"', t => {
47-
const res = m(chalk.green('hello') + '-world', 5, {hard: false});
48-
t.is(res.split('\n').length, 1);
47+
const result = wrapAnsi(chalk.green('hello') + '-world', 5, {hard: false});
48+
t.is(result.split('\n').length, 1);
4949
});
5050

5151
// When "hard" is true
5252

5353
test('breaks strings longer than "cols" characters', t => {
54-
const res5 = m(fixture, 5, {hard: true});
54+
const result = wrapAnsi(fixture, 5, {hard: true});
5555

56-
t.is(res5, 'The\nquick\nbrown\n\u001B[31mfox j\u001B[39m\n\u001B[31mumped\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe\nlazy\n\u001B[32mdog\u001B[39m\n\u001B[32mand\u001B[39m\n\u001B[32mthen\u001B[39m\n\u001B[32mran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe\u001B[39m\n\u001B[32munico\u001B[39m\n\u001B[32mrn.\u001B[39m');
57-
t.true(stripAnsi(res5).split('\n').every(x => x.length <= 5));
56+
t.is(result, 'The\nquick\nbrown\n\u001B[31mfox j\u001B[39m\n\u001B[31mumped\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe\nlazy\n\u001B[32mdog\u001B[39m\n\u001B[32mand\u001B[39m\n\u001B[32mthen\u001B[39m\n\u001B[32mran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe\u001B[39m\n\u001B[32munico\u001B[39m\n\u001B[32mrn.\u001B[39m');
57+
t.true(stripAnsi(result).split('\n').every(line => line.length <= 5));
5858
});
5959

6060
test('removes last row if it contained only ansi escape codes', t => {
61-
const res = m(chalk.green('helloworld'), 2, {hard: true});
62-
t.true(stripAnsi(res).split('\n').every(x => x.length === 2));
61+
const result = wrapAnsi(chalk.green('helloworld'), 2, {hard: true});
62+
t.true(stripAnsi(result).split('\n').every(x => x.length === 2));
6363
});
6464

6565
test('does not prepend newline if first word is split', t => {
66-
const res = m(chalk.green('hello') + 'world', 5, {hard: true});
67-
t.is(res.split('\n').length, 2);
66+
const result = wrapAnsi(chalk.green('hello') + 'world', 5, {hard: true});
67+
t.is(result.split('\n').length, 2);
6868
});
6969

7070
test('takes into account line returns inside input', t => {
71-
const res20 = m(fixture2, 10, {hard: true});
72-
t.is(res20, '12345678\n9012345678\n90');
71+
t.is(wrapAnsi(fixture2, 10, {hard: true}), '12345678\n9012345678\n90');
7372
});
7473

7574
test('word wrapping', t => {
76-
const res = m(fixture3, 15);
77-
t.is(res, '12345678\n901234567890\n12345');
75+
t.is(wrapAnsi(fixture3, 15), '12345678\n901234567890\n12345');
7876
});
7977

8078
test('no word-wrapping', t => {
81-
const res = m(fixture3, 15, {wordWrap: false});
82-
t.is(res, '12345678\n901234567890 12\n345');
79+
const result = wrapAnsi(fixture3, 15, {wordWrap: false});
80+
t.is(result, '12345678\n901234567890 12\n345');
8381

84-
const res2 = m(fixture3, 5, {wordWrap: false});
85-
t.is(res2, '12345\n678\n90123\n45678\n90 12\n345');
82+
const result2 = wrapAnsi(fixture3, 5, {wordWrap: false});
83+
t.is(result2, '12345\n678\n90123\n45678\n90 12\n345');
8684

87-
const res3 = m(fixture5, 5, {wordWrap: false});
88-
t.is(res3, '12345\n678\n');
85+
const rsult3 = wrapAnsi(fixture5, 5, {wordWrap: false});
86+
t.is(rsult3, '12345\n678\n');
8987

90-
const res4 = m(fixture, 5, {wordWrap: false});
91-
t.is(res4, 'The q\nuick\nbrown\n\u001B[31mfox j\u001B[39m\n\u001B[31mumped\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe l\nazy \u001B[32md\u001B[39m\n\u001B[32mog an\u001B[39m\n\u001B[32md the\u001B[39m\n\u001B[32mn ran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe u\u001B[39m\n\u001B[32mnicor\u001B[39m\n\u001B[32mn.\u001B[39m');
88+
const result4 = wrapAnsi(fixture, 5, {wordWrap: false});
89+
t.is(result4, 'The q\nuick\nbrown\n\u001B[31mfox j\u001B[39m\n\u001B[31mumped\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe l\nazy \u001B[32md\u001B[39m\n\u001B[32mog an\u001B[39m\n\u001B[32md the\u001B[39m\n\u001B[32mn ran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe u\u001B[39m\n\u001B[32mnicor\u001B[39m\n\u001B[32mn.\u001B[39m');
9290
});
9391

9492
test('no word-wrapping and no trimming', t => {
95-
const res = m(fixture3, 13, {wordWrap: false, trim: false});
96-
t.is(res, '12345678\n901234567890 \n12345');
93+
const result = wrapAnsi(fixture3, 13, {wordWrap: false, trim: false});
94+
t.is(result, '12345678\n901234567890 \n12345');
9795

98-
const res2 = m(fixture4, 5, {wordWrap: false, trim: false});
99-
t.is(res2, '12345\n678\n');
96+
const result2 = wrapAnsi(fixture4, 5, {wordWrap: false, trim: false});
97+
t.is(result2, '12345\n678\n');
10098

101-
const res3 = m(fixture5, 5, {wordWrap: false, trim: false});
102-
t.is(res3, '12345\n678\n ');
99+
const result3 = wrapAnsi(fixture5, 5, {wordWrap: false, trim: false});
100+
t.is(result3, '12345\n678\n ');
103101

104-
const res4 = m(fixture, 5, {wordWrap: false, trim: false});
105-
t.is(res4, 'The q\nuick \nbrown\n \u001B[31mfox \u001B[39m\n[31mjumpe[39m\n[31md ove[39m\n[31mr \u001B[39mthe\n lazy\n \u001B[32mdog \u001B[39m\n[32mand t[39m\n[32mhen r[39m\n[32man aw[39m\n[32may wi[39m\n[32mth th[39m\n[32me uni[39m\n[32mcorn.\u001B[39m');
102+
const result4 = wrapAnsi(fixture, 5, {wordWrap: false, trim: false});
103+
t.is(result4, 'The q\nuick \nbrown\n \u001B[31mfox \u001B[39m\n[31mjumpe[39m\n[31md ove[39m\n[31mr \u001B[39mthe\n lazy\n \u001B[32mdog \u001B[39m\n[32mand t[39m\n[32mhen r[39m\n[32man aw[39m\n[32may wi[39m\n[32mth th[39m\n[32me uni[39m\n[32mcorn.\u001B[39m');
106104
});
107105

108106
test('supports fullwidth characters', t => {
109-
t.is(m('안녕하세', 4, {hard: true}), '안녕\n하세');
107+
t.is(wrapAnsi('안녕하세', 4, {hard: true}), '안녕\n하세');
110108
});
111109

112110
test('supports unicode surrogate pairs', t => {
113-
t.is(m('a\uD83C\uDE00bc', 2, {hard: true}), 'a\n\uD83C\uDE00\nbc');
114-
t.is(m('a\uD83C\uDE00bc\uD83C\uDE00d\uD83C\uDE00', 2, {hard: true}), 'a\n\uD83C\uDE00\nbc\n\uD83C\uDE00\nd\n\uD83C\uDE00');
111+
t.is(wrapAnsi('a\uD83C\uDE00bc', 2, {hard: true}), 'a\n\uD83C\uDE00\nbc');
112+
t.is(wrapAnsi('a\uD83C\uDE00bc\uD83C\uDE00d\uD83C\uDE00', 2, {hard: true}), 'a\n\uD83C\uDE00\nbc\n\uD83C\uDE00\nd\n\uD83C\uDE00');
115113
});
116114

117115
test('#23, properly wraps whitespace with no trimming', t => {
118-
t.is(m(' ', 2, {trim: false}), ' \n ');
119-
t.is(m(' ', 2, {trim: false, hard: true}), ' \n ');
116+
t.is(wrapAnsi(' ', 2, {trim: false}), ' \n ');
117+
t.is(wrapAnsi(' ', 2, {trim: false, hard: true}), ' \n ');
120118
});
121119

122120
test('#24, trims leading and trailing whitespace only on actual wrapped lines and only with trimming', t => {
123-
t.is(m(' foo bar ', 6), 'foo\nbar');
124-
t.is(m(' foo bar ', 42), 'foo bar');
125-
t.is(m(' foo bar ', 42, {trim: false}), ' foo bar ');
121+
t.is(wrapAnsi(' foo bar ', 6), 'foo\nbar');
122+
t.is(wrapAnsi(' foo bar ', 42), 'foo bar');
123+
t.is(wrapAnsi(' foo bar ', 42, {trim: false}), ' foo bar ');
126124
});
127125

128126
test('#25, properly wraps whitespace between words with no trimming', t => {
129-
t.is(m('foo bar', 3), 'foo\nbar');
130-
t.is(m('foo bar', 3, {hard: true}), 'foo\nbar');
131-
t.is(m('foo bar', 3, {trim: false}), 'foo\n \nbar');
132-
t.is(m('foo bar', 3, {trim: false, hard: true}), 'foo\n \nbar');
127+
t.is(wrapAnsi('foo bar', 3), 'foo\nbar');
128+
t.is(wrapAnsi('foo bar', 3, {hard: true}), 'foo\nbar');
129+
t.is(wrapAnsi('foo bar', 3, {trim: false}), 'foo\n \nbar');
130+
t.is(wrapAnsi('foo bar', 3, {trim: false, hard: true}), 'foo\n \nbar');
133131
});
134132

135133
test('#26, does not multiplicate leading spaces with no trimming', t => {
136-
t.is(m(' a ', 10, {trim: false}), ' a ');
137-
t.is(m(' a ', 10, {trim: false}), ' a ');
134+
t.is(wrapAnsi(' a ', 10, {trim: false}), ' a ');
135+
t.is(wrapAnsi(' a ', 10, {trim: false}), ' a ');
138136
});
139137

140138
test('#27, does not remove spaces in line with ansi escapes when no trimming', t => {
141-
t.is(m(chalk.bgGreen(` ${chalk.black('OK')} `), 100, {trim: false}), chalk.bgGreen(` ${chalk.black('OK')} `));
142-
t.is(m(chalk.bgGreen(` ${chalk.black('OK')} `), 100, {trim: false}), chalk.bgGreen(` ${chalk.black('OK')} `));
143-
t.is(m(chalk.bgGreen(' hello '), 10, {hard: true, trim: false}), chalk.bgGreen(' hello '));
139+
t.is(wrapAnsi(chalk.bgGreen(` ${chalk.black('OK')} `), 100, {trim: false}), chalk.bgGreen(` ${chalk.black('OK')} `));
140+
t.is(wrapAnsi(chalk.bgGreen(` ${chalk.black('OK')} `), 100, {trim: false}), chalk.bgGreen(` ${chalk.black('OK')} `));
141+
t.is(wrapAnsi(chalk.bgGreen(' hello '), 10, {hard: true, trim: false}), chalk.bgGreen(' hello '));
144142
});

0 commit comments

Comments
 (0)
Please sign in to comment.