Skip to content

Commit

Permalink
chore(ignoreDigits): Strip back scope of new functionality
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
danielgolden committed Jul 29, 2022
1 parent ab689e1 commit d71c22b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 35 deletions.
13 changes: 2 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`'`)
Expand All @@ -34,7 +32,6 @@
* @property {Array<string>} ignore
* @property {boolean} ignoreLiteral
* @property {boolean} ignoreDigits
* @property {boolean} ignoreAnyDigits
* @property {boolean} normalizeApostrophes
* @property {any} checker
* @property {Record<string, Array<string>>} cache
Expand Down Expand Up @@ -72,7 +69,6 @@ export default function retextSpell(options = {}) {
max,
ignoreLiteral,
ignoreDigits,
ignoreAnyDigits,
normalizeApostrophes,
personal
} = options
Expand All @@ -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
Expand Down Expand Up @@ -170,7 +162,6 @@ function all(tree, file, config) {
ignore,
ignoreLiteral,
ignoreDigits,
ignoreAnyDigits,
normalizeApostrophes,
// To do: nspell.
// type-coverage:ignore-next-line
Expand Down Expand Up @@ -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))
)
}
}
9 changes: 2 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
20 changes: 3 additions & 17 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit d71c22b

Please sign in to comment.