From d82ae60c6222093431b724cc6c8f7735aacc7f19 Mon Sep 17 00:00:00 2001 From: teabyii Date: Sat, 15 Feb 2020 11:44:54 +0800 Subject: [PATCH 1/4] Fix #17, add test case, release 0.23 --- lib/Builder.js | 3 +++ package.json | 2 +- test/issue-17-test.js | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/issue-17-test.js diff --git a/lib/Builder.js b/lib/Builder.js index 5e5d483..4c51c83 100644 --- a/lib/Builder.js +++ b/lib/Builder.js @@ -761,6 +761,9 @@ class Builder { _mapCaptureIndexToName(result) { const names = this._captureNames + // No match + if (!result) return null + return Array.prototype.reduce.call(result.slice(1), (result, current, index) => { if (names[index]) { result[names[index]] = current || '' diff --git a/package.json b/package.json index bd24ba3..c587421 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "srl", - "version": "0.2.2", + "version": "0.2.3", "description": "Simple Regex Language", "main": "lib/SRL.js", "scripts": { diff --git a/test/issue-17-test.js b/test/issue-17-test.js new file mode 100644 index 0000000..ec5f359 --- /dev/null +++ b/test/issue-17-test.js @@ -0,0 +1,16 @@ +'use strict' + +const assert = require('assert') +const SRL = require('../') + +describe('Fix issue 17', () => { + it('Capture group name assignment fails', () => { + assert.doesNotThrow(() => { + const query = new SRL('capture (literally "TEST") as test') + const match = query.getMatch('WORD NOT HERE') + console.log(match) + }, TypeError); + }) +}) + + From 8c08fade471509a4674e2ef1f0494362adf4ed18 Mon Sep 17 00:00:00 2001 From: teabyii Date: Sat, 15 Feb 2020 11:53:24 +0800 Subject: [PATCH 2/4] Fix eslint for travis --- .eslintrc | 5 +---- .travis.yml | 3 +-- lib/Builder.js | 4 ++-- package.json | 2 ++ 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.eslintrc b/.eslintrc index 2052e44..1d0a4a1 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,8 +1,5 @@ { - "ecmaFeatures": { - "modules": true - }, - "env": { + "env": { "node": true, "es6": true, "mocha": true diff --git a/.travis.yml b/.travis.yml index 138cf6d..6c068e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,9 @@ cache: - node_modules install: - npm install - - npm install -g eslint - npm install -g codecov script: - - eslint . + - npm run lint - istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec - codecov diff --git a/lib/Builder.js b/lib/Builder.js index 4c51c83..96398ad 100644 --- a/lib/Builder.js +++ b/lib/Builder.js @@ -215,7 +215,7 @@ class Builder { noDigit() { this._validateAndAddMethodType(METHOD_TYPE_CHARACTER, METHOD_TYPES_ALLOWED_FOR_CHARACTERS) - return this.add(`[^0-9]`) + return this.add('[^0-9]') } /** @@ -762,7 +762,7 @@ class Builder { const names = this._captureNames // No match - if (!result) return null + if (!result) {return null} return Array.prototype.reduce.call(result.slice(1), (result, current, index) => { if (names[index]) { diff --git a/package.json b/package.json index c587421..cbac627 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "lib/SRL.js", "scripts": { "test": "mocha", + "lint": "eslint lib --fix", "coverage": "istanbul cover _mocha" }, "repository": { @@ -30,6 +31,7 @@ }, "homepage": "https://simple-regex.com", "devDependencies": { + "eslint": "^6.8.0", "istanbul": "^0.4.5", "mocha": "^3.0.2", "mocha-lcov-reporter": "^1.2.0" From 82628fc405377aada00a5e8d47d5fc14a32c3d6b Mon Sep 17 00:00:00 2001 From: teabyii Date: Sat, 15 Feb 2020 11:59:00 +0800 Subject: [PATCH 3/4] Tweak travis --- .travis.yml | 4 +++- README.md | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6c068e8..ec02ede 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: node_js node_js: - - "6" + - 8 + - 10 + - 12 cache: - node_modules install: diff --git a/README.md b/README.md index 4e67cfb..e57f4b1 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ query .get() // /[a-z]{3}[0-9]*$/g ``` -Required Node 6.0+ for the ES6 support, Or you can use [Babel](http://babeljs.io/) to support Node below 6.0. +Required Node 8.0+ for the ES6 support, Or you can use [Babel](http://babeljs.io/) to support Node below 6.0. Using [Webpack](http://webpack.github.io) and [babel-loader](https://github.com/babel/babel-loader) to pack it if want to use in browsers. From 392faf0eabed61d0d50fbef31296b4704d17bdc1 Mon Sep 17 00:00:00 2001 From: teabyii Date: Sat, 15 Feb 2020 12:05:13 +0800 Subject: [PATCH 4/4] Tweak test case --- test/issue-17-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/issue-17-test.js b/test/issue-17-test.js index ec5f359..2a30be1 100644 --- a/test/issue-17-test.js +++ b/test/issue-17-test.js @@ -8,8 +8,8 @@ describe('Fix issue 17', () => { assert.doesNotThrow(() => { const query = new SRL('capture (literally "TEST") as test') const match = query.getMatch('WORD NOT HERE') - console.log(match) - }, TypeError); + assert.equal(match, null) + }, TypeError) }) })