{"id":15412426,"url":"https://github.com/robertknight/approx-string-match-js","last_synced_at":"2025-09-16T04:32:22.893Z","repository":{"id":45979035,"uuid":"94767222","full_name":"robertknight/approx-string-match-js","owner":"robertknight","description":"Fast approximate string matching library for JavaScript","archived":false,"fork":false,"pushed_at":"2024-06-17T13:24:57.000Z","size":129,"stargazers_count":50,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-28T16:29:08.721Z","etag":null,"topics":["algorithms","javascript"],"latest_commit_sha":null,"homepage":"","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/robertknight.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":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-19T10:55:31.000Z","updated_at":"2024-12-27T21:01:52.000Z","dependencies_parsed_at":"2024-10-19T17:56:41.347Z","dependency_job_id":null,"html_url":"https://github.com/robertknight/approx-string-match-js","commit_stats":{"total_commits":57,"total_committers":3,"mean_commits":19.0,"dds":"0.052631578947368474","last_synced_commit":"fe814eba4d6b6daf88d38179331a14d156a0b5a0"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertknight%2Fapprox-string-match-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertknight%2Fapprox-string-match-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertknight%2Fapprox-string-match-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertknight%2Fapprox-string-match-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertknight","download_url":"https://codeload.github.com/robertknight/approx-string-match-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233210351,"owners_count":18642032,"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":["algorithms","javascript"],"created_at":"2024-10-01T16:52:59.905Z","updated_at":"2025-09-16T04:32:17.618Z","avatar_url":"https://github.com/robertknight.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# approx-string-match\n\nA library for approximate string matching.\n\nThis can be used to find occurrences of a pattern P (of length _m_) in a text T\n(of length _n_) allowing for up to a given number of errors (_k_), where errors may\ninclude insertions, substitutions or deletions of characters from the pattern.\n\nFor example the pattern \"annd\" occurs in the string \"four score and seven\" with\none error.\n\nThe implementation uses a bit-parallel algorithm by G. Myers [1] which, to the\nbest of my knowledge, is the state of the art algorithm for the online version\nof the problem (where the text and pattern cannot be preprocessed in advance).\nIt runs in _O((k/w) \\* n)_ expected-time where _k_ \u003c= _m_ and _w_ is the word\nsize (32 in JavaScript). It also includes some additional optimizations\nsuggested in [3]. See comments in the code for more details.\n\n## Usage\n\n```\nnpm install --save approx-string-match\n```\n\n```js\nimport search from \"approx-string-match\";\n\nconst text = \"Four score and seven\";\nconst pattern = \"annd\";\nconst matches = search(text, pattern, 2 /* max errors */);\nconsole.log(matches);\n\n// Outputs `[{ start: 11, end: 14, errors: 1 }]`\n```\n\n## API\n\nThe library exports a single function `search(text, pattern, maxErrors)` which\nreturns an array of the closest matches for _pattern_ in _text_ allowing up to\n_maxErrors_ errors.\n\n```ts\ninterface Match {\n  start: number;\n  end: number;\n  errors: number;\n}\n\nsearch(text: string, pattern: string, maxErrors: number): Match[]\n```\n\n## Implementation notes\n\n#### Word size\n\nThe algorithm uses bitwise operations on integers. Since JavaScript only\nsupports bitwise operations on 32-bit integers, that is the word size,\nregardless of the platform.\n\nIf JS gains support for bitwise operations on larger integers in future, that\nsupport could be used to speed up this library.\n\n#### Unicode\n\nThe library currently works on _code units_ rather than _code points_, where the\ncode unit is a UTF-16 value. What this means is that a change to a unicode\ncharacter which requires multiple characters to represent in a JavaScript\nstring, such as emoji, would actually count as two changes rather than one. This\nis because such chars require two elements to represent in a string (eg.\n`\"😊\".length` is 2).\n\n## Related reading\n\nFor an overview of the different approaches to approximate string matching and\nthe history of the development of solutions, there is a good survey paper [2].\n\n## References\n\n[1] G. Myers, “[A Fast Bit-Vector Algorithm for Approximate String Matching Based on\nDynamic\nProgramming](https://scholar.google.com/scholar?q=A+Fast+Bit-Vector+Algorithm+for+Approximate+String+Matching+Based+on+Dynamic+Programming),”\nvol. 46, no. 3, pp. 395–415, 1999.\n\n[2] G. Navarro, “[A guided tour to approximate string\nmatching](https://scholar.google.com/scholar?q=A+guided+tour+to+approximate+string+matching),”\nACM Comput. Surv., vol. 33, no. 1, pp. 31–88, 2001.\n\n[3] Šošić, M. (2014). \"[An SIMD dynamic programming c/c++ library](https://bib.irb.hr/datoteka/758607.diplomski_Martin_Sosic.pdf)\" (Doctoral dissertation, Fakultet Elektrotehnike i računarstva, Sveučilište u Zagrebu).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertknight%2Fapprox-string-match-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertknight%2Fapprox-string-match-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertknight%2Fapprox-string-match-js/lists"}