Skip to content

Commit

Permalink
Require Node.js 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 22, 2020
1 parent 0e49047 commit f96455f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 35 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:
- '14'
- '12'
- '10'
- '8'
after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
34 changes: 17 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ const wrapWord = (rows, word, columns) => {
};

// Trims spaces from a string ignoring invisible sequences
const stringVisibleTrimSpacesRight = str => {
const words = str.split(' ');
const stringVisibleTrimSpacesRight = string => {
const words = string.split(' ');
let last = words.length;

while (last > 0) {
Expand All @@ -89,7 +89,7 @@ const stringVisibleTrimSpacesRight = str => {
}

if (last === words.length) {
return str;
return string;
}

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

let ret = '';
let returnValue = '';
let escapeCode;
let escapeUri;
let escapeUrl;

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

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

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

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

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

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

if (pre[index + 1] === '\n') {
if (escapeUri) {
ret += wrapAnsiHyperlink('');
if (escapeUrl) {
returnValue += wrapAnsiHyperlink('');
}

if (escapeCode && code) {
ret += wrapAnsi(code);
returnValue += wrapAnsi(code);
}
} else if (character === '\n') {
if (escapeCode && code) {
ret += wrapAnsi(escapeCode);
returnValue += wrapAnsi(escapeCode);
}

if (escapeUri) {
ret += wrapAnsiHyperlink(escapeUri);
if (escapeUrl) {
returnValue += wrapAnsiHyperlink(escapeUrl);
}
}
}

return ret;
return returnValue;
};

// For each newline, invoke the method separately
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

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

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:

Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"description": "Wordwrap a string with ANSI escape codes",
"license": "MIT",
"repository": "chalk/wrap-ansi",
"funding": "https://github.com/chalk/wrap-ansi?sponsor=1",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && nyc ava"
Expand Down Expand Up @@ -52,10 +53,10 @@
},
"devDependencies": {
"ava": "^2.1.0",
"chalk": "^2.4.2",
"chalk": "^4.0.0",
"coveralls": "^3.0.3",
"has-ansi": "^3.0.0",
"nyc": "^14.1.1",
"xo": "^0.24.0"
"has-ansi": "^4.0.0",
"nyc": "^15.0.1",
"xo": "^0.29.1"
}
}
14 changes: 4 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# 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)
# 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)

> Wordwrap a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)

## Install

```
$ npm install wrap-ansi
```


## Usage

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

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


## API

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

##### hard

Type: `boolean`<br>
Type: `boolean`\
Default: `false`

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.

##### wordWrap

Type: `boolean`<br>
Type: `boolean`\
Default: `true`

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.

##### trim

Type: `boolean`<br>
Type: `boolean`\
Default: `true`

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


## Related

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


## Maintainers

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


---

<div align="center">
Expand Down

0 comments on commit f96455f

Please sign in to comment.