{"id":13508734,"url":"https://github.com/jfmdev/simple-spellchecker","last_synced_at":"2025-04-05T12:06:35.385Z","repository":{"id":53551106,"uuid":"53958651","full_name":"jfmdev/simple-spellchecker","owner":"jfmdev","description":"A simple and fast spellchecker with spelling suggestions and Electron's integration","archived":false,"fork":false,"pushed_at":"2024-07-13T19:24:20.000Z","size":27182,"stargazers_count":78,"open_issues_count":1,"forks_count":34,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T11:06:46.695Z","etag":null,"topics":["electron","electron-app","javascript","node-js","nodejs","spellcheck","spellchecker"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jfmdev.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-15T16:01:23.000Z","updated_at":"2025-03-13T05:53:03.000Z","dependencies_parsed_at":"2024-01-13T20:36:57.752Z","dependency_job_id":"8cde9030-edaf-4bd3-99f1-32bbace85771","html_url":"https://github.com/jfmdev/simple-spellchecker","commit_stats":{"total_commits":51,"total_committers":18,"mean_commits":"2.8333333333333335","dds":0.6862745098039216,"last_synced_commit":"68ce326b60fe156259fbebb2a396ecf48498ce52"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfmdev%2Fsimple-spellchecker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfmdev%2Fsimple-spellchecker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfmdev%2Fsimple-spellchecker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfmdev%2Fsimple-spellchecker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jfmdev","download_url":"https://codeload.github.com/jfmdev/simple-spellchecker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332604,"owners_count":20921853,"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":["electron","electron-app","javascript","node-js","nodejs","spellcheck","spellchecker"],"created_at":"2024-08-01T02:00:57.680Z","updated_at":"2025-04-05T12:06:35.359Z","avatar_url":"https://github.com/jfmdev.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"Simple Spellchecker\n===================\n\n\u003e A simple and fast spellchecker with spelling suggestions and Electron's integration\n\n\nFeatures\n--------\n\n**Simple Spellchecker** is a spellchecker module for Node.js, that allows to check if a word is misspelled and to get spelling suggestions.\n\nIt comes with dictionaries for English, Spanish, French, German and Dutch, but you can easily add more languages by simply defining a text file with a list of valid words.\n\nIt also has a CLI tool that allows to check words from the command line.\n\nUsage\n-----\n\nIn order to use the module, you must first install it using NPM.\n\n    npm install simple-spellchecker\n\nAnd then require the module, get a `Dictionary` object and invoke their methods.\n\n```javascript\nvar SpellChecker = require('simple-spellchecker');\nSpellChecker.getDictionary(\"fr-FR\", function(err, dictionary) {\n    if(!err) {\n        var misspelled = ! dictionary.spellCheck('maisonn');\n        if(misspelled) {\n            var suggestions = dictionary.getSuggestions('maisonn');\n        }\n    }\n});    \n```\n\nMethods\n-------\n\n### Module\n\nThe module has three public methods: `getDictionary()`,  `getDictionarySync()` and `normalizeDictionary()`.\n\n#### getDictionary(fileName [, folderPath], callback)\n\nThis method allows to get a `Dictionary` instance from a file. \n\nParameters:\n * `fileName`: The name of the dictionary's file. The method is going to first search a file with `.dic` extension, if not found, then is going to search a `.zip` and is going to unzip it.\n * `folderPath`: The folder in which the dictionary's file is located. This parameter is optional, by default it assumes that the file is in the `dict` folder.\n * `callback`: A function which is going to be invoked for return the `Dictionary` object.\n\nExample: \n\n```javascript\nvar SpellChecker = require('simple-spellchecker');\nSpellChecker.getDictionary(\"fr-FR\", function(err, result) {\n    var dictionary = result;\n});    \n```\n\n#### getDictionarySync(fileName [, folderPath])\n\nThis method allows to get a `Dictionary` instance from a file, in a synchronous way.\n\nParameters:\n * `fileName`: The name of the dictionary's file. The file must have `.dic` extension.\n * `folderPath`: The folder in which the dictionary's file is located. This parameter is optional, by default it assumes that the file is in the `dict` folder.\n\nReturns:\n * A `Dictionary` object. \n\nExample: \n\n```javascript\nvar SpellChecker = require('simple-spellchecker');\nvar dictionary = SpellChecker.getDictionarySync(\"fr-FR\");    \n```\n\n#### normalizeDictionary(inputPath [, outputPath], callback)\n\nThis methods reads a UTF-8 dictionary file, removes the BOM and `\\r` characters and sorts the list of words.\n\nParameters:\n * `inputPath`: The path of the dictionary file.\n * `outputPath`: The path for the normalized dictionary file. This parameter is optional, by deafult the original file is overwritten.\n * `callback`: A function which is going to be invoked when the process has finished.\n\nExample:\n\n```javascript\nvar SpellChecker = require('simple-spellchecker');\nSpellChecker.normalizeDictionary(inputFile, outputFile, function(err, success) {\n    if(success) console.log(\"The file was normalized\");\n}); \n```   \n\n### Dictionary\n\nThe `Dictionary` class has six public methods: `getLength()`,  `setWordlist()`,  `spellCheck()`,  `isMisspelled()`,  `getSuggestions()` and `checkAndSuggest()`\n\n#### getLength()\n\nThis method allows to get the quantity of words that the dictionary has.\n\nReturns:\n * An integer with the number of words. \n\n#### setWordlist(wordlist)\n\nThis method allows to set the words of the dictionary.\n\nParameter:\n * `wordlist`: an array of strings.\n\n### spellCheck(word)\n\nThis method allows to verify is a word is correctly written or not.\n\nParameter:\n * `word`: the word to verify.\n\nReturns:\n * `true` if the word is in the dictionary, `false` if not. \n\n#### isMisspelled(word)\n\nThis method allows to verify is a word is misspelled or not.\n\nParameter:\n * `word`: the word to verify.\n\nReturns:\n * `true` if the word is misspelled, `false` if not\n\n#### getSuggestions(word [, limit] [, maxDistance])\n\nThis method allows to get spelling suggestions for a word.\n\nParameters:\n * `word`: the word used to generate the suggestions.\n * `limit`: the maximum number of suggestions to get (by default, 5).\n * `maxDistance`: the maximum _edit distance_ that a word can have from the `word` parameter, in order to being considered as a valid suggestion (by default, 2).\n\nReturns:\n * An array of strings.\n\n#### checkAndSuggest(word [, limit] [, maxDistance])\n\nThis method allows to verify if a word is misspelled and to get spelling suggestions.\n\nParameters:\n * `word`: the word to verify.\n * `limit`: the maximum number of suggestions to get (by default, 5).\n * `maxDistance`: the maximum _edit distance_ that a word can have from the `word` parameter, in order to being considered as a valid suggestion (by default, 2).\n\nReturns:\n * An object with the fields `misspelled`, which contains a boolean, and `suggestions`, which contains an array of strings.\n\n#### addRegex(regex)\n\nThis method adds a regular expression that will be used to verify if a word is valid even though is not in the dictionary.\n\nThis might be useful when avoiding marking special words as misspelled, such as numbers, emails, or URL addresses.\n\nParameters:\n * `regex`: a regular expression object.\n\n#### clearRegex\n\nThis method removes all previous regular expressions added using the method `addRegex()`.\n\nAdd dictionaries\n----------------\n\nIn order to use custom dictionaries, you must define a text file with a list of valid words, where each word is separated by a new line. \n\n### File's name\n\nThe file's extension must be `.dic`, and the name should (preferably) be composed by the language code and the region designator (e.g. `es-AR` if the language is Spanish and the region is Argentina).\n\nOptionally you can also pack the file in a ZIP package, the module is going to be able to unzip it and read it as long as the `.zip` file has the same name has the `.dic` file (e.g. a file `es-AR.zip` that contains the file `es-AR.dic`). \n\n### File's encoding\n\nThe file must be encoded in UTF8 (without BOM), the words must be separated with a _Line Feed_ (i.e. `\\n`) and not with a _Carriage Return_ plus a _Line Feed_ (i.e. `\\r\\n`), and the words must be sorted in ascending order.\n\nThe module can remove all unwanted characters and sort the words, if you either invoke the `normalize()` method or pack the file in a ZIP file (the module automatically calls the `normalize()` method after unzip it).\n\nCLI tools\n---------\n\nThe module comes with a script that allows to normalize dictionaries and to test them.\n\n### Test\n\nIn order to test a dictionary file, you must execute the script indicating the folder and the name of the dictionary's file and the word that you want to test. \n\nFor example, the following sentence will search in the `dict` folder a dictionary which is either in the file `en-GB.dic` or `en-GB.zip`, and is going to verify if the word `house` is misspelled or not and is going to search some spelling suggestions.\n\n    node cli.js check \"./dict\" en-GB house\n    \n\n### Normalize\n\nIn order to normalize a dictionary file, you must execute the script indicating the file's path:\n\n    node cli.js normalize \"./dict/en-GB.dic\"\n\nIf you don't want to override the original file, you can specify the path for an output file:\n\n    node cli.js normalize \"./dict/en-GB.dic\" \"C:/output/en-GB.dic\"\n\nElectron's integration\n----------------------\n\nThere are several ways in which you can integrate this module with Electron. But if you want a starting point, the following example shows how to enable the English dictionary:\n\n**1)** Install the module as a dependency of your project (`npm install simple-spellchecker --save`).\n\n**2)** In the main process, require the module, load the dictionary, and define a function to access to his methods:\n\n```javascript\n// Initialization.\nvar SpellChecker = require('simple-spellchecker');\nvar myDictionary = null;\n\n// Load dictionary.\nSpellChecker.getDictionary(\"en-US\", \"./node_modules/simple-spellchecker/dict\", function(err, result) {\n    if(!err) {\n        myDictionary = result;\n    }\n});\n\n// Define function for consult the dictionary.\nipcMain.on('checkspell', function(event, word) {\n    var res = null;\n    if(myDictionary != null \u0026\u0026 word != null) {\n        res = myDictionary.spellCheck(word);\n    }\n    event.returnValue = res;\n});\n```\n\n**3)** In the renderer process, define a spell checker provider that uses the previously loaded dictionary.\n\n```javascript\n// Get web frame.\nvar webFrame = require('electron').webFrame;\n\nwebFrame.setSpellCheckProvider(\"en-US\", false, {\n    spellCheck: function(text) {      \n        var res = ipcRenderer.sendSync('checkspell', text);\n        return res != null? res : true;\n    }\n});\n```\n\nUnit testing\n------------\n\nThe module is partially tested by the file `test.js` (using _Mocha_ and _Chai_). In order to run the tests, just execute the command `npm test`.\n\nLicense\n-------\n\nSimple Spellchecker is free software; you can redistribute it and/or modify it under the terms of the Mozilla Public License v2.0. \nYou should have received a copy of the MPL 2.0 along with this library, otherwise you can obtain one at \u003chttp://mozilla.org/MPL/2.0/\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfmdev%2Fsimple-spellchecker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjfmdev%2Fsimple-spellchecker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfmdev%2Fsimple-spellchecker/lists"}