{"id":15896423,"url":"https://github.com/sandinmyjoints/equivalency","last_synced_at":"2025-03-20T15:32:44.247Z","repository":{"id":33011281,"uuid":"149523681","full_name":"sandinmyjoints/equivalency","owner":"sandinmyjoints","description":"Declaratively define rules for string equivalence so you can focus on the differences that matter.","archived":false,"fork":false,"pushed_at":"2024-03-25T17:57:30.000Z","size":1637,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-04-26T11:02:17.500Z","etag":null,"topics":["comparison","javascript","string-distance","strings"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sandinmyjoints.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2018-09-19T23:26:00.000Z","updated_at":"2024-04-26T11:02:28.323Z","dependencies_parsed_at":"2024-04-26T11:12:24.074Z","dependency_job_id":null,"html_url":"https://github.com/sandinmyjoints/equivalency","commit_stats":null,"previous_names":["spanishdict/equivalency"],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandinmyjoints%2Fequivalency","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandinmyjoints%2Fequivalency/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandinmyjoints%2Fequivalency/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandinmyjoints%2Fequivalency/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sandinmyjoints","download_url":"https://codeload.github.com/sandinmyjoints/equivalency/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244075622,"owners_count":20393980,"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":["comparison","javascript","string-distance","strings"],"created_at":"2024-10-06T09:08:15.605Z","updated_at":"2025-03-20T15:32:43.841Z","avatar_url":"https://github.com/sandinmyjoints.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Equivalency\n\n## Focus on the differences that matter.\n\nEquivalency lets you declaratively define rules for string equivalence.\n\n- Several useful rules are provided out of the box, for example, Unicode\n  normalization, capitalization, common puncutation and diacritical marks.\n- Custom rules can be created using plain strings, regexes, or functions.\n- Comparing two strings via an equivalency returns whether the two strings are\n  equivalent according to that equivalency's ruleset, and can optionally\n  return\n  - the edit distance between the two fully transformed strings using the\n  [damerau-levenshtein](https://www.npmjs.com/package/damerau-levenshtein)\n  algorithm\n  - reasons why the strings differ\n- Equivalency instances can be cloned, making it easy to start with a root\n  equivalency that takes care of universal concerns like Unicode\n  normalization, then derive more specific equivalencies that are tailored to\n  specific cases, like case- or punctuation-sensitivity.\n\nEquivalency works in both Node and browsers back as far as IE 11 ([full list\nof supported browsers](./.browserslistrc)).\n\n## Usage\n\n```js\nconst checker = require('equivalency');\nconst { Equivalency } = checker;\n\n// Default rule is byte-equality.\nchecker.compare('a', 'a');\n// { isEquivalent: true }\n\nchecker.compare('a', 'A');\n// { isEquivalent: false }\n\n// Specify which differences matter/don't matter.\nchecker.doesntMatter(Equivalency.CAPITALIZATION);\nchecker.compare('a', 'A');\n// { isEquivalent: true }\n\nchecker.compare('Hot-dog', 'hotdog');\n// { isEquivalent: false }\n\nchecker.doesntMatter(Equivalency.en.COMMON_PUNCTUATION);\nchecker.compare('Hot-dog', 'hotdog');\n// { isEquivalent: true }\n\nchecker.compare('Go away, fly!', 'Go away; fly!');\n// { isEquivalent: true }\n\nchecker.matters(',;');\nchecker.compare('Go away, fly!', 'Go away; fly!');\n// { isEquivalent: false }\n\nchecker.compare('Go away, fly!', 'Go away; fly!',{giveReasons: true});\n// { isEquivalent: false, reasons: [{name: ',;'}] }\n\n// Return edit distance\nconst options = { calculateEditDistance: true };\nchecker.compare('show', 'shoe', options);\n// { isEquivalent: false, editDistance: 1 }\n\nconst esChecker = new Equivalency();\nesChecker.compare('adiós', 'adios');\n// { isEquivalent: false }\n\nconst enChecker = new Equivalency();\nenChecker.doesntMatter(Equivalency.ACCENTS);\nenChecker.compare('adiós', 'adios');\n// { isEquivalent: true }\n\n// Root equivalency: normalizes Unicode, whitespace differences, and case.\nconst root = new Equivalency()\n  .doesntMatter(Equivalency.UNICODE_NORMALIZATION)\n  .doesntMatter(Equivalency.WHITESPACE_DIFFERENCES)\n  .doesntMatter(Equivalency.CAPITALIZATION)\n\n// Diacritic-blind equivalency cloned from root equivalency.\nconst equivalencyForDiacriticWarning = root\n  .clone()\n  .doesntMatter(Equivalency.COMMON_DIACRITICS);\n\nconst isMatch = root.compare(\n  providedAnswer,\n  expectedAnswer\n).isEquivalent;\n\nconst isMatchExceptForDiacritics = equivalencyForDiacriticWarning.compare(\n  providedAnswer,\n  expectedAnswer\n).isEquivalent;\n```\n\nEquivalency Rules are not applied strictly in the order they are supplied. All map rules are applied, and only then\nare function rules applied. Therefore, FunctionRules can apply transformations on top of MapRule transformations, but\nMapRules cannot apply transformations on top of FunctionRules. These two rule types are also applied in fundamentally\ndifferent ways. MapRules are collapsed into a single map which is then used to transform the comparison strings in a\nsingle operation. When two MapRules have conflicting mappings, the mappings in the rule further down the rule chain\ntakes precedence. FunctionRules cascade such that transformation operations are performed individually one after another\nin the order given.\n\n## Tests\n\n[![BrowserStack\nStatus](https://www.browserstack.com/automate/badge.svg?badge_key=b1pkZFN2ejJFVzFDZHhNeHUydk9HSlRxUUk1M1ZGRzZidDZKUU9NTksxdz0tLUI2MFRlazFhUW8rQU82MmxTMDdvNUE9PQ==--c1cd245939097acf9f1b9399a2db0661b6738e7d)](https://www.browserstack.com/automate/public-build/b1pkZFN2ejJFVzFDZHhNeHUydk9HSlRxUUk1M1ZGRzZidDZKUU9NTksxdz0tLUI2MFRlazFhUW8rQU82MmxTMDdvNUE9PQ==--c1cd245939097acf9f1b9399a2db0661b6738e7d)\n\n### Running tests\n\n- local: `yarn test`\n- Browserstack (for browser compatability, particular IE 11): `BROWSER_STACK_ACCESS_KEY=\u003ckey\u003e yarn run test:karma`\n\n## Release steps\n\nSee [the release doc](./docs/release.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandinmyjoints%2Fequivalency","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandinmyjoints%2Fequivalency","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandinmyjoints%2Fequivalency/lists"}