Skip to content

Commit 424b42a

Browse files
committed
Require Node.js 14
1 parent 29f76a4 commit 424b42a

File tree

4 files changed

+30
-38
lines changed

4 files changed

+30
-38
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 18
14+
- 16
1315
- 14
14-
- 12
1516
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v2
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-node@v3
1819
with:
1920
node-version: ${{ matrix.node-version }}
2021
- run: npm install

index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import isFullwidthCodePoint from 'is-fullwidth-code-point';
44
// \x1b and \x9b
55
const ESCAPES = new Set([27, 155]);
66

7-
const CHAR_CODE_0 = '0'.charCodeAt(0);
8-
const CHAR_CODE_9 = '9'.charCodeAt(0);
7+
const CODE_POINT_0 = '0'.codePointAt(0);
8+
const CODE_POINT_9 = '9'.codePointAt(0);
99

1010
const endCodesSet = new Set();
1111
const endCodesMap = new Map();
@@ -38,8 +38,8 @@ function getEndCode(code) {
3838

3939
function findNumberIndex(string) {
4040
for (let index = 0; index < string.length; index++) {
41-
const charCode = string.charCodeAt(index);
42-
if (charCode >= CHAR_CODE_0 && charCode <= CHAR_CODE_9) {
41+
const codePoint = string.codePointAt(index);
42+
if (codePoint >= CODE_POINT_0 && codePoint <= CODE_POINT_9) {
4343
return index;
4444
}
4545
}
@@ -60,7 +60,7 @@ function parseAnsiCode(string, offset) {
6060
}
6161
}
6262

63-
function tokenize(string, endChar = Number.POSITIVE_INFINITY) {
63+
function tokenize(string, endCharacter = Number.POSITIVE_INFINITY) {
6464
const returnValue = [];
6565

6666
let index = 0;
@@ -74,7 +74,7 @@ function tokenize(string, endChar = Number.POSITIVE_INFINITY) {
7474
returnValue.push({
7575
type: 'ansi',
7676
code,
77-
endCode: getEndCode(code)
77+
endCode: getEndCode(code),
7878
});
7979
index += code.length;
8080
continue;
@@ -87,11 +87,13 @@ function tokenize(string, endChar = Number.POSITIVE_INFINITY) {
8787
returnValue.push({
8888
type: 'character',
8989
value: character,
90-
isFullWidth
90+
isFullWidth,
9191
});
92+
9293
index += character.length;
9394
visibleCount += isFullWidth ? 2 : character.length;
94-
if (visibleCount >= endChar) {
95+
96+
if (visibleCount >= endCharacter) {
9597
break;
9698
}
9799
}
@@ -101,6 +103,7 @@ function tokenize(string, endChar = Number.POSITIVE_INFINITY) {
101103

102104
function reduceAnsiCodes(codes) {
103105
let returnValue = [];
106+
104107
for (const code of codes) {
105108
if (code.code === ansiStyles.reset.open) {
106109
// Reset code, disable all codes
@@ -124,7 +127,7 @@ function undoAnsiCodes(codes) {
124127
return endCodes.reverse().join('');
125128
}
126129

127-
export default function sliceAnsi(string, begin, end) {
130+
export default function sliceAnsi(string, start, end) {
128131
const tokens = tokenize(string, end);
129132
let activeCodes = [];
130133
let position = 0;
@@ -142,8 +145,8 @@ export default function sliceAnsi(string, begin, end) {
142145
returnValue += token.code;
143146
}
144147
} else {
145-
// Char
146-
if (!include && position >= begin) {
148+
// Character
149+
if (!include && position >= start) {
147150
include = true;
148151
// Simplify active codes
149152
activeCodes = reduceAnsiCodes(activeCodes);

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"type": "module",
99
"exports": "./index.js",
1010
"engines": {
11-
"node": ">=12"
11+
"node": ">=14.16"
1212
},
1313
"scripts": {
1414
"test": "xo && ava"
@@ -40,14 +40,14 @@
4040
"text"
4141
],
4242
"dependencies": {
43-
"ansi-styles": "^6.0.0",
43+
"ansi-styles": "^6.2.1",
4444
"is-fullwidth-code-point": "^4.0.0"
4545
},
4646
"devDependencies": {
47-
"ava": "^3.15.0",
48-
"chalk": "^4.1.0",
49-
"random-item": "^4.0.0",
50-
"strip-ansi": "^7.0.0",
51-
"xo": "^0.38.2"
47+
"ava": "^5.2.0",
48+
"chalk": "^5.2.0",
49+
"random-item": "^4.0.1",
50+
"strip-ansi": "^7.0.1",
51+
"xo": "^0.53.1"
5252
}
5353
}

readme.md

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

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

1111
## Usage
@@ -22,19 +22,19 @@ console.log(sliceAnsi(string, 20, 30));
2222

2323
## API
2424

25-
### sliceAnsi(string, beginSlice, endSlice?)
25+
### sliceAnsi(string, startSlice, endSlice?)
2626

2727
#### string
2828

2929
Type: `string`
3030

3131
String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk).
3232

33-
#### beginSlice
33+
#### startSlice
3434

3535
Type: `number`
3636

37-
Zero-based index at which to begin the slice.
37+
Zero-based index at which to start the slice.
3838

3939
#### endSlice
4040

@@ -52,15 +52,3 @@ Zero-based index at which to end the slice.
5252

5353
- [Sindre Sorhus](https://github.com/sindresorhus)
5454
- [Josh Junon](https://github.com/qix-)
55-
56-
---
57-
58-
<div align="center">
59-
<b>
60-
<a href="https://tidelift.com/subscription/pkg/npm-slice_ansi?utm_source=npm-slice-ansi&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
61-
</b>
62-
<br>
63-
<sub>
64-
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
65-
</sub>
66-
</div>

0 commit comments

Comments
 (0)