Skip to content

Commit f96455f

Browse files
committed
Require Node.js 10
1 parent 0e49047 commit f96455f

File tree

5 files changed

+30
-35
lines changed

5 files changed

+30
-35
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
node_js:
3+
- '14'
34
- '12'
45
- '10'
5-
- '8'
66
after_success:
77
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'

index.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ const wrapWord = (rows, word, columns) => {
7676
};
7777

7878
// Trims spaces from a string ignoring invisible sequences
79-
const stringVisibleTrimSpacesRight = str => {
80-
const words = str.split(' ');
79+
const stringVisibleTrimSpacesRight = string => {
80+
const words = string.split(' ');
8181
let last = words.length;
8282

8383
while (last > 0) {
@@ -89,7 +89,7 @@ const stringVisibleTrimSpacesRight = str => {
8989
}
9090

9191
if (last === words.length) {
92-
return str;
92+
return string;
9393
}
9494

9595
return words.slice(0, last).join(' ') + words.slice(last).join('');
@@ -105,16 +105,16 @@ const exec = (string, columns, options = {}) => {
105105
return '';
106106
}
107107

108-
let ret = '';
108+
let returnValue = '';
109109
let escapeCode;
110-
let escapeUri;
110+
let escapeUrl;
111111

112112
const lengths = wordLengths(string);
113113
let rows = [''];
114114

115115
for (const [index, word] of string.split(' ').entries()) {
116116
if (options.trim !== false) {
117-
rows[rows.length - 1] = rows[rows.length - 1].trimLeft();
117+
rows[rows.length - 1] = rows[rows.length - 1].trimStart();
118118
}
119119

120120
let rowLength = stringWidth(rows[rows.length - 1]);
@@ -169,40 +169,40 @@ const exec = (string, columns, options = {}) => {
169169
const pre = [...rows.join('\n')];
170170

171171
for (const [index, character] of pre.entries()) {
172-
ret += character;
172+
returnValue += character;
173173

174174
if (ESCAPES.has(character)) {
175175
const {groups} = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(pre.slice(index).join('')) || {groups: {}};
176176
if (groups.code !== undefined) {
177-
const code = parseFloat(groups.code);
178-
escapeCode = code === END_CODE ? null : code;
177+
const code = Number.parseFloat(groups.code);
178+
escapeCode = code === END_CODE ? undefined : code;
179179
} else if (groups.uri !== undefined) {
180-
escapeUri = groups.uri.length === 0 ? null : groups.uri;
180+
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
181181
}
182182
}
183183

184184
const code = ansiStyles.codes.get(Number(escapeCode));
185185

186186
if (pre[index + 1] === '\n') {
187-
if (escapeUri) {
188-
ret += wrapAnsiHyperlink('');
187+
if (escapeUrl) {
188+
returnValue += wrapAnsiHyperlink('');
189189
}
190190

191191
if (escapeCode && code) {
192-
ret += wrapAnsi(code);
192+
returnValue += wrapAnsi(code);
193193
}
194194
} else if (character === '\n') {
195195
if (escapeCode && code) {
196-
ret += wrapAnsi(escapeCode);
196+
returnValue += wrapAnsi(escapeCode);
197197
}
198198

199-
if (escapeUri) {
200-
ret += wrapAnsiHyperlink(escapeUri);
199+
if (escapeUrl) {
200+
returnValue += wrapAnsiHyperlink(escapeUrl);
201201
}
202202
}
203203
}
204204

205-
return ret;
205+
return returnValue;
206206
};
207207

208208
// For each newline, invoke the method separately

license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"description": "Wordwrap a string with ANSI escape codes",
55
"license": "MIT",
66
"repository": "chalk/wrap-ansi",
7+
"funding": "https://github.com/chalk/wrap-ansi?sponsor=1",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
1213
"engines": {
13-
"node": ">=8"
14+
"node": ">=10"
1415
},
1516
"scripts": {
1617
"test": "xo && nyc ava"
@@ -52,10 +53,10 @@
5253
},
5354
"devDependencies": {
5455
"ava": "^2.1.0",
55-
"chalk": "^2.4.2",
56+
"chalk": "^4.0.0",
5657
"coveralls": "^3.0.3",
57-
"has-ansi": "^3.0.0",
58-
"nyc": "^14.1.1",
59-
"xo": "^0.24.0"
58+
"has-ansi": "^4.0.0",
59+
"nyc": "^15.0.1",
60+
"xo": "^0.29.1"
6061
}
6162
}

readme.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
# wrap-ansi [![Build Status](https://travis-ci.org/chalk/wrap-ansi.svg?branch=master)](https://travis-ci.org/chalk/wrap-ansi) [![Coverage Status](https://coveralls.io/repos/github/chalk/wrap-ansi/badge.svg?branch=master)](https://coveralls.io/github/chalk/wrap-ansi?branch=master)
1+
# wrap-ansi [![Build Status](https://travis-ci.com/chalk/wrap-ansi.svg?branch=master)](https://travis-ci.com/chalk/wrap-ansi) [![Coverage Status](https://coveralls.io/repos/github/chalk/wrap-ansi/badge.svg?branch=master)](https://coveralls.io/github/chalk/wrap-ansi?branch=master)
22

33
> Wordwrap a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
44
5-
65
## Install
76

87
```
98
$ npm install wrap-ansi
109
```
1110

12-
1311
## Usage
1412

1513
```js
@@ -24,7 +22,6 @@ console.log(wrapAnsi(input, 20));
2422

2523
<img width="331" src="screenshot.png">
2624

27-
2825
## API
2926

3027
### wrapAnsi(string, columns, options?)
@@ -49,41 +46,38 @@ Type: `object`
4946

5047
##### hard
5148

52-
Type: `boolean`<br>
49+
Type: `boolean`\
5350
Default: `false`
5451

5552
By default the wrap is soft, meaning long words may extend past the column width. Setting this to `true` will make it hard wrap at the column width.
5653

5754
##### wordWrap
5855

59-
Type: `boolean`<br>
56+
Type: `boolean`\
6057
Default: `true`
6158

6259
By default, an attempt is made to split words at spaces, ensuring that they don't extend past the configured columns. If wordWrap is `false`, each column will instead be completely filled splitting words as necessary.
6360

6461
##### trim
6562

66-
Type: `boolean`<br>
63+
Type: `boolean`\
6764
Default: `true`
6865

6966
Whitespace on all lines is removed by default. Set this option to `false` if you don't want to trim.
7067

71-
7268
## Related
7369

7470
- [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes
7571
- [cli-truncate](https://github.com/sindresorhus/cli-truncate) - Truncate a string to a specific width in the terminal
7672
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
7773
- [jsesc](https://github.com/mathiasbynens/jsesc) - Generate ASCII-only output from Unicode strings. Useful for creating test fixtures.
7874

79-
8075
## Maintainers
8176

8277
- [Sindre Sorhus](https://github.com/sindresorhus)
8378
- [Josh Junon](https://github.com/qix-)
8479
- [Benjamin Coe](https://github.com/bcoe)
8580

86-
8781
---
8882

8983
<div align="center">

0 commit comments

Comments
 (0)