Skip to content

Commit ced7421

Browse files
committedSep 18, 2018
Require Node.js 6
1 parent eac826a commit ced7421

10 files changed

+85
-86
lines changed
 

‎.gitattributes

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
yarn.lock

‎.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

‎.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: node_js
22
node_js:
3+
- '10'
34
- '8'
45
- '6'
5-
- '4'

‎fixtures/ansi-codes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ exports.otherCode = new Map([
215215
['6n', ['Get cursor position', 'DSR']]
216216
]);
217217

218-
// urxvt escapes
218+
// `urxvt` escapes
219219
exports.urxvt = new Map([
220220
['[5~', ['URxvt.keysym.Prior']],
221221
['[6~', ['URxvt.keysym.Next']],

‎fixtures/view-codes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ const supported = [];
77
const unsupported = [];
88

99
function addCodesToTest(codes) {
10-
for (const code in codes) {
10+
for (const code of Object.keys(codes)) {
1111
allCodes[code] = codes[code];
1212
}
1313
}
1414

1515
function identifySupportedCodes() {
1616
let codeSupport = {};
1717

18-
for (const code in allCodes) {
18+
for (const code of Object.keys(allCodes)) {
1919
codeSupport = {
2020
code,
2121
matches: `\u001B${code}`.match(ansiRegex()),

‎index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
'use strict';
22

3-
const defaultOptions = {
4-
onlyFirst: false
5-
};
6-
73
module.exports = options => {
8-
options = Object.assign({}, defaultOptions, options);
4+
options = Object.assign({
5+
onlyFirst: false
6+
}, options);
97

108
const pattern = [
119
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)',

‎package.json

+51-51
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
{
2-
"name": "ansi-regex",
3-
"version": "3.0.0",
4-
"description": "Regular expression for matching ANSI escape codes",
5-
"license": "MIT",
6-
"repository": "chalk/ansi-regex",
7-
"author": {
8-
"name": "Sindre Sorhus",
9-
"email": "sindresorhus@gmail.com",
10-
"url": "sindresorhus.com"
11-
},
12-
"engines": {
13-
"node": ">=4"
14-
},
15-
"scripts": {
16-
"test": "xo && ava",
17-
"view-supported": "node fixtures/view-codes.js"
18-
},
19-
"files": [
20-
"index.js"
21-
],
22-
"keywords": [
23-
"ansi",
24-
"styles",
25-
"color",
26-
"colour",
27-
"colors",
28-
"terminal",
29-
"console",
30-
"cli",
31-
"string",
32-
"tty",
33-
"escape",
34-
"formatting",
35-
"rgb",
36-
"256",
37-
"shell",
38-
"xterm",
39-
"command-line",
40-
"text",
41-
"regex",
42-
"regexp",
43-
"re",
44-
"match",
45-
"test",
46-
"find",
47-
"pattern"
48-
],
49-
"devDependencies": {
50-
"ava": "*",
51-
"xo": "*"
52-
}
2+
"name": "ansi-regex",
3+
"version": "3.0.0",
4+
"description": "Regular expression for matching ANSI escape codes",
5+
"license": "MIT",
6+
"repository": "chalk/ansi-regex",
7+
"author": {
8+
"name": "Sindre Sorhus",
9+
"email": "sindresorhus@gmail.com",
10+
"url": "sindresorhus.com"
11+
},
12+
"engines": {
13+
"node": ">=6"
14+
},
15+
"scripts": {
16+
"test": "xo && ava",
17+
"view-supported": "node fixtures/view-codes.js"
18+
},
19+
"files": [
20+
"index.js"
21+
],
22+
"keywords": [
23+
"ansi",
24+
"styles",
25+
"color",
26+
"colour",
27+
"colors",
28+
"terminal",
29+
"console",
30+
"cli",
31+
"string",
32+
"tty",
33+
"escape",
34+
"formatting",
35+
"rgb",
36+
"256",
37+
"shell",
38+
"xterm",
39+
"command-line",
40+
"text",
41+
"regex",
42+
"regexp",
43+
"re",
44+
"match",
45+
"test",
46+
"find",
47+
"pattern"
48+
],
49+
"devDependencies": {
50+
"ava": "^0.25.0",
51+
"xo": "^0.23.0"
52+
}
5353
}

‎readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Returns a regex for matching ANSI escape codes.
4242
Type: `boolean`<br>
4343
Default: `false` *(Matches any ANSI escape codes in a string)*
4444

45-
Match only the first one.<br>
45+
Match only the first ANSI escape.
4646

4747

4848
## FAQ

‎test.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
import test from 'ava';
22
import ansiCodes from './fixtures/ansi-codes';
3-
import m from '.';
3+
import ansiRegex from '.';
44

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

77
// Testing against codes found at: http://ascii-table.com/ansi-escape-sequences-vt-100.php
88
test('match ansi code in a string', t => {
9-
t.regex('foo\u001B[4mcake\u001B[0m', m());
10-
t.regex('\u001B[4mcake\u001B[0m', m());
11-
t.regex('foo\u001B[4mcake\u001B[0m', m());
12-
t.regex('\u001B[0m\u001B[4m\u001B[42m\u001B[31mfoo\u001B[39m\u001B[49m\u001B[24mfoo\u001B[0m', m());
13-
t.regex('foo\u001B[mfoo', m());
9+
t.regex('foo\u001B[4mcake\u001B[0m', ansiRegex());
10+
t.regex('\u001B[4mcake\u001B[0m', ansiRegex());
11+
t.regex('foo\u001B[4mcake\u001B[0m', ansiRegex());
12+
t.regex('\u001B[0m\u001B[4m\u001B[42m\u001B[31mfoo\u001B[39m\u001B[49m\u001B[24mfoo\u001B[0m', ansiRegex());
13+
t.regex('foo\u001B[mfoo', ansiRegex());
1414
});
1515

1616
test('match ansi code from ls command', t => {
17-
t.regex('\u001B[00;38;5;244m\u001B[m\u001B[00;38;5;33mfoo\u001B[0m', m());
17+
t.regex('\u001B[00;38;5;244m\u001B[m\u001B[00;38;5;33mfoo\u001B[0m', ansiRegex());
1818
});
1919

2020
test('match reset;setfg;setbg;italics;strike;underline sequence in a string', t => {
21-
t.regex('\u001B[0;33;49;3;9;4mbar\u001B[0m', m());
22-
t.is('foo\u001B[0;33;49;3;9;4mbar'.match(m())[0], '\u001B[0;33;49;3;9;4m');
21+
t.regex('\u001B[0;33;49;3;9;4mbar\u001B[0m', ansiRegex());
22+
t.is('foo\u001B[0;33;49;3;9;4mbar'.match(ansiRegex())[0], '\u001B[0;33;49;3;9;4m');
2323
});
2424

2525
test('match clear tabs sequence in a string', t => {
26-
t.regex('foo\u001B[0gbar', m());
27-
t.is('foo\u001B[0gbar'.match(m())[0], '\u001B[0g');
26+
t.regex('foo\u001B[0gbar', ansiRegex());
27+
t.is('foo\u001B[0gbar'.match(ansiRegex())[0], '\u001B[0g');
2828
});
2929

3030
test('match clear line from cursor right in a string', t => {
31-
t.regex('foo\u001B[Kbar', m());
32-
t.is('foo\u001B[Kbar'.match(m())[0], '\u001B[K');
31+
t.regex('foo\u001B[Kbar', ansiRegex());
32+
t.is('foo\u001B[Kbar'.match(ansiRegex())[0], '\u001B[K');
3333
});
3434

3535
test('match clear screen in a string', t => {
36-
t.regex('foo\u001B[2Jbar', m());
37-
t.is('foo\u001B[2Jbar'.match(m())[0], '\u001B[2J');
36+
t.regex('foo\u001B[2Jbar', ansiRegex());
37+
t.is('foo\u001B[2Jbar'.match(ansiRegex())[0], '\u001B[2J');
3838
});
3939

4040
test('match only first', t => {
41-
t.is('foo\u001B[4mcake\u001B[0m'.match(m({onlyFirst: true})).length, 1);
41+
t.is('foo\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true})).length, 1);
4242
});
4343

4444
test.failing('match "change icon name and window title" in string', t => {
45-
t.is('\u001B]0;sg@tota:~/git/\u0007\u001B[01;32m[sg@tota\u001B[01;37m misc-tests\u001B[01;32m]$'.match(m())[0], '\u001B]0;sg@tota:~/git/\u0007');
45+
t.is('\u001B]0;sg@tota:~/git/\u0007\u001B[01;32m[sg@tota\u001B[01;37m misc-tests\u001B[01;32m]$'.match(ansiRegex())[0], '\u001B]0;sg@tota:~/git/\u0007');
4646
});
4747

4848
// Testing against extended codes (excluding codes ending in 0-9)
@@ -61,9 +61,9 @@ for (const codeSet of Object.keys(ansiCodes)) {
6161
}
6262

6363
const string = `hel${ecode}lo`;
64-
t.regex(string, m());
65-
t.is(string.match(m())[0], ecode);
66-
t.is(string.replace(m(), ''), 'hello');
64+
t.regex(string, ansiRegex());
65+
t.is(string.match(ansiRegex())[0], ecode);
66+
t.is(string.replace(ansiRegex(), ''), 'hello');
6767
});
6868

6969
test(`${skipText}${code} should not overconsume`, t => {
@@ -74,9 +74,9 @@ for (const codeSet of Object.keys(ansiCodes)) {
7474

7575
for (const c of consumptionChars) {
7676
const string = ecode + c;
77-
t.regex(string, m());
78-
t.is(string.match(m())[0], ecode);
79-
t.is(string.replace(m(), ''), c);
77+
t.regex(string, ansiRegex());
78+
t.is(string.match(ansiRegex())[0], ecode);
79+
t.is(string.replace(ansiRegex(), ''), c);
8080
}
8181
});
8282
}

0 commit comments

Comments
 (0)
Please sign in to comment.