Skip to content

Commit 43069a6

Browse files
committed
Require Node.js 18
1 parent d989bc4 commit 43069a6

File tree

5 files changed

+29
-45
lines changed

5 files changed

+29
-45
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13-
- 14
14-
- 12
13+
- 20
14+
- 18
1515
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v2
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
1818
with:
1919
node-version: ${{ matrix.node-version }}
2020
- run: npm install

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export type Options = {
2424
/**
2525
Wrap words to the specified column width.
2626
27-
@param string - String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk). Newline characters will be normalized to `\n`.
28-
@param columns - Number of columns to wrap the text to.
27+
@param string - A string with ANSI escape codes, like one styled by [`chalk`](https://github.com/chalk/chalk). Newline characters will be normalized to `\n`.
28+
@param columns - The number of columns to wrap the text to.
2929
3030
@example
3131
```

index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const ANSI_SGR_TERMINATOR = 'm';
1515
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
1616

1717
const wrapAnsiCode = code => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
18-
const wrapAnsiHyperlink = uri => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${uri}${ANSI_ESCAPE_BELL}`;
18+
const wrapAnsiHyperlink = url => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
1919

2020
// Calculate the length of words split on ' ', ignoring
2121
// the extra characters added by ansi escape codes
@@ -28,7 +28,7 @@ const wrapWord = (rows, word, columns) => {
2828

2929
let isInsideEscape = false;
3030
let isInsideLinkEscape = false;
31-
let visible = stringWidth(stripAnsi(rows[rows.length - 1]));
31+
let visible = stringWidth(stripAnsi(rows.at(-1)));
3232

3333
for (const [index, character] of characters.entries()) {
3434
const characterLength = stringWidth(character);
@@ -70,7 +70,7 @@ const wrapWord = (rows, word, columns) => {
7070

7171
// It's possible that the last row we copy over is only
7272
// ansi escape characters, handle this edge-case
73-
if (!visible && rows[rows.length - 1].length > 0 && rows.length > 1) {
73+
if (!visible && rows.at(-1).length > 0 && rows.length > 1) {
7474
rows[rows.length - 2] += rows.pop();
7575
}
7676
};
@@ -95,11 +95,11 @@ const stringVisibleTrimSpacesRight = string => {
9595
return words.slice(0, last).join(' ') + words.slice(last).join('');
9696
};
9797

98-
// The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode
98+
// The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode.
9999
//
100-
// 'hard' will never allow a string to take up more than columns characters
100+
// 'hard' will never allow a string to take up more than columns characters.
101101
//
102-
// 'soft' allows long words to expand past the column length
102+
// 'soft' allows long words to expand past the column length.
103103
const exec = (string, columns, options = {}) => {
104104
if (options.trim !== false && string.trim() === '') {
105105
return '';
@@ -114,10 +114,10 @@ const exec = (string, columns, options = {}) => {
114114

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

120-
let rowLength = stringWidth(rows[rows.length - 1]);
120+
let rowLength = stringWidth(rows.at(-1));
121121

122122
if (index !== 0) {
123123
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
@@ -215,7 +215,7 @@ const exec = (string, columns, options = {}) => {
215215
export default function wrapAnsi(string, columns, options) {
216216
return String(string)
217217
.normalize()
218-
.replace(/\r\n/g, '\n')
218+
.replaceAll('\r\n', '\n')
219219
.split('\n')
220220
.map(line => exec(line, columns, options))
221221
.join('\n');

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"default": "./index.js"
1717
},
1818
"engines": {
19-
"node": ">=12"
19+
"node": ">=18"
2020
},
2121
"scripts": {
2222
"test": "xo && nyc ava && tsd"
@@ -53,17 +53,17 @@
5353
"text"
5454
],
5555
"dependencies": {
56-
"ansi-styles": "^6.1.0",
57-
"string-width": "^5.0.1",
58-
"strip-ansi": "^7.0.1"
56+
"ansi-styles": "^6.2.1",
57+
"string-width": "^7.0.0",
58+
"strip-ansi": "^7.1.0"
5959
},
6060
"devDependencies": {
61-
"ava": "^3.15.0",
62-
"chalk": "^4.1.2",
61+
"ava": "^5.3.1",
62+
"chalk": "^5.3.0",
6363
"coveralls": "^3.1.1",
6464
"has-ansi": "^5.0.1",
6565
"nyc": "^15.1.0",
66-
"tsd": "^0.25.0",
67-
"xo": "^0.44.0"
66+
"tsd": "^0.29.0",
67+
"xo": "^0.56.0"
6868
}
6969
}

readme.md

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
55
## Install
66

7-
```
8-
$ npm install wrap-ansi
7+
```sh
8+
npm install wrap-ansi
99
```
1010

1111
## Usage
@@ -32,13 +32,15 @@ Wrap words to the specified column width.
3232

3333
Type: `string`
3434

35-
String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk). Newline characters will be normalized to `\n`.
35+
A string with ANSI escape codes, like one styled by [`chalk`](https://github.com/chalk/chalk).
36+
37+
Newline characters will be normalized to `\n`.
3638

3739
#### columns
3840

3941
Type: `number`
4042

41-
Number of columns to wrap the text to.
43+
The number of columns to wrap the text to.
4244

4345
#### options
4446

@@ -71,21 +73,3 @@ Whitespace on all lines is removed by default. Set this option to `false` if you
7173
- [cli-truncate](https://github.com/sindresorhus/cli-truncate) - Truncate a string to a specific width in the terminal
7274
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
7375
- [jsesc](https://github.com/mathiasbynens/jsesc) - Generate ASCII-only output from Unicode strings. Useful for creating test fixtures.
74-
75-
## Maintainers
76-
77-
- [Sindre Sorhus](https://github.com/sindresorhus)
78-
- [Josh Junon](https://github.com/qix-)
79-
- [Benjamin Coe](https://github.com/bcoe)
80-
81-
---
82-
83-
<div align="center">
84-
<b>
85-
<a href="https://tidelift.com/subscription/pkg/npm-wrap_ansi?utm_source=npm-wrap-ansi&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
86-
</b>
87-
<br>
88-
<sub>
89-
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
90-
</sub>
91-
</div>

0 commit comments

Comments
 (0)