@nextgensoftwares/folio-spell
The spell checker Folio's apps use when the host passes none: Hunspell dictionaries through nspell (MIT), without a DOM. It ships one dictionary, SCOWL's en_US Hunspell dictionary (2020.12.07, unmodified, from the dictionary-en package; its licence is in dict/LICENSE-en.txt).
import { builtInSpellChecker, createSpellChecker, bundledDictionaries } from '@nextgensoftwares/folio-spell';
const check = builtInSpellChecker(); // English, one instance per page
await check(['recieve', 'world'], 'en-US'); // [['receive', 'relieve'], null]
// Your own dictionaries (Hunspell .aff/.dic), loaded the first time text in that language is checked.
const mine = createSpellChecker({
dictionaries: { ...bundledDictionaries(), fr: async () => ({ aff: await get('fr.aff'), dic: await get('fr.dic') }) },
});folio-react's builtInSpellcheck wraps it as a lazy import: FolioApp and SlidesApp use it when their spellcheck is absent (false turns spelling off), so its code (about 6 KB gzipped) and the dictionary (550 KB, fetched as an asset beside the package's code) load on the first check, never while spelling is off.
- Languages: a word's language is its text's (
lang, BCP 47; the base language picks the dictionary). Text without one is checked asfallback(defaulten). A language without a dictionary is left alone, and so are words in another script than the dictionary's (Arabic or Japanese inside English text): nothing is flagged rather than everything. - Answers: null for a right word, else up to
suggestions(default 5) suggestions. Curly apostrophes are read as straight ones. Long batches yield to the page between slices of about 12 ms. - A dictionary that fails to load (offline, blocked) checks nothing.
bundledDictionaryUrls() gives the dictionary files' URLs (literal new URL(…, import.meta.url)s, so bundlers emit them as assets); a host serving them elsewhere passes its own loaders to createSpellChecker.