Skip to content

Commit baacbab

Browse files
committedJun 20, 2017
Require Node.js 4 and meta tweaks
1 parent 7c908e7 commit baacbab

9 files changed

+152
-167
lines changed
 

‎.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
99

10-
[{package.json,*.yml}]
10+
[*.yml]
1111
indent_style = space
1212
indent_size = 2

‎.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
sudo: false
21
language: node_js
32
node_js:
3+
- '8'
44
- '6'
55
- '4'
6-
- '0.12'
7-
- '0.10'

‎fixtures/ansi-codes.js

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
'use strict';
22

3-
// from http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
3+
// From http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
44
exports.vt52Codes = {
5-
'A': ['Cursor up'],
6-
'B': ['Cursor down'],
7-
'C': ['Cursor right'],
8-
'D': ['Cursor left'],
9-
'H': ['Cursor to home'],
10-
'I': ['Reverse line feed'],
11-
'J': ['Erase to end of screen'],
12-
'K': ['Erase to end of line'],
13-
'Z': ['Identify'],
5+
A: ['Cursor up'],
6+
B: ['Cursor down'],
7+
C: ['Cursor right'],
8+
D: ['Cursor left'],
9+
H: ['Cursor to home'],
10+
I: ['Reverse line feed'],
11+
J: ['Erase to end of screen'],
12+
K: ['Erase to end of line'],
13+
Z: ['Identify'],
1414
'=': ['Enter alternate keypad mode'],
1515
'>': ['Exit alternate keypad mode'],
16-
'1': ['Graphics processor on'],
17-
'2': ['Graphics processor off'],
16+
1: ['Graphics processor on'],
17+
2: ['Graphics processor off'],
1818
'<': ['Enter ANSI mode']
1919
};
2020

21-
// from http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
21+
// From http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
2222
exports.ansiCompatible = {
2323
'[176A': ['Cursor up Pn lines'],
2424
'[176B': ['Cursor down Pn lines'],
@@ -27,8 +27,8 @@ exports.ansiCompatible = {
2727
'[176;176H': ['Direct cursor addressing, where Pl is line#, Pc is column#'],
2828
'[176;176f': ['Direct cursor addressing, where Pl is line#, Pc is column#'],
2929

30-
'7': ['Save cursor and attributes'],
31-
'8': ['Restore cursor and attributes'],
30+
7: ['Save cursor and attributes'],
31+
8: ['Restore cursor and attributes'],
3232

3333
'#3': ['Change this line to double-height top half'],
3434
'#4': ['Change this line to double-height bottom half'],
@@ -45,7 +45,7 @@ exports.ansiCompatible = {
4545
'[J': ['Erase from cursor to end of screen'],
4646
'[0J': ['Same'],
4747
'[2J': ['Erase entire screen'],
48-
'[P' : ['Delete character'],
48+
'[P': ['Delete character'],
4949
'[0P': ['Delete character (0P)'],
5050
'[2P': ['Delete 2 characters'],
5151

@@ -60,7 +60,7 @@ exports.ansiCompatible = {
6060
'(2': ['Alternative graphic ROM (Character Set G0)'],
6161
')2': ['Alternative graphic ROM (Character Set G1)'],
6262

63-
'H': ['Set tab at current column'],
63+
H: ['Set tab at current column'],
6464
'[g': ['Clear tab at current column'],
6565
'[0g': ['Same'],
6666
'[3g': ['Clear all tabs'],
@@ -72,12 +72,12 @@ exports.ansiCompatible = {
7272
'[0c': ['(response; teminal not Ok)'],
7373
'[?1;176c': ['response; where Ps is option present:'],
7474

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

80-
// from http://ascii-table.com/ansi-escape-sequences-vt-100.php
80+
// From http://ascii-table.com/ansi-escape-sequences-vt-100.php
8181
exports.commonCodes = {
8282
'[176A': ['Move cursor up n lines', 'CUU'],
8383
'[176B': ['Move cursor down n lines', 'CUD'],
@@ -110,8 +110,8 @@ exports.commonCodes = {
110110
'[?8l': ['Reset auto-repeat mode', 'DECARM'],
111111
'[?9l': ['Reset interlacing mode', 'DECINLM'],
112112

113-
'N': ['Set single shift 2', 'SS2'],
114-
'O': ['Set single shift 3', 'SS3'],
113+
N: ['Set single shift 2', 'SS2'],
114+
O: ['Set single shift 3', 'SS3'],
115115

116116
'[m': ['Turn off character attributes', 'SGR0'],
117117
'[0m': ['Turn off character attributes', 'SGR0'],
@@ -151,10 +151,10 @@ exports.commonCodes = {
151151
'[;H': ['Move cursor to upper left corner', 'cursorhome'],
152152
'[f': ['Move cursor to upper left corner', 'hvhome'],
153153
'[;f': ['Move cursor to upper left corner', 'hvhome'],
154-
'M': ['Move/scroll window down one line', 'RI'],
155-
'E': ['Move to next line', 'NEL'],
154+
M: ['Move/scroll window down one line', 'RI'],
155+
E: ['Move to next line', 'NEL'],
156156

157-
'H': ['Set a tab at the current column', 'HTS'],
157+
H: ['Set a tab at the current column', 'HTS'],
158158
'[g': ['Clear a tab at the current column', 'TBC'],
159159
'[0g': ['Clear a tab at the current column', 'TBC'],
160160
'[3g': ['Clear all tabs', 'TBC'],
@@ -170,7 +170,7 @@ exports.commonCodes = {
170170

171171
'[c': ['Identify what terminal type', 'DA'],
172172
'[0c': ['Identify what terminal type (another)', 'DA'],
173-
'c': ['Reset terminal to initial state', 'RIS'],
173+
c: ['Reset terminal to initial state', 'RIS'],
174174
'[2;1y': ['Confidence power up test', 'DECTST'],
175175
'[2;2y': ['Confidence loopback test', 'DECTST'],
176176
'[2;9y': ['Repeat power up test', 'DECTST'],
@@ -182,10 +182,10 @@ exports.commonCodes = {
182182
'[4q': ['Turn on LED #4', 'DECLL4']
183183
};
184184

185-
// from http://ascii-table.com/ansi-escape-sequences-vt-100.php
185+
// From http://ascii-table.com/ansi-escape-sequences-vt-100.php
186186
exports.otherCode = {
187-
'7': ['Save cursor position and attributes', 'DECSC'],
188-
'8': ['Restore cursor position and attributes', 'DECSC'],
187+
7: ['Save cursor position and attributes', 'DECSC'],
188+
8: ['Restore cursor position and attributes', 'DECSC'],
189189

190190
'=': ['Set alternate keypad mode', 'DECKPAM'],
191191
'>': ['Set numeric keypad mode', 'DECKPNM'],

‎fixtures/view-codes.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
'use strict';
2-
var ansiRegex = require('../');
3-
var ansiCodes = require('./ansi-codes');
4-
var allCodes = {};
5-
var supported = [];
6-
var unsupported = [];
2+
const ansiRegex = require('..');
3+
const ansiCodes = require('./ansi-codes');
4+
5+
const allCodes = {};
6+
const supported = [];
7+
const unsupported = [];
78

89
function addCodesToTest(codes) {
9-
for (var code in codes) {
10+
for (const code in codes) {
1011
allCodes[code] = codes[code];
1112
}
1213
}
1314

1415
function identifySupportedCodes() {
15-
var codeSupport = {};
16+
let codeSupport = {};
1617

17-
for (var code in allCodes) {
18+
for (const code in allCodes) {
1819
codeSupport = {
19-
code: code,
20-
matches: ('\u001b' + code).match(ansiRegex()),
20+
code,
21+
matches: `\u001B${code}`.match(ansiRegex()),
2122
description: allCodes[code][0]
2223
};
2324

24-
if (codeSupport.matches !== null && codeSupport.matches[0] === '\u001b' + code) {
25+
if (codeSupport.matches !== null && codeSupport.matches[0] === `\u001B${code}`) {
2526
supported.push(codeSupport);
2627
} else {
2728
unsupported.push(codeSupport);
@@ -30,21 +31,21 @@ function identifySupportedCodes() {
3031
}
3132

3233
function displaySupport() {
33-
process.stdout.write('\u001b[32m');
34+
process.stdout.write('\u001B[32m');
3435

3536
console.log('SUPPORTED');
36-
for (var i = 0; i < supported.length; i++) {
37-
console.log(supported[i]);
37+
for (const el of supported) {
38+
console.log(el);
3839
}
3940

40-
process.stdout.write('\u001b[31m');
41+
process.stdout.write('\u001B[31m');
4142
console.log('UNSUPPORTED');
4243

43-
for (var j = 0; j < unsupported.length; j++) {
44-
console.log(unsupported[j]);
44+
for (const el of unsupported) {
45+
console.log(el);
4546
}
4647

47-
process.stdout.write('\u001b[0m');
48+
process.stdout.write('\u001B[0m');
4849
}
4950

5051
addCodesToTest(ansiCodes.vt52Codes);

‎index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
'use strict';
2-
module.exports = function () {
3-
return /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><]/g;
4-
};
2+
module.exports = () => (/[\u001B\u009B][[()#;?]*(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PRZcf-nqry=><]/g);

‎license

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
The MIT License (MIT)
1+
MIT License
22

33
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
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:
116

12-
The above copyright notice and this permission notice shall be included in
13-
all copies or substantial portions of the Software.
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
148

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎package.json

+56-62
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,58 @@
11
{
2-
"name": "ansi-regex",
3-
"version": "2.1.1",
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-
"maintainers": [
13-
"Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)",
14-
"Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)",
15-
"JD Ballard <i.am.qix@gmail.com> (github.com/qix-)"
16-
],
17-
"engines": {
18-
"node": ">=0.10.0"
19-
},
20-
"scripts": {
21-
"test": "xo && ava --verbose",
22-
"view-supported": "node fixtures/view-codes.js"
23-
},
24-
"files": [
25-
"index.js"
26-
],
27-
"keywords": [
28-
"ansi",
29-
"styles",
30-
"color",
31-
"colour",
32-
"colors",
33-
"terminal",
34-
"console",
35-
"cli",
36-
"string",
37-
"tty",
38-
"escape",
39-
"formatting",
40-
"rgb",
41-
"256",
42-
"shell",
43-
"xterm",
44-
"command-line",
45-
"text",
46-
"regex",
47-
"regexp",
48-
"re",
49-
"match",
50-
"test",
51-
"find",
52-
"pattern"
53-
],
54-
"devDependencies": {
55-
"ava": "0.17.0",
56-
"xo": "0.16.0"
57-
},
58-
"xo": {
59-
"rules": {
60-
"guard-for-in": 0,
61-
"no-loop-func": 0
62-
}
63-
}
2+
"name": "ansi-regex",
3+
"version": "2.1.1",
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+
},
53+
"xo": {
54+
"rules": {
55+
"guard-for-in": 0
56+
}
57+
}
6458
}

‎readme.md

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# ansi-regex [![Build Status](https://travis-ci.org/chalk/ansi-regex.svg?branch=master)](https://travis-ci.org/chalk/ansi-regex)
22

3-
> Regular expression for matching [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code)
3+
> Regular expression for matching [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
44
55

66
## Install
77

88
```
9-
$ npm install --save ansi-regex
9+
$ npm install ansi-regex
1010
```
1111

1212

@@ -15,25 +15,32 @@ $ npm install --save ansi-regex
1515
```js
1616
const ansiRegex = require('ansi-regex');
1717

18-
ansiRegex().test('\u001b[4mcake\u001b[0m');
18+
ansiRegex().test('\u001B[4mcake\u001B[0m');
1919
//=> true
2020

2121
ansiRegex().test('cake');
2222
//=> false
2323

24-
'\u001b[4mcake\u001b[0m'.match(ansiRegex());
25-
//=> ['\u001b[4m', '\u001b[0m']
24+
'\u001B[4mcake\u001B[0m'.match(ansiRegex());
25+
//=> ['\u001B[4m', '\u001B[0m']
2626
```
2727

28+
2829
## FAQ
2930

3031
### Why do you test for codes not in the ECMA 48 standard?
3132

32-
Some of the codes we run as a test are codes that we acquired finding various lists of non-standard or manufacturer specific codes. If I recall correctly, we test for both standard and non-standard codes, as most of them follow the same or similar format and can be safely matched in strings without the risk of removing actual string content. There are a few non-standard control codes that do not follow the traditional format (i.e. they end in numbers) thus forcing us to exclude them from the test because we cannot reliably match them.
33+
Some of the codes we run as a test are codes that we acquired finding various lists of non-standard or manufacturer specific codes. We test for both standard and non-standard codes, as most of them follow the same or similar format and can be safely matched in strings without the risk of removing actual string content. There are a few non-standard control codes that do not follow the traditional format (i.e. they end in numbers) thus forcing us to exclude them from the test because we cannot reliably match them.
3334

3435
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.
3536

3637

38+
## Maintainers
39+
40+
- [Sindre Sorhus](https://github.com/sindresorhus)
41+
- [Josh Junon](https://github.com/qix-)
42+
43+
3744
## License
3845

39-
MIT © [Sindre Sorhus](http://sindresorhus.com)
46+
MIT

‎test.js

+28-29
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,71 @@
11
import test from 'ava';
22
import ansiCodes from './fixtures/ansi-codes';
3-
import m from './';
3+
import m from '.';
44

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

7-
// testing against codes found at: http://ascii-table.com/ansi-escape-sequences-vt-100.php
7+
// 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.true(m().test('foo\u001b[4mcake\u001b[0m'));
10-
t.true(m().test('\u001b[4mcake\u001b[0m'));
11-
t.true(m().test('foo\u001b[4mcake\u001b[0m'));
12-
t.true(m().test('\u001b[0m\u001b[4m\u001b[42m\u001b[31mfoo\u001b[39m\u001b[49m\u001b[24mfoo\u001b[0m'));
13-
t.true(m().test('foo\u001b[mfoo'));
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());
1414
});
1515

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

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

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

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

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

40-
// testing against extended codes (excluding codes ending in 0-9)
40+
// Testing against extended codes (excluding codes ending in 0-9)
4141
for (const codeSet in ansiCodes) {
42-
for (var code in ansiCodes[codeSet]) {
42+
for (const code in ansiCodes[codeSet]) {
4343
const codeInfo = ansiCodes[codeSet][code];
44-
const skip = /[0-9]$/.test(code);
44+
const skip = /\d$/.test(code);
4545
const skipText = skip ? '[SKIP] ' : '';
46-
const ecode = '\u001b' + code;
46+
const ecode = `\u001B${code}`;
4747

48-
test(skipText + code + ' -> ' + codeInfo[0], t => {
48+
test(`${skipText}${code}${codeInfo[0]}`, t => {
4949
if (skip) {
50+
t.pass();
5051
return;
5152
}
5253

53-
const string = 'hel' + ecode + 'lo';
54-
55-
t.true(m().test(string));
54+
const string = `hel${ecode}lo`;
55+
t.regex(string, m());
5656
t.is(string.match(m())[0], ecode);
5757
t.is(string.replace(m(), ''), 'hello');
5858
});
5959

60-
test(skipText + code + ' should not overconsume', t => {
60+
test(`${skipText}${code} should not overconsume`, t => {
6161
if (skip) {
62+
t.pass();
6263
return;
6364
}
6465

65-
for (var i = 0; i < consumptionChars.length; i++) {
66-
const c = consumptionChars[i];
66+
for (const c of consumptionChars) {
6767
const string = ecode + c;
68-
69-
t.true(m().test(string));
68+
t.regex(string, m());
7069
t.is(string.match(m())[0], ecode);
7170
t.is(string.replace(m(), ''), c);
7271
}

0 commit comments

Comments
 (0)
Please sign in to comment.