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 6 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
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +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`.
* 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 Down Expand Up @@ -286,6 +286,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)) ||
(ignoreDigits && /^\d{1,2}:\d{2}(?:[ap]\.?m)?$/i.test(word))
wooorm marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +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`).
Whether to ignore “words” that contain only digits or times, such as
`123456` or `2:41pm` (`boolean?`, default `true`).

###### `options.normalizeApostrophes`

Expand Down
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ test('should ignore digits', (t) => {
}, t.ifErr)
})

test('should ignore times', (t) => {
t.plan(1)
wooorm marked this conversation as resolved.
Show resolved Hide resolved

retext()
.use(retextSpell, enGb)
.process('2:41pm')
wooorm marked this conversation as resolved.
Show resolved Hide resolved
.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