From d71c22bf2917b28ade1157eb2c530e9a35002614 Mon Sep 17 00:00:00 2001 From: danielgolden Date: Fri, 29 Jul 2022 09:53:12 -0400 Subject: [PATCH] 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)