From 166a0d5eddedacf0db7ccd7ee137b862ab1dae70 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 31 May 2019 13:58:17 +0700 Subject: [PATCH] Require Node.js 8 --- .travis.yml | 2 +- index.js | 8 ++------ package.json | 6 +++--- test.js | 8 ++++---- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2ae9d62..f98fed0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js node_js: + - '12' - '10' - '8' - - '6' diff --git a/index.js b/index.js index c254480..35054aa 100644 --- a/index.js +++ b/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'); }; diff --git a/package.json b/package.json index a849fdf..713ecfc 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=6" + "node": ">=8" }, "scripts": { "test": "xo && ava", @@ -47,7 +47,7 @@ "pattern" ], "devDependencies": { - "ava": "^0.25.0", - "xo": "^0.23.0" + "ava": "^1.4.1", + "xo": "^0.24.0" } } diff --git a/test.js b/test.js index f8b4519..d24c22d 100644 --- a/test.js +++ b/test.js @@ -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 => { @@ -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; @@ -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);