From 87fbee61318f4292f70976047af4e8404d782d3a Mon Sep 17 00:00:00 2001 From: hrai <4055444+hrai@users.noreply.github.com> Date: Sat, 12 Oct 2024 18:08:53 +1100 Subject: [PATCH] Fixed nums regex match (#268) * cleanup * cleanup --- .husky/common.sh | 8 ++++++++ package.json | 2 +- src/utils.js | 4 ++-- test/util.test.js | 5 +++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .husky/common.sh diff --git a/.husky/common.sh b/.husky/common.sh new file mode 100644 index 0000000..35bc37b --- /dev/null +++ b/.husky/common.sh @@ -0,0 +1,8 @@ +command_exists () { + command -v "$1" > /dev/null 2>&1 & +} + +# Windows 10, Git Bash and Yarn workaround +if command_exists winpty && test -t 1; then + exec < /dev/tty +fi diff --git a/package.json b/package.json index 9c74a70..a72d77f 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "nodemon": "^3.0.3", "prettier": "^3.2.5", "run-script-os": "^1.1.3", - "sinon": "^18.0.0", + "sinon": "^19.0.2", "web-ext": "^8.2.0", "web-ext-submit": "^7.8.0", "webextension-polyfill": "^0.12.0", diff --git a/src/utils.js b/src/utils.js index 1d7780d..6df4ec3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -164,7 +164,7 @@ export function setKeyValue(keyValueName, value) { } export function shouldCapitalise(text) { - const multilineRegex = /\s*\n+\s*\w$/; + const multilineRegex = /\s*\n+\s*[a-z]$/; let matches = multilineRegex.test(text); //console.log("matches:" + matches); @@ -173,7 +173,7 @@ export function shouldCapitalise(text) { return true; } - const sentenceRegex = /\w+\s*\W?([.?!])+\s+\w$/; + const sentenceRegex = /\w+\s*\W?([.?!])+\s+[a-z]$/; matches = sentenceRegex.test(text); if (!matches) { diff --git a/test/util.test.js b/test/util.test.js index ad32a6b..f5d6d6d 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -76,6 +76,8 @@ describe('util file tests', function () { expect(utils.shouldCapitalise(' k ')).toBe(false); expect(utils.shouldCapitalise(' k ')).toBe(false); expect(utils.shouldCapitalise(' ')).toBe(false); + expect(utils.shouldCapitalise(' 1')).toBe(false); + expect(utils.shouldCapitalise('this is ? 1')).toBe(false); expect(utils.shouldCapitalise('?')).toBe(true); expect(utils.shouldCapitalise('!')).toBe(true); @@ -97,6 +99,9 @@ describe('util file tests', function () { expect(utils.shouldCapitalise('war? lasting \n peace \n\n k')).toBe( true ); + + expect(utils.shouldCapitalise('war? \n\n 1')).toBe(false); + expect(utils.shouldCapitalise('war? \n\n 12')).toBe(false); }); test('shouldCapitalise_singleChar', () => {