Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 31, 2019
1 parent f115fca commit 166a0d5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '12'
- '10'
- '8'
- '6'
8 changes: 2 additions & 6 deletions index.js
@@ -1,14 +1,10 @@
'use strict';

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

module.exports = ({onlyFirst = false} = {}) => {
const pattern = [
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
].join('|');

return new RegExp(pattern, options.onlyFirst ? undefined : 'g');
return new RegExp(pattern, onlyFirst ? undefined : 'g');
};
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava",
Expand Down Expand Up @@ -47,7 +47,7 @@
"pattern"
],
"devDependencies": {
"ava": "^0.25.0",
"xo": "^0.23.0"
"ava": "^1.4.1",
"xo": "^0.24.0"
}
}
8 changes: 4 additions & 4 deletions test.js
Expand Up @@ -2,7 +2,7 @@ import test from 'ava';
import ansiCodes from './fixtures/ansi-codes';
import ansiRegex from '.';

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

// Testing against codes found at: http://ascii-table.com/ansi-escape-sequences-vt-100.php
test('match ansi code in a string', t => {
Expand Down Expand Up @@ -67,7 +67,7 @@ for (const codeSet of Object.keys(ansiCodes)) {
const skipText = skip ? '[SKIP] ' : '';
const ecode = `\u001B${code}`;

test(`${skipText}${code}${codeInfo[0]}`, t => {
test(`${codeSet} - ${skipText}${code}${codeInfo[0]}`, t => {
if (skip) {
t.pass();
return;
Expand All @@ -79,13 +79,13 @@ for (const codeSet of Object.keys(ansiCodes)) {
t.is(string.replace(ansiRegex(), ''), 'hello');
});

test(`${skipText}${code} should not overconsume`, t => {
test(`${codeSet} - ${skipText}${code} should not overconsume`, t => {
if (skip) {
t.pass();
return;
}

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

0 comments on commit 166a0d5

Please sign in to comment.