{"id":15767956,"url":"https://github.com/bubkoo/spelling-suggestion","last_synced_at":"2025-04-21T04:31:26.258Z","repository":{"id":56716243,"uuid":"523954613","full_name":"bubkoo/spelling-suggestion","owner":"bubkoo","description":"Given a name and a list of names that are not equal to the name, return a spelling suggestion if there is one that is close enough.","archived":false,"fork":false,"pushed_at":"2024-01-01T03:10:19.000Z","size":259,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T20:00:21.283Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/bubkoo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-12T04:28:28.000Z","updated_at":"2023-03-08T22:58:05.000Z","dependencies_parsed_at":"2024-10-04T13:42:06.080Z","dependency_job_id":"044f5a83-cc68-4d43-a2be-c0047168a2a1","html_url":"https://github.com/bubkoo/spelling-suggestion","commit_stats":{"total_commits":16,"total_committers":4,"mean_commits":4.0,"dds":0.4375,"last_synced_commit":"6f0673e1b32cea20d1382fa9d46aebdedb1dbef2"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Fspelling-suggestion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Fspelling-suggestion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Fspelling-suggestion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Fspelling-suggestion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bubkoo","download_url":"https://codeload.github.com/bubkoo/spelling-suggestion/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249996091,"owners_count":21358061,"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":[],"created_at":"2024-10-04T13:41:55.153Z","updated_at":"2025-04-21T04:31:25.938Z","avatar_url":"https://github.com/bubkoo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eSpelling Suggestion\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\u003cstrong\u003eGiven a name and a list of names that are not equal to the name, return a spelling suggestion if there is one that is close enough.\u003c/strong\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/bubkoo/spelling-suggestion?style=flat-square\" alt=\"MIT License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.typescriptlang.org\"\u003e\u003cimg alt=\"Language\" src=\"https://img.shields.io/badge/language-TypeScript-blue.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/bubkoo/spelling-suggestion/pulls\"\u003e\u003cimg alt=\"PRs Welcome\" src=\"https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/bubkoo/spelling-suggestion/actions/workflows/ci.yml\"\u003e\u003cimg alt=\"build\" src=\"https://img.shields.io/github/actions/workflow/status/bubkoo/spelling-suggestion/ci.yml?branch=master\u0026logo=github\u0026style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://app.codecov.io/gh/bubkoo/spelling-suggestion\"\u003e\u003cimg alt=\"coverage\" src=\"https://img.shields.io/codecov/c/gh/bubkoo/spelling-suggestion?logo=codecov\u0026style=flat-square\u0026token=BWweeU2uNX\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## Install\n\n```shell\nnpm install --save spelling-suggestion\n```\n\n## Usage\nNames less than length 3 only check for case-insensitive equality, not Levenshtein distance.\n\n- If there is a candidate that's the same except for case, return that.\n- If there is a candidate that's within one edit of the name, return that.\n- Otherwise, return the candidate with the smallest Levenshtein distance, except for candidates: \n  - With no name\n  - Whose length differs from the target name by more than 0.34 of the length of the name. \n  - Whose levenshtein distance is more than 0.4 of the length of the name (0.4 allows 1 substitution/transposition for every 5 characters, and 1 insertion/deletion at 3 characters)\n\n\n```js\nimport { getSpellingSuggestion } from 'spelling-suggestion';\n\n// return the best matched item\ngetSpellingSuggestion(\n  'foo',\n  [\n    { name: 'fo' },\n    { name: 'foo' },\n    { name: 'book' },\n    { name: 'cook' },\n    { name: 'food' },\n  ],\n  (candidate) =\u003e candidate.name,\n)\n// =\u003e { name: 'food' }\n\n// return the best matched string\ngetSpellingSuggestion('foo', ['fo', 'foo', 'book', 'cook', 'food']) // =\u003e food\n\n// return the best matched string with case-insensitive equality\ngetSpellingSuggestion('foo', ['fo', 'Foo', 'book', 'cook', 'food']) // =\u003e Foo\n\n// return undefined when no match found\ngetSpellingSuggestion('fo', ['fo', 'foo', 'book', 'cook', 'food']) // =\u003e undefined\n\n// return the first best match\ngetSpellingSuggestion('foo', ['fo', 'foo', 'food', 'fooo', 'fook']) // =\u003e food\ngetSpellingSuggestion('foo', ['fo', 'foo', 'fook', 'food', 'fooo']) // =\u003e fook\ngetSpellingSuggestion('foo', ['fo', 'foo', 'fooo', 'fook', 'food']) // =\u003e fooo\n```\n\n\n## Contributing\n\nPlease let us know how can we help. Do check out [issues](https://github.com/bubkoo/spelling-suggestion/issues) for bug reports or suggestions first.\n\nTo become a contributor, please follow our [contributing guide](/CONTRIBUTING.md).\n\n\u003ca href=\"https://github.com/bubkoo/spelling-suggestion/graphs/contributors\"\u003e\n  \u003cimg src=\"/CONTRIBUTORS.svg\" alt=\"Contributors\" width=\"740\" /\u003e\n\u003c/a\u003e\n\n\n## License\n\nThe scripts and documentation in this project are released under the [MIT License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbubkoo%2Fspelling-suggestion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbubkoo%2Fspelling-suggestion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbubkoo%2Fspelling-suggestion/lists"}