Skip to content

Commit

Permalink
Require Node.js 6
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 18, 2018
1 parent eac826a commit ced7421
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 86 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
- '4'
2 changes: 1 addition & 1 deletion fixtures/ansi-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ exports.otherCode = new Map([
['6n', ['Get cursor position', 'DSR']]
]);

// urxvt escapes
// `urxvt` escapes
exports.urxvt = new Map([
['[5~', ['URxvt.keysym.Prior']],
['[6~', ['URxvt.keysym.Next']],
Expand Down
4 changes: 2 additions & 2 deletions fixtures/view-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ const supported = [];
const unsupported = [];

function addCodesToTest(codes) {
for (const code in codes) {
for (const code of Object.keys(codes)) {
allCodes[code] = codes[code];
}
}

function identifySupportedCodes() {
let codeSupport = {};

for (const code in allCodes) {
for (const code of Object.keys(allCodes)) {
codeSupport = {
code,
matches: `\u001B${code}`.match(ansiRegex()),
Expand Down
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';

const defaultOptions = {
onlyFirst: false
};

module.exports = options => {
options = Object.assign({}, defaultOptions, options);
options = Object.assign({
onlyFirst: false
}, options);

const pattern = [
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)',
Expand Down
102 changes: 51 additions & 51 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
{
"name": "ansi-regex",
"version": "3.0.0",
"description": "Regular expression for matching ANSI escape codes",
"license": "MIT",
"repository": "chalk/ansi-regex",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava",
"view-supported": "node fixtures/view-codes.js"
},
"files": [
"index.js"
],
"keywords": [
"ansi",
"styles",
"color",
"colour",
"colors",
"terminal",
"console",
"cli",
"string",
"tty",
"escape",
"formatting",
"rgb",
"256",
"shell",
"xterm",
"command-line",
"text",
"regex",
"regexp",
"re",
"match",
"test",
"find",
"pattern"
],
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "ansi-regex",
"version": "3.0.0",
"description": "Regular expression for matching ANSI escape codes",
"license": "MIT",
"repository": "chalk/ansi-regex",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && ava",
"view-supported": "node fixtures/view-codes.js"
},
"files": [
"index.js"
],
"keywords": [
"ansi",
"styles",
"color",
"colour",
"colors",
"terminal",
"console",
"cli",
"string",
"tty",
"escape",
"formatting",
"rgb",
"256",
"shell",
"xterm",
"command-line",
"text",
"regex",
"regexp",
"re",
"match",
"test",
"find",
"pattern"
],
"devDependencies": {
"ava": "^0.25.0",
"xo": "^0.23.0"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Returns a regex for matching ANSI escape codes.
Type: `boolean`<br>
Default: `false` *(Matches any ANSI escape codes in a string)*

Match only the first one.<br>
Match only the first ANSI escape.


## FAQ
Expand Down
46 changes: 23 additions & 23 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
import test from 'ava';
import ansiCodes from './fixtures/ansi-codes';
import m from '.';
import ansiRegex from '.';

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

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

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

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

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

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

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

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

test.failing('match "change icon name and window title" in string', t => {
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');
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');
});

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

const string = `hel${ecode}lo`;
t.regex(string, m());
t.is(string.match(m())[0], ecode);
t.is(string.replace(m(), ''), 'hello');
t.regex(string, ansiRegex());
t.is(string.match(ansiRegex())[0], ecode);
t.is(string.replace(ansiRegex(), ''), 'hello');
});

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

for (const c of consumptionChars) {
const string = ecode + c;
t.regex(string, m());
t.is(string.match(m())[0], ecode);
t.is(string.replace(m(), ''), c);
t.regex(string, ansiRegex());
t.is(string.match(ansiRegex())[0], ecode);
t.is(string.replace(ansiRegex(), ''), c);
}
});
}
Expand Down

0 comments on commit ced7421

Please sign in to comment.