@react-native-gpui/spellcheck
v0.0.1
Published
Spell checking for React Native GPUI apps: misspelled ranges, suggestions, the user's dictionary and the available languages
Readme
@react-native-gpui/spellcheck
Spell checking for react-native-gpui apps: the misspelled words in a text, suggestions, the app's own dictionary and the languages the system can check.
About
This is our own module; it has no upstream library.
Install
npm install @react-native-gpui/spellcheckUsage
import {
check,
suggest,
learn,
forget,
getLanguages,
} from '@react-native-gpui/spellcheck';
const languages = await getLanguages(); // [{ code: 'en-US', name: 'English (United States)' }, ...]
const text = 'This is a tset';
for (const { start, length } of await check(text, ['en-US'])) {
console.log(
text.slice(start, start + length),
await suggest(text.slice(start, start + length), ['en-US']),
);
}
await learn('Notesnook'); // kept in the app's own dictionaryRanges are UTF-16 offsets, as String indexes them. With several languages a word is misspelled only when none accepts it.
macOS only for now, through NSSpellChecker; other platforms reject with ERR_UNSUPPORTED. The app's dictionary (learn, forget, getLearnedWords) is kept in a file under the app's support directory and is not the system's, so a word learned here is not accepted in other apps, as with a browser's custom dictionary.
Platforms
macOS only for now, through NSSpellChecker; Windows and Linux reject with ERR_UNSUPPORTED.
Limitations
Ranges are UTF-16 offsets. With several languages a word is misspelled only when none accepts it.
Documentation
License
MIT. See LICENSE.
