Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jun 11, 2019
1 parent ae43658 commit 9fbf24c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- '12'
- '10'
- '8'
- '6'
after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
19 changes: 8 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const wordLengths = string => string.split(' ').map(character => stringWidth(cha
const wrapWord = (rows, word, columns) => {
const characters = [...word];

let insideEscape = false;
let isInsideEscape = false;
let visible = stringWidth(stripAnsi(rows[rows.length - 1]));

for (const [index, character] of characters.entries()) {
Expand All @@ -35,13 +35,13 @@ const wrapWord = (rows, word, columns) => {
}

if (ESCAPES.has(character)) {
insideEscape = true;
} else if (insideEscape && character === 'm') {
insideEscape = false;
isInsideEscape = true;
} else if (isInsideEscape && character === 'm') {
isInsideEscape = false;
continue;
}

if (insideEscape) {
if (isInsideEscape) {
continue;
}

Expand Down Expand Up @@ -80,11 +80,9 @@ const stringVisibleTrimSpacesRight = str => {
return words.slice(0, last).join(' ') + words.slice(last).join('');
};

// The wrap-ansi module can be invoked
// in either 'hard' or 'soft' wrap mode
// The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode
//
// 'hard' will never allow a string to take up more
// than columns characters
// 'hard' will never allow a string to take up more than columns characters
//
// 'soft' allows long words to expand past the column length
const exec = (string, columns, options = {}) => {
Expand Down Expand Up @@ -119,8 +117,7 @@ const exec = (string, columns, options = {}) => {
}
}

// In 'hard' wrap mode, the length of a line is
// never allowed to extend past 'columns'
// In 'hard' wrap mode, the length of a line is never allowed to extend past 'columns'
if (options.hard && lengths[index] > columns) {
const remainingColumns = (columns - rowLength);
const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && nyc ava"
Expand Down Expand Up @@ -46,16 +46,16 @@
"text"
],
"dependencies": {
"ansi-styles": "^3.2.0",
"string-width": "^3.0.0",
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^5.0.0"
},
"devDependencies": {
"ava": "^1.2.1",
"ava": "^2.1.0",
"chalk": "^2.4.2",
"coveralls": "^3.0.3",
"has-ansi": "^3.0.0",
"nyc": "^13.3.0",
"nyc": "^14.1.1",
"xo": "^0.24.0"
}
}
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ console.log(wrapAnsi(input, 20));

## API

### wrapAnsi(input, columns, options?)
### wrapAnsi(string, columns, options?)

Wrap words to the specified column width.

#### input
#### string

Type: `string`

Expand All @@ -45,7 +45,7 @@ Number of columns to wrap the text to.

#### options

Type: `Object`
Type: `object`

##### hard

Expand Down

0 comments on commit 9fbf24c

Please sign in to comment.