Skip to content

Commit b630317

Browse files
committed
Meta tweaks
1 parent 02fa893 commit b630317

File tree

8 files changed

+39
-50
lines changed

8 files changed

+39
-50
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 22
1314
- 14
14-
- 12
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

fixtures/ansi-codes.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const vt52Codes = new Map([
1717
['2', ['Graphics processor off']],
1818
['<', ['Enter ANSI mode']],
1919
['s', ['Cursor save']],
20-
['u', ['Cursor restore']]
20+
['u', ['Cursor restore']],
2121
]);
2222

2323
// From https://espterm.github.io/docs/VT100%20escape%20codes.html
@@ -76,7 +76,7 @@ export const ansiCompatible = new Map([
7676

7777
['c', ['Causes power-up reset routine to be executed']],
7878
['#8', ['Fill screen with "E"']],
79-
['[2;176y', ['Invoke Test(s), where Ps is a decimal computed by adding the numbers of the desired tests to be executed']]
79+
['[2;176y', ['Invoke Test(s), where Ps is a decimal computed by adding the numbers of the desired tests to be executed']],
8080
]);
8181

8282
// From http://ascii-table.com/ansi-escape-sequences-vt-100.php
@@ -181,7 +181,7 @@ export const commonCodes = new Map([
181181
['[1q', ['Turn on LED #1', 'DECLL1']],
182182
['[2q', ['Turn on LED #2', 'DECLL2']],
183183
['[3q', ['Turn on LED #3', 'DECLL3']],
184-
['[4q', ['Turn on LED #4', 'DECLL4']]
184+
['[4q', ['Turn on LED #4', 'DECLL4']],
185185
]);
186186

187187
// From http://ascii-table.com/ansi-escape-sequences-vt-100.php
@@ -212,7 +212,7 @@ export const otherCode = new Map([
212212
['5n', ['Device status report', 'DSR']],
213213
['0n', ['Response: terminal is OK', 'DSR']],
214214
['3n', ['Response: terminal is not OK', 'DSR']],
215-
['6n', ['Get cursor position', 'DSR']]
215+
['6n', ['Get cursor position', 'DSR']],
216216
]);
217217

218218
// `urxvt` escapes
@@ -229,5 +229,5 @@ export const urxvt = new Map([
229229
['[3;5;606t', ['URxvt.keysym.C-M-y']],
230230
['[3;1605;5t', ['URxvt.keysym.C-M-e']],
231231
['[3;1605;606t', ['URxvt.keysym.C-M-c']],
232-
[']710;9x15bold\u0007', ['URxvt.keysym.font']]
232+
[']710;9x15bold\u0007', ['URxvt.keysym.font']],
233233
]);

fixtures/view-codes.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import ansiCodes from './ansi-codes.js';
1+
import process from 'node:process';
22
import ansiRegex from '../index.js';
3+
import ansiCodes from './ansi-codes.js';
34

45
const allCodes = {};
56
const supported = [];
@@ -18,7 +19,7 @@ function identifySupportedCodes() {
1819
codeSupport = {
1920
code,
2021
matches: `\u001B${code}`.match(ansiRegex()),
21-
description: value[0]
22+
description: value[0],
2223
};
2324

2425
if (codeSupport.matches !== null && codeSupport.matches[0] === `\u001B${code}`) {

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
export interface Options {
1+
export type Options = {
22
/**
33
Match only the first ANSI escape.
44
55
@default false
66
*/
77
readonly onlyFirst: boolean;
8-
}
8+
};
99

1010
/**
1111
Regular expression for matching ANSI escape codes.

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default function ansiRegex({onlyFirst = false} = {}) {
22
const pattern = [
33
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
4-
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
4+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
55
].join('|');
66

77
return new RegExp(pattern, onlyFirst ? undefined : 'g');

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
},
1313
"type": "module",
1414
"exports": "./index.js",
15+
"types": "./index.d.ts",
16+
"sideEffects": false,
1517
"engines": {
1618
"node": ">=12"
1719
},
@@ -53,7 +55,7 @@
5355
"devDependencies": {
5456
"ansi-escapes": "^5.0.0",
5557
"ava": "^3.15.0",
56-
"tsd": "^0.14.0",
57-
"xo": "^0.38.2"
58+
"tsd": "^0.21.0",
59+
"xo": "^0.54.2"
5860
}
5961
}

readme.md

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

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

1111
## Usage
@@ -58,15 +58,3 @@ On the historical side, those ECMA standards were established in the early 90's
5858

5959
- [Sindre Sorhus](https://github.com/sindresorhus)
6060
- [Josh Junon](https://github.com/qix-)
61-
62-
---
63-
64-
<div align="center">
65-
<b>
66-
<a href="https://tidelift.com/subscription/pkg/npm-ansi-regex?utm_source=npm-ansi-regex&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
67-
</b>
68-
<br>
69-
<sub>
70-
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
71-
</sub>
72-
</div>

test.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ test('match terminal link', t => {
4747
t.regex('\u001B]8;;mailto:no-replay@mail.com\u0007mail\u001B]8;;\u0007', ansiRegex());
4848
t.deepEqual('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007'.match(ansiRegex()), [
4949
'\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007',
50-
'\u001B]8;;\u0007'
50+
'\u001B]8;;\u0007',
5151
]);
5252
t.deepEqual('\u001B]8;;mailto:no-reply@mail.com\u0007mail-me\u001B]8;;\u0007'.match(ansiRegex()), [
5353
'\u001B]8;;mailto:no-reply@mail.com\u0007',
54-
'\u001B]8;;\u0007'
54+
'\u001B]8;;\u0007',
5555
]);
5656
});
5757

@@ -60,14 +60,14 @@ test('match "change icon name and window title" in string', t => {
6060
});
6161

6262
// Testing against extended codes (excluding codes ending in 0-9)
63-
for (const codeSet of Object.keys(ansiCodes)) {
64-
for (const [code, codeInfo] of ansiCodes[codeSet]) {
65-
const skip = /\d$/.test(code);
66-
const skipText = skip ? '[SKIP] ' : '';
63+
for (const [codeSetKey, codeSetValue] of Object.entries(ansiCodes)) {
64+
for (const [code, codeInfo] of codeSetValue) {
65+
const shouldSkip = /\d$/.test(code);
66+
const skipText = shouldSkip ? '[SKIP] ' : '';
6767
const ecode = `\u001B${code}`;
6868

69-
test(`${codeSet} - ${skipText}${code}${codeInfo[0]}`, t => {
70-
if (skip) {
69+
test(`${codeSetKey} - ${skipText}${code}${codeInfo[0]}`, t => {
70+
if (shouldSkip) {
7171
t.pass();
7272
return;
7373
}
@@ -78,36 +78,34 @@ for (const codeSet of Object.keys(ansiCodes)) {
7878
t.is(string.replace(ansiRegex(), ''), 'hello');
7979
});
8080

81-
test(`${codeSet} - ${skipText}${code} should not overconsume`, t => {
82-
if (skip) {
81+
test(`${codeSetKey} - ${skipText}${code} should not overconsume`, t => {
82+
if (shouldSkip) {
8383
t.pass();
8484
return;
8585
}
8686

87-
for (const c of consumptionCharacters) {
88-
const string = ecode + c;
87+
for (const character of consumptionCharacters) {
88+
const string = ecode + character;
8989
t.regex(string, ansiRegex());
9090
t.is(string.match(ansiRegex())[0], ecode);
91-
t.is(string.replace(ansiRegex(), ''), c);
91+
t.is(string.replace(ansiRegex(), ''), character);
9292
}
9393
});
9494
}
9595
}
9696

97-
const escapeCodeFunctionArgs = [1, 2];
97+
const escapeCodeFunctionArguments = [1, 2];
9898
const escapeCodeIgnoresList = new Set(['beep', 'image', 'iTerm']);
99-
const escapeCodeResultMap = new Map([['link', escapeCodeFunctionArgs[0]]]);
99+
const escapeCodeResultMap = new Map([['link', escapeCodeFunctionArguments[0]]]);
100100

101-
for (const key of Object.keys(ansiEscapes)) {
101+
for (const [key, escapeCode] of Object.entries(ansiEscapes)) {
102102
if (escapeCodeIgnoresList.has(key)) {
103103
continue;
104104
}
105105

106-
const escapeCode = ansiEscapes[key];
107-
108-
const escapeCodeValue = typeof escapeCode === 'function' ?
109-
escapeCode(...escapeCodeFunctionArgs) :
110-
escapeCode;
106+
const escapeCodeValue = typeof escapeCode === 'function'
107+
? escapeCode(...escapeCodeFunctionArguments)
108+
: escapeCode;
111109

112110
test(`ansi-escapes ${key}`, t => {
113111
for (const character of consumptionCharacters) {

0 commit comments

Comments
 (0)