{"id":13527612,"url":"https://github.com/wooorm/nspell","last_synced_at":"2025-04-04T10:03:50.113Z","repository":{"id":54992135,"uuid":"65242360","full_name":"wooorm/nspell","owner":"wooorm","description":"📝 Hunspell compatible spell-checker","archived":false,"fork":false,"pushed_at":"2021-01-17T14:48:43.000Z","size":156,"stargazers_count":277,"open_issues_count":8,"forks_count":18,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-28T09:03:09.828Z","etag":null,"topics":["check","checker","dictionaries","grammar","hunspell","myspell","node","spell","spellcheck","spellchecker","spelling"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wooorm.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":"funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"wooorm"}},"created_at":"2016-08-08T21:57:35.000Z","updated_at":"2025-03-13T06:02:06.000Z","dependencies_parsed_at":"2022-08-14T08:30:32.895Z","dependency_job_id":null,"html_url":"https://github.com/wooorm/nspell","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fnspell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fnspell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fnspell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fnspell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooorm","download_url":"https://codeload.github.com/wooorm/nspell/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247150740,"owners_count":20892193,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["check","checker","dictionaries","grammar","hunspell","myspell","node","spell","spellcheck","spellchecker","spelling"],"created_at":"2024-08-01T06:01:53.926Z","updated_at":"2025-04-04T10:03:50.091Z","avatar_url":"https://github.com/wooorm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/wooorm"],"categories":["JavaScript"],"sub_categories":[],"readme":"# nspell\n\n[![Travis][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n\nHunspell-like spell-checker in plain-vanilla JavaScript.\n\n**nspell** contains most of the essential core of Hunspell.\nIt does not contain a tokeniser but leaves many details up to implementors.\nThe main difference, conceptually, is that Hunspell is based on the user and\ntheir preferences, whereas **nspell** is based on explicitly passed in options,\nthus producing the same results regardless of OS, file system, or environment.\n\n## Contents\n\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`NSpell(dictionary)`](#nspelldictionary)\n    *   [`NSpell#correct(word)`](#nspellcorrectword)\n    *   [`NSpell#suggest(word)`](#nspellsuggestword)\n    *   [`NSpell#spell(word)`](#nspellspellword)\n    *   [`NSpell#add(word[, model])`](#nspelladdword-model)\n    *   [`NSpell#remove(word)`](#nspellremoveword)\n    *   [`NSpell#wordCharacters()`](#nspellwordcharacters)\n    *   [`NSpell#dictionary(dic)`](#nspelldictionarydic)\n    *   [`NSpell#personal(dic)`](#nspellpersonaldic)\n*   [Dictionaries](#dictionaries)\n    *   [Affix documents](#affix-documents)\n    *   [Dictionary documents](#dictionary-documents)\n    *   [Personal dictionary documents](#personal-dictionary-documents)\n    *   [Affix options](#affix-options)\n*   [License](#license)\n\n## Install\n\n[npm][]:\n\n```sh\nnpm install nspell\n```\n\nYou probably also want to install some [dictionaries][]:\n\n```sh\nnpm install dictionary-en\n```\n\n## Use\n\n```js\nvar dictionary = require('dictionary-en')\nvar nspell = require('nspell')\n\ndictionary(ondictionary)\n\nfunction ondictionary(err, dict) {\n  if (err) {\n    throw err\n  }\n\n  var spell = nspell(dict)\n\n  console.log(spell.correct('colour')) // =\u003e false\n  console.log(spell.suggest('colour')) // =\u003e ['color']\n  console.log(spell.correct('color')) // =\u003e true\n  console.log(spell.correct('npm')) // =\u003e false\n  spell.add('npm')\n  console.log(spell.correct('npm')) // =\u003e true\n}\n```\n\n## API\n\n### `NSpell(dictionary)`\n\nCreate a new spell checker.\nPassing an affix document is required, through any of the below mentioned\nsignatures.\n**nspell** is useless without at least one `dic` passed: make sure to pass one\neither in the constructor or to [`nspell#dictionary`][dictionary].\n\n###### Signatures\n\n*   `NSpell(dictionary)`\n*   `NSpell(aff[, dic])`\n*   `NSpell(dictionaries)`\n\n###### Parameters\n\n*   `dictionary` (`Object`)\n    — Object with `aff` (required) and `dic` (optional) properties\n*   `aff` (`Buffer` or `string`)\n    — Affix document to use.  Must be in UTF-8 when buffer\n*   `dic` (`Buffer` or `string`)\n    — Dictionary document to use.  Must be in UTF-8 when buffer\n*   `dictionaries` (`Array.\u003cDictionary\u003e`)\n    — List of `dictionary` objects.  The first must have an `aff` key,\n    other `aff` keys are ignored\n\n###### Returns\n\nNew instance of `NSpell`.\n\n### `NSpell#correct(word)`\n\nCheck if `word` is correctly spelled.\n\n###### Example\n\n```js\nspell.correct('color') // =\u003e true\nspell.correct('html') // =\u003e false\nspell.correct('abreviation') // =\u003e false\n```\n\n###### Parameters\n\n*   `word` (`string`) — Word to check for correct spelling\n\n###### Returns\n\n`boolean` — Whether `word` is correctly spelled.\n\n### `NSpell#suggest(word)`\n\nSuggest correctly spelled words close to `word`.\n\n###### Example\n\n```js\nspell.suggest('colour') // =\u003e ['color']\nspell.suggest('color') // =\u003e []\nspell.suggest('html') // =\u003e ['HTML']\nspell.suggest('alot') // =\u003e ['allot', 'slot', 'clot', …]\n```\n\n###### Parameters\n\n*   `word` (`string`) — Word to suggest spelling corrections for\n\n###### Returns\n\n`Array.\u003cstring\u003e` — List with zero or more suggestions.\n\n### `NSpell#spell(word)`\n\nGet spelling information for `word`.\n\n###### Example\n\n```js\nspell.spell('colour') // =\u003e {correct: false, forbidden: false, warn: false}\nspell.spell('color') // =\u003e {correct: true, forbidden: false, warn: false}\n```\n\n###### Parameters\n\n*   `word` (`string`) — Word to check\n\n###### Returns\n\n`Object`, with the following properties:\n\n*   `correct` (`boolean`)\n    — Whether `word` is correctly spelled\n*   `forbidden` (`boolean`)\n    — Whether `word` is actually correct, but forbidden from showing up as such\n    (often by the users wish)\n*   `warn` (`boolean`)\n    — Whether `word` is correct, but should trigger a warning\n    (rarely used in dictionaries)\n\n### `NSpell#add(word[, model])`\n\nAdd `word` to known words.\nIf no model is given, the word will be marked as correct in the future, and will\nshow up in spelling suggestions.\nIf a model is given, `word` will be handled the same as `model`.\n\n###### Example\n\n```js\nspell.correct('npm') // =\u003e false\nspell.suggest('nnpm') // =\u003e ['ppm', 'bpm', …]\n\nspell.add('npm')\n\nspell.correct('npm') // =\u003e true\nspell.suggest('nnpm') // =\u003e ['npm']\n```\n\n###### Parameters\n\n*   `word` (`string`) — Word to add\n*   `model` (`string`, optional) — Known word to model `word` after\n\n###### Returns\n\n`NSpell` — Operated on instance.\n\n### `NSpell#remove(word)`\n\nRemove `word` from the known words.\n\n###### Example\n\n```js\nspell.correct('color') // =\u003e true\n\nspell.remove('color')\n\nspell.correct('color') // =\u003e false\n```\n\n###### Parameters\n\n*   `word` (`string`) — Word to add\n\n###### Returns\n\n`NSpell` — Operated on instance.\n\n### `NSpell#wordCharacters()`\n\nGet extra word characters defined by the loaded affix file.\nMost affix files don’t set these, but for example the [en][] dictionary sets\n`0123456789`.\n\n###### Example\n\n```js\nspell.wordCharacters() // =\u003e '0123456789'\n```\n\n###### Returns\n\n`string?` — Defined word characters, if any.\n\n### `NSpell#dictionary(dic)`\n\nAdd an extra dictionary to the spellchecker.\n\n###### Example\n\n```js\nspell.dictionary(\n  ['5', 'npm', 'nullish', 'rebase', 'SHA', 'stringification'].join('\\n')\n)\n```\n\n###### Parameters\n\n*   `dic` (`Buffer` or `string`)\n    — Dictionary document to use; must be in UTF-8 when buffer\n\n###### Returns\n\n`NSpell` — Operated on instance.\n\n###### Note\n\nThe given `dic` must be designed to work with the already loaded affix.\nIt’s not possible to add dictionary files from different languages together\n(use two `NSpell` instances for that).\n\n### `NSpell#personal(dic)`\n\nAdd a personal dictionary.\n\n###### Example\n\n```js\nspell.personal(['foo', 'bar/color', '*baz'].join('\\n'))\n```\n\n###### Parameters\n\n*   `dic` (`Buffer` or `string`)\n    — Dictionary document to use; must be in UTF-8 when buffer\n\n###### Returns\n\n`NSpell` — Operated on instance.\n\n###### Note\n\nLines starting with a `*` mark a word as forbidden, which results in them being\nseen as incorrect, and prevents them from showing up in suggestions.\nSplitting a line in two with a slash, adds the left side and models it after the\nalready known right word.\n\n## Dictionaries\n\n**nspell** supports many parts of Hunspell-style dictionaries.\nEssentially, the concept of a dictionary consists of one “affix” document, and\none or more “dictionary” documents.\nThe documents are tightly linked, so it’s not possible to use a Dutch affix with\nan English dictionary document.\n\nBelow is a short introduction, see [hunspell(5)][hunspell-5] for more\ninformation.\n\n### Affix documents\n\nAffix documents define the language, keyboard, flags, and much more.\nFor example, a paraphrased [Dutch][nl] affix document looks as follows:\n\n```text\nSET UTF-8\n\nKEY qwertyuiop|asdfghjkl|zxcvbnm|qawsedrftgyhujikolp|azsxdcfvgbhnjmk|aze|qsd|lm|wx|aqz|qws|\n\nWORDCHARS '’0123456789ĳ.-\\/\n\nREP 487\nREP e en\nREP ji ĳ\nREP u oe\n# …\n\nSFX An Y 11\nSFX An 0 de d\nSFX An 0 fe f\nSFX An 0 ge g\n# …\n```\n\nNot every option is supported in **nspell**.\nSee [Affix options][affix-options] for a list of all options and which ones are\nsupported.\n\n### Dictionary documents\n\nDictionary documents contain words and flags applying to those words.\nFor example:\n\n```text\n3\nfoo\nbar/a\nbaz/ab\n```\n\nThe above document contains three words, as the count on the first line shows.\nFurther lines each start with a word.\nSome lines contain flags, as denoted by the slashes.\nWhat those flags do, and the size of flags, is defined by affix documents.\n\n### Personal dictionary documents\n\nPersonal dictionaries are not intertwined with affix document.\nThey define new words and words to forbid.\nFor example:\n\n```text\nfoo\nbar/baz\n*qux\n```\n\nIn the above example, `foo` is added as a known word; `bar` is added as well,\nbut modelled after the existing word `baz`; finally, `qux` is marked as a\nforbidden word.\n\n### Affix options\n\nThe following affix options are known to Hunspell.\nThe checked ones are supported by **nspell**.\n\n###### General\n\n*   [ ] `SET encoding` (UTF-8 is implied)\n*   [x] `FLAG value`\n*   [ ] `COMPLEXPREFIXES`\n*   [ ] `LANG langcode`\n*   [ ] `IGNORE characters`\n*   [ ] `AF number_of_flag_vector_aliases`\n*   [ ] `AF flag_vector`\n*   [ ] `AF definitions in the affix file:`\n*   [ ] `AF flag_vector`\n\n###### Suggestion\n\n*   [x] `KEY characters_separated_by_vertical_line_optionally`\n*   [x] `TRY characters`\n*   [x] `NOSUGGEST flag`\n*   [ ] `MAXCPDSUGS num`\n*   [ ] `MAXNGRAMSUGS num`\n*   [ ] `MAXDIFF [0-10]`\n*   [ ] `ONLYMAXDIFF`\n*   [ ] `NOSPLITSUGS`\n*   [ ] `SUGSWITHDOTS`\n*   [x] `REP number_of_replacement_definitions`\n*   [x] `REP what replacement`\n*   [ ] `MAP number_of_map_definitions`\n*   [ ] `MAP string_of_related_chars_or_parenthesized_character_sequences`\n*   [ ] `PHONE number_of_phone_definitions`\n*   [ ] `PHONE what replacement`\n*   [x] `WARN flag`\n*   [x] `FORBIDWARN`\n\n###### Compounding\n\n*   [ ] `BREAK number_of_break_definitions`\n*   [ ] `BREAK character_or_character_sequence`\n*   [x] `COMPOUNDRULE number_of_compound_definitions`\n*   [x] `COMPOUNDRULE compound_pattern`\n*   [x] `COMPOUNDMIN num`\n*   [ ] `COMPOUNDFLAG flag`\n*   [ ] `COMPOUNDBEGIN flag`\n*   [ ] `COMPOUNDLAST flag`\n*   [ ] `COMPOUNDMIDDLE flag`\n*   [x] `ONLYINCOMPOUND flag`\n*   [ ] `COMPOUNDPERMITFLAG flag`\n*   [ ] `COMPOUNDFORBIDFLAG flag`\n*   [ ] `COMPOUNDMORESUFFIXES`\n*   [ ] `COMPOUNDROOT flag`\n*   [ ] `COMPOUNDWORDMAX number`\n*   [ ] `CHECKCOMPOUNDDUP`\n*   [ ] `CHECKCOMPOUNDREP`\n*   [ ] `CHECKCOMPOUNDCASE`\n*   [ ] `CHECKCOMPOUNDTRIPLE`\n*   [ ] `SIMPLIFIEDTRIPLE`\n*   [ ] `CHECKCOMPOUNDPATTERN number_of_checkcompoundpattern_definitions`\n*   [ ] `CHECKCOMPOUNDPATTERN endchars[/flag] beginchars[/flag] [replacement]`\n*   [ ] `FORCEUCASE flag`\n*   [ ] `COMPOUNDSYLLABLE max_syllable vowels`\n*   [ ] `SYLLABLENUM flags`\n\n###### Affix creation\n\n*   [x] `PFX flag cross_product number`\n*   [x] `PFX flag stripping prefix [condition [morphological_fields…]]`\n*   [x] `SFX flag cross_product number`\n*   [x] `SFX flag stripping suffix [condition [morphological_fields…]]`\n\n###### Other\n\n*   [ ] `CIRCUMFIX flag`\n*   [x] `FORBIDDENWORD flag`\n*   [ ] `FULLSTRIP`\n*   [x] `KEEPCASE flag`\n*   [x] `ICONV number_of_ICONV_definitions`\n*   [x] `ICONV pattern pattern2`\n*   [x] `OCONV number_of_OCONV_definitions`\n*   [x] `OCONV pattern pattern2`\n*   [ ] `LEMMA_PRESENT flag`\n*   [x] `NEEDAFFIX flag`\n*   [ ] `PSEUDOROOT flag`\n*   [ ] `SUBSTANDARD flag`\n*   [x] `WORDCHARS characters`\n*   [ ] `CHECKSHARPS`\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/wooorm/nspell/workflows/main/badge.svg\n\n[build]: https://github.com/wooorm/nspell/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/nspell.svg\n\n[coverage]: https://codecov.io/github/wooorm/nspell\n\n[downloads-badge]: https://img.shields.io/npm/dm/nspell.svg\n\n[downloads]: https://www.npmjs.com/package/nspell\n\n[size-badge]: https://img.shields.io/bundlephobia/minzip/nspell.svg\n\n[size]: https://bundlephobia.com/result?p=nspell\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[dictionaries]: https://github.com/wooorm/dictionaries\n\n[en]: https://github.com/wooorm/dictionaries/tree/HEAD/dictionaries/en\n\n[nl]: https://github.com/wooorm/dictionaries/tree/HEAD/dictionaries/nl\n\n[hunspell-5]: https://linux.die.net/man/4/hunspell\n\n[affix-options]: #affix-options\n\n[dictionary]: #nspelldictionarydic\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fnspell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooorm%2Fnspell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fnspell/lists"}