From 3884998d61ddaa46e12d4fcbb3cf0b4bc2004486 Mon Sep 17 00:00:00 2001 From: danielgolden Date: Tue, 26 Jul 2022 07:06:33 -0400 Subject: [PATCH 1/7] chore(Tests): Add test for ignore words with digits option --- test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test.js b/test.js index 98efb88..2de44c3 100644 --- a/test.js +++ b/test.js @@ -223,6 +223,17 @@ test('should ignore digits', (t) => { }, t.ifErr) }) +test('should ignore words that contain any digits', (t) => { + t.plan(1) + + retext() + .use(retextSpell, enGb) + .process('2:41pm') + .then((file) => { + check(t, file, []) + }, t.ifErr) +}) + test('should treat smart apostrophes as straight apostrophes', (t) => { t.plan(3) From 2f65236f479a707c74d0c61791a908c5d12c1a39 Mon Sep 17 00:00:00 2001 From: danielgolden Date: Tue, 26 Jul 2022 07:21:05 -0400 Subject: [PATCH 2/7] chore(Tests): Improve existing test and add another --- test.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/test.js b/test.js index 2de44c3..dafbece 100644 --- a/test.js +++ b/test.js @@ -227,8 +227,11 @@ test('should ignore words that contain any digits', (t) => { t.plan(1) retext() - .use(retextSpell, enGb) - .process('2:41pm') + .use(retextSpell, { + dictionary: enGb, + ignoreAnyDigits: true + }) + .process('2:41pm is a gr8 time for A11y enthusiasts.') .then((file) => { check(t, file, []) }, t.ifErr) @@ -322,6 +325,17 @@ test('should not ignore words that include digits', (t) => { }, t.ifErr) }) +test('...unless `ignoreAnyDigits` is true', (t) => { + t.plan(1) + + retext() + .use(retextSpell, {dictionary: enGb, ignoreAnyDigits: true}) + .process('768x1024') + .then((file) => { + check(t, file, []) + }, t.ifErr) +}) + test('should `ignore`', (t) => { t.plan(1) From 5003a00340d7e96d216c622babc1f9f65320ff59 Mon Sep 17 00:00:00 2001 From: danielgolden Date: Tue, 26 Jul 2022 07:22:27 -0400 Subject: [PATCH 3/7] chore(Options): Add option - It's set to by default - The JSDoc documentation for it has also been added --- index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index fdbb120..5c6b5c4 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,8 @@ * Whether to ignore literal words. * @property {boolean} [ignoreDigits=true] * Whether to ignore “words” that contain only digits, such as `123456`. + * @property {boolean} [ignoreAnyDigits=false] + * Whether to ignore “words” that contain *any* digits, such as `2:41pm` or `A11y`. * @property {boolean} [normalizeApostrophes=true] * Deal with apostrophes. * Whether to swap smart apostrophes (`’`) with straight apostrophes (`'`) @@ -32,6 +34,7 @@ * @property {Array} ignore * @property {boolean} ignoreLiteral * @property {boolean} ignoreDigits + * @property {boolean} ignoreAnyDigits * @property {boolean} normalizeApostrophes * @property {any} checker * @property {Record>} cache @@ -69,6 +72,7 @@ export default function retextSpell(options = {}) { max, ignoreLiteral, ignoreDigits, + ignoreAnyDigits, normalizeApostrophes, personal } = options @@ -89,6 +93,10 @@ export default function retextSpell(options = {}) { : ignoreLiteral, ignoreDigits: ignoreDigits === null || ignoreDigits === undefined ? true : ignoreDigits, + ignoreAnyDigits: + ignoreAnyDigits === null || ignoreAnyDigits === undefined + ? false + : ignoreAnyDigits, normalizeApostrophes: normalizeApostrophes === null || normalizeApostrophes === undefined ? true @@ -162,6 +170,7 @@ function all(tree, file, config) { ignore, ignoreLiteral, ignoreDigits, + ignoreAnyDigits, normalizeApostrophes, // To do: nspell. // type-coverage:ignore-next-line @@ -286,6 +295,10 @@ function all(tree, file, config) { * @returns {boolean} */ function irrelevant(word) { - return ignore.includes(word) || (ignoreDigits && /^\d+$/.test(word)) + return ( + ignore.includes(word) || + (ignoreDigits && /^\d+$/.test(word)) || + (ignoreAnyDigits && /\d/.test(word)) + ) } } From 80c0488ad5c50e13f00fbe7fd2c5e0666f7eb4a8 Mon Sep 17 00:00:00 2001 From: danielgolden Date: Tue, 26 Jul 2022 07:29:25 -0400 Subject: [PATCH 4/7] docs(README): Add documentation for ignoreAnyDigits option --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index b50c336..0fbd202 100644 --- a/readme.md +++ b/readme.md @@ -111,6 +111,10 @@ Whether to ignore [literal words][literal] (`boolean?`, default `true`). Whether to ignore “words” that contain only digits, such as `123456` (`boolean?`, default `true`). +###### `options.ignoreAnyDigits` + +Whether to ignore “words” that contain *any* digits, such as `2:41pm` or `A11y`. +(`boolean?`, default `false`). ###### `options.normalizeApostrophes` From ab689e1c2d5d06edc021bea15969705830270956 Mon Sep 17 00:00:00 2001 From: danielgolden Date: Tue, 26 Jul 2022 07:32:53 -0400 Subject: [PATCH 5/7] docs(README): Minor formatting adjustment --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 0fbd202..e6b60f1 100644 --- a/readme.md +++ b/readme.md @@ -111,6 +111,7 @@ Whether to ignore [literal words][literal] (`boolean?`, default `true`). Whether to ignore “words” that contain only digits, such as `123456` (`boolean?`, default `true`). + ###### `options.ignoreAnyDigits` Whether to ignore “words” that contain *any* digits, such as `2:41pm` or `A11y`. From d71c22bf2917b28ade1157eb2c530e9a35002614 Mon Sep 17 00:00:00 2001 From: danielgolden Date: Fri, 29 Jul 2022 09:53:12 -0400 Subject: [PATCH 6/7] chore(ignoreDigits): Strip back scope of new functionality - Removes the recently added prop and stuffs it's time ignoring functionality into the prop. - Updates tests to reflect the above changes - Updates README to reflect the above changes --- index.js | 13 ++----------- readme.md | 9 ++------- test.js | 20 +++----------------- 3 files changed, 7 insertions(+), 35 deletions(-) diff --git a/index.js b/index.js index 5c6b5c4..3e8e2e4 100644 --- a/index.js +++ b/index.js @@ -16,9 +16,7 @@ * @property {boolean} [ignoreLiteral=true] * Whether to ignore literal words. * @property {boolean} [ignoreDigits=true] - * Whether to ignore “words” that contain only digits, such as `123456`. - * @property {boolean} [ignoreAnyDigits=false] - * Whether to ignore “words” that contain *any* digits, such as `2:41pm` or `A11y`. + * Whether to ignore “words” that contain only digits or are times, such as `123456` or `2:41pm`. * @property {boolean} [normalizeApostrophes=true] * Deal with apostrophes. * Whether to swap smart apostrophes (`’`) with straight apostrophes (`'`) @@ -34,7 +32,6 @@ * @property {Array} ignore * @property {boolean} ignoreLiteral * @property {boolean} ignoreDigits - * @property {boolean} ignoreAnyDigits * @property {boolean} normalizeApostrophes * @property {any} checker * @property {Record>} cache @@ -72,7 +69,6 @@ export default function retextSpell(options = {}) { max, ignoreLiteral, ignoreDigits, - ignoreAnyDigits, normalizeApostrophes, personal } = options @@ -93,10 +89,6 @@ export default function retextSpell(options = {}) { : ignoreLiteral, ignoreDigits: ignoreDigits === null || ignoreDigits === undefined ? true : ignoreDigits, - ignoreAnyDigits: - ignoreAnyDigits === null || ignoreAnyDigits === undefined - ? false - : ignoreAnyDigits, normalizeApostrophes: normalizeApostrophes === null || normalizeApostrophes === undefined ? true @@ -170,7 +162,6 @@ function all(tree, file, config) { ignore, ignoreLiteral, ignoreDigits, - ignoreAnyDigits, normalizeApostrophes, // To do: nspell. // type-coverage:ignore-next-line @@ -298,7 +289,7 @@ function all(tree, file, config) { return ( ignore.includes(word) || (ignoreDigits && /^\d+$/.test(word)) || - (ignoreAnyDigits && /\d/.test(word)) + (ignoreDigits && /^\d{1,2}:\d{2}(?:[ap]\.?m)?$/i.test(word)) ) } } diff --git a/readme.md b/readme.md index e6b60f1..b8e65e4 100644 --- a/readme.md +++ b/readme.md @@ -109,13 +109,8 @@ Whether to ignore [literal words][literal] (`boolean?`, default `true`). ###### `options.ignoreDigits` -Whether to ignore “words” that contain only digits, such as `123456` -(`boolean?`, default `true`). - -###### `options.ignoreAnyDigits` - -Whether to ignore “words” that contain *any* digits, such as `2:41pm` or `A11y`. -(`boolean?`, default `false`). +Whether to ignore “words” that contain only digits or times, such as +`123456` or `2:41pm` (`boolean?`, default `true`). ###### `options.normalizeApostrophes` diff --git a/test.js b/test.js index dafbece..5acc36d 100644 --- a/test.js +++ b/test.js @@ -223,15 +223,12 @@ test('should ignore digits', (t) => { }, t.ifErr) }) -test('should ignore words that contain any digits', (t) => { +test('should ignore times', (t) => { t.plan(1) retext() - .use(retextSpell, { - dictionary: enGb, - ignoreAnyDigits: true - }) - .process('2:41pm is a gr8 time for A11y enthusiasts.') + .use(retextSpell, enGb) + .process('2:41pm') .then((file) => { check(t, file, []) }, t.ifErr) @@ -325,17 +322,6 @@ test('should not ignore words that include digits', (t) => { }, t.ifErr) }) -test('...unless `ignoreAnyDigits` is true', (t) => { - t.plan(1) - - retext() - .use(retextSpell, {dictionary: enGb, ignoreAnyDigits: true}) - .process('768x1024') - .then((file) => { - check(t, file, []) - }, t.ifErr) -}) - test('should `ignore`', (t) => { t.plan(1) From 45f316e650171a435a64456f1e020c1ea89952be Mon Sep 17 00:00:00 2001 From: Titus Date: Sat, 30 Jul 2022 11:13:11 +0200 Subject: [PATCH 7/7] Apply suggestions from code review --- index.js | 2 +- test.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 3e8e2e4..2051fa0 100644 --- a/index.js +++ b/index.js @@ -289,7 +289,7 @@ function all(tree, file, config) { return ( ignore.includes(word) || (ignoreDigits && /^\d+$/.test(word)) || - (ignoreDigits && /^\d{1,2}:\d{2}(?:[ap]\.?m)?$/i.test(word)) + (ignoreDigits && /^\d{1,2}:\d{2}(?:[ap]\.?m\.?)?$/i.test(word)) ) } } diff --git a/test.js b/test.js index 5acc36d..2938862 100644 --- a/test.js +++ b/test.js @@ -224,14 +224,21 @@ test('should ignore digits', (t) => { }) test('should ignore times', (t) => { - t.plan(1) + t.plan(2) retext() .use(retextSpell, enGb) - .process('2:41pm') + .process('Let’s meet at 2:41pm.') .then((file) => { check(t, file, []) }, t.ifErr) + + retext() + .use(retextSpell, enGb) + .process("On my way! ETA 11:50!") + .then((file) => { + check(t, file, []); + }, t.ifErr); }) test('should treat smart apostrophes as straight apostrophes', (t) => {