Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ignoring times (12:34) ignoreDigits is on #25

Merged
merged 7 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`'`)
Expand All @@ -32,6 +34,7 @@
* @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 @@ -69,6 +72,7 @@ export default function retextSpell(options = {}) {
max,
ignoreLiteral,
ignoreDigits,
ignoreAnyDigits,
normalizeApostrophes,
personal
} = options
Expand All @@ -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
Expand Down Expand Up @@ -162,6 +170,7 @@ function all(tree, file, config) {
ignore,
ignoreLiteral,
ignoreDigits,
ignoreAnyDigits,
normalizeApostrophes,
// To do: nspell.
// type-coverage:ignore-next-line
Expand Down Expand Up @@ -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))
)
}
}
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ 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`

Deal with apostrophes (`boolean?`, default `true`).
Expand Down
25 changes: 25 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ test('should ignore digits', (t) => {
}, t.ifErr)
})

test('should ignore words that contain any digits', (t) => {
t.plan(1)
wooorm marked this conversation as resolved.
Show resolved Hide resolved

retext()
.use(retextSpell, {
dictionary: enGb,
ignoreAnyDigits: true
})
.process('2:41pm is a gr8 time for A11y enthusiasts.')
.then((file) => {
check(t, file, [])
}, t.ifErr)
wooorm marked this conversation as resolved.
Show resolved Hide resolved
})

test('should treat smart apostrophes as straight apostrophes', (t) => {
t.plan(3)

Expand Down Expand Up @@ -311,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)

Expand Down