Skip to content

Commit 1b337ad

Browse files
committedApr 16, 2021
Require Node.js 12 and move to ESM
1 parent 178363b commit 1b337ad

11 files changed

+35
-51
lines changed
 

‎.github/funding.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github: [sindresorhus,Qix-]
1+
github: [sindresorhus, Qix-]
22
tidelift: npm/ansi-regex

‎.github/workflows/main.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ jobs:
1212
node-version:
1313
- 14
1414
- 12
15-
- 10
16-
- 8
1715
steps:
1816
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
17+
- uses: actions/setup-node@v2
2018
with:
2119
node-version: ${{ matrix.node-version }}
2220
- run: npm install

‎fixtures/ansi-codes.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict';
2-
31
// From http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
4-
exports.vt52Codes = new Map([
2+
export const vt52Codes = new Map([
53
['A', ['Cursor up']],
64
['B', ['Cursor down']],
75
['C', ['Cursor right']],
@@ -21,7 +19,7 @@ exports.vt52Codes = new Map([
2119
]);
2220

2321
// From http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
24-
exports.ansiCompatible = new Map([
22+
export const ansiCompatible = new Map([
2523
['[176A', ['Cursor up Pn lines']],
2624
['[176B', ['Cursor down Pn lines']],
2725
['[176C', ['Cursor forward Pn characters (right)']],
@@ -80,7 +78,7 @@ exports.ansiCompatible = new Map([
8078
]);
8179

8280
// From http://ascii-table.com/ansi-escape-sequences-vt-100.php
83-
exports.commonCodes = new Map([
81+
export const commonCodes = new Map([
8482
['[176A', ['Move cursor up n lines', 'CUU']],
8583
['[176B', ['Move cursor down n lines', 'CUD']],
8684
['[176C', ['Move cursor right n lines', 'CUF']],
@@ -185,7 +183,7 @@ exports.commonCodes = new Map([
185183
]);
186184

187185
// From http://ascii-table.com/ansi-escape-sequences-vt-100.php
188-
exports.otherCode = new Map([
186+
export const otherCode = new Map([
189187
['7', ['Save cursor position and attributes', 'DECSC']],
190188
['8', ['Restore cursor position and attributes', 'DECSC']],
191189

@@ -216,7 +214,7 @@ exports.otherCode = new Map([
216214
]);
217215

218216
// `urxvt` escapes
219-
exports.urxvt = new Map([
217+
export const urxvt = new Map([
220218
['[5~', ['URxvt.keysym.Prior']],
221219
['[6~', ['URxvt.keysym.Next']],
222220
['[7~', ['URxvt.keysym.Home']],

‎fixtures/view-codes.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
'use strict';
2-
const ansiCodes = require('./ansi-codes');
3-
const ansiRegex = require('..');
1+
import ansiCodes from './ansi-codes.js';
2+
import ansiRegex from '../index.js';
43

54
const allCodes = {};
65
const supported = [];

‎index.d.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
declare namespace ansiRegex {
2-
interface Options {
3-
/**
4-
Match only the first ANSI escape.
5-
6-
@default false
7-
*/
8-
onlyFirst: boolean;
9-
}
1+
export interface Options {
2+
/**
3+
Match only the first ANSI escape.
4+
5+
@default false
6+
*/
7+
readonly onlyFirst: boolean;
108
}
119

1210
/**
1311
Regular expression for matching ANSI escape codes.
1412
1513
@example
1614
```
17-
import ansiRegex = require('ansi-regex');
15+
import ansiRegex from 'ansi-regex';
1816
1917
ansiRegex().test('\u001B[4mcake\u001B[0m');
2018
//=> true
@@ -32,6 +30,4 @@ ansiRegex().test('cake');
3230
//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
3331
```
3432
*/
35-
declare function ansiRegex(options?: ansiRegex.Options): RegExp;
36-
37-
export = ansiRegex;
33+
export default function ansiRegex(options?: Options): RegExp;

‎index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict';
2-
3-
module.exports = ({onlyFirst = false} = {}) => {
1+
export default function ansiRegex({onlyFirst = false} = {}) {
42
const pattern = [
53
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
64
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
75
].join('|');
86

97
return new RegExp(pattern, onlyFirst ? undefined : 'g');
10-
};
8+
}

‎index.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {expectType} from 'tsd';
2-
import ansiRegex = require('.');
2+
import ansiRegex from './index.js';
33

44
expectType<RegExp>(ansiRegex());
55
expectType<RegExp>(ansiRegex({onlyFirst: true}));

‎license

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
44

55
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:
66

‎package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Regular expression for matching ANSI escape codes",
55
"license": "MIT",
66
"repository": "chalk/ansi-regex",
7+
"funding": "https://github.com/chalk/ansi-regex?sponsor=1",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "sindresorhus@gmail.com",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=8"
16+
"node": ">=12"
1417
},
1518
"scripts": {
1619
"test": "xo && ava && tsd",
@@ -48,8 +51,8 @@
4851
"pattern"
4952
],
5053
"devDependencies": {
51-
"ava": "^2.4.0",
52-
"tsd": "^0.9.0",
53-
"xo": "^0.25.3"
54+
"ava": "^3.15.0",
55+
"tsd": "^0.14.0",
56+
"xo": "^0.38.2"
5457
}
5558
}

‎readme.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
> Regular expression for matching [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
44
5-
65
## Install
76

87
```
98
$ npm install ansi-regex
109
```
1110

12-
1311
## Usage
1412

1513
```js
16-
const ansiRegex = require('ansi-regex');
14+
import ansiRegex from 'ansi-regex';
1715

1816
ansiRegex().test('\u001B[4mcake\u001B[0m');
1917
//=> true
@@ -31,7 +29,6 @@ ansiRegex().test('cake');
3129
//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
3230
```
3331

34-
3532
## API
3633

3734
### ansiRegex(options?)
@@ -44,12 +41,11 @@ Type: `object`
4441

4542
##### onlyFirst
4643

47-
Type: `boolean`<br>
44+
Type: `boolean`\
4845
Default: `false` *(Matches any ANSI escape codes in a string)*
4946

5047
Match only the first ANSI escape.
5148

52-
5349
## FAQ
5450

5551
### Why do you test for codes not in the ECMA 48 standard?
@@ -58,13 +54,11 @@ Some of the codes we run as a test are codes that we acquired finding various li
5854

5955
On the historical side, those ECMA standards were established in the early 90's whereas the VT100, for example, was designed in the mid/late 70's. At that point in time, control codes were still pretty ungoverned and engineers used them for a multitude of things, namely to activate hardware ports that may have been proprietary. Somewhere else you see a similar 'anarchy' of codes is in the x86 architecture for processors; there are a ton of "interrupts" that can mean different things on certain brands of processors, most of which have been phased out.
6056

61-
6257
## Maintainers
6358

6459
- [Sindre Sorhus](https://github.com/sindresorhus)
6560
- [Josh Junon](https://github.com/qix-)
6661

67-
6862
---
6963

7064
<div align="center">

‎test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava';
2-
import ansiCodes from './fixtures/ansi-codes';
3-
import ansiRegex from '.';
2+
import * as ansiCodes from './fixtures/ansi-codes.js';
3+
import ansiRegex from './index.js';
44

55
const consumptionCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+1234567890-=[]{};\':"./>?,<\\|';
66

@@ -60,9 +60,7 @@ test('match "change icon name and window title" in string', t => {
6060

6161
// Testing against extended codes (excluding codes ending in 0-9)
6262
for (const codeSet of Object.keys(ansiCodes)) {
63-
for (const el of ansiCodes[codeSet]) {
64-
const code = el[0];
65-
const codeInfo = el[1];
63+
for (const [code, codeInfo] of ansiCodes[codeSet]) {
6664
const skip = /\d$/.test(code);
6765
const skipText = skip ? '[SKIP] ' : '';
6866
const ecode = `\u001B${code}`;

0 commit comments

Comments
 (0)
Please sign in to comment.