retext-spell
retext plugin to check spelling.
Contents
What is this?
This package is a unified (retext) plugin to check spelling with nspell
and a dictionary.
When should I use this?
You can opt-into this plugin when you’re dealing with content that might contain spelling mistakes, and have authors that can fix that content.
Install
This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with npm:
npm install retext-spell
Use
import {reporter} from 'vfile-reporter'
import {retext} from 'retext'
import retextSpell from 'retext-spell'
import dictionary from 'dictionary-en-gb'
const file = await retext()
.use(retextSpell, dictionary)
.process('Some useles documeant.')
console.error(reporter(file))
Yields:
1:6-1:12 warning `useles` is misspelt; did you mean `useless`? useles retext-spell
1:13-1:22 warning `documeant` is misspelt; did you mean `document`? documeant retext-spell
⚠ 2 warnings
API
This package exports no identifiers. The default export is retextSpell
.
unified().use(retextSpell, options)
Check spelling (with nspell
).
⚠️ Important:
retext-spell
is async. You must useprocess
instead ofprocessSync
.
Signatures
retext().use(spell, dictionary)
retext().use(spell, options)
options
Configuration (optional).
options.dictionary
A dictionary (Function
). Result of importing one of the dictionaries in wooorm/dictionaries
.
options.personal
Personal dictionary (string
or a Buffer
in UTF-8, optional).
options.ignore
List of words to ignore (Array<string>
, default []
).
options.ignoreLiteral
Whether to ignore literal words (boolean?
, default true
).
options.ignoreDigits
Whether to ignore “words” that contain only digits or times, such as 123456
or 2:41pm
(boolean?
, default true
).
options.normalizeApostrophes
Deal with apostrophes (boolean?
, default true
). Whether to swap smart apostrophes (’
) with straight apostrophes ('
) before checking spelling. Dictionaries typically support this, but this option can be used if not.
options.max
Number of unique words to suggest for (number?
, default 30
). By default, up to thirty words are suggested for. Further misspellings are still warned about, but without suggestions. Increasing this number significantly impacts performance.
Messages
Each message is emitted as a VFileMessage
on file
, with the following fields:
message.source
Name of this plugin ('retext-spell'
).
message.ruleId
Normalized not ok word (string
, such as 'useles'
).
message.actual
Current not ok word (string
, such as 'Useles'
).
message.expected
List of suggestions of words to use (Array<string>
, such as ['Useless']
).
Types
This package is fully typed with TypeScript. It exports the additional types Options
and Dictionary
.
Compatibility
Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. Our projects sometimes work with older versions, but this is not guaranteed.
Related
retext-contractions
— check apostrophe use in contractionsretext-diacritics
— check for proper use of diacriticsretext-indefinite-article
— check if indefinite articles (a
,an
) are used correctlyretext-redundant-acronyms
— check for redundant acronyms (ATM machine
)retext-repeated-words
— checkfor for
repeated wordsretext-emoji
— classify emoji, gemoji, emoticonsretext-syntax-mentions
— classify @mentions as syntaxretext-syntax-urls
— classify URLs and filepaths as syntax
Contribute
See contributing.md
in retextjs/.github
for ways to get started. See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.