{"id":18686779,"url":"https://github.com/leon/similar-object","last_synced_at":"2025-08-23T10:33:18.621Z","repository":{"id":142075602,"uuid":"452566784","full_name":"leon/similar-object","owner":"leon","description":"Compare objects by similar fields","archived":false,"fork":false,"pushed_at":"2022-01-27T21:35:34.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-27T09:32:14.911Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leon.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,"publiccode":null,"codemeta":null}},"created_at":"2022-01-27T06:32:36.000Z","updated_at":"2022-01-27T21:34:22.000Z","dependencies_parsed_at":"2023-07-09T05:31:22.946Z","dependency_job_id":null,"html_url":"https://github.com/leon/similar-object","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/leon/similar-object","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leon%2Fsimilar-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leon%2Fsimilar-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leon%2Fsimilar-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leon%2Fsimilar-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leon","download_url":"https://codeload.github.com/leon/similar-object/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leon%2Fsimilar-object/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271746655,"owners_count":24813575,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-07T10:29:03.842Z","updated_at":"2025-08-23T10:33:18.604Z","avatar_url":"https://github.com/leon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Similar Object\n\nA utility to compare objects with numeric fields and get back a score of how close they are.\n\nCan then be used together with `.sort()` to get the most similar objects.\n\nUseful for getting related objects that don't match fully.\n\n# Install\n\n```sh\nnpm install similar-object\n# or\nyarn add similar-object\n```\n\n```ts\nimport { similarObject } from 'similar-object'\n\n// we are looking at this\nconst current = { price: 800, rooms: 3, area: 80 }\n\n// which one of these is closest to current?\nconst unit1 = { price: 1000, rooms: 3, area: 100 }\nconst unit2 = { price: 1000, rooms: 5, area: 50 }\nconst unit3 = { price: 1500, rooms: 5, area: 50 }\nconst units = [unit1, unit2, unit3]\n\nconst similarConfig = {\n  price: 1, // weight 1\n  rooms: 2, // it's more important so we boost the score of rooms by 2\n  area: 3, // area is most important, so we boost it by 3\n}\n\nunits.sort(\n  (a, b) =\u003e similarObject(current, a, similarConfig) - similarObject(current, b, similarConfig),\n)\n\n// units are now sorted according to how similar they are\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleon%2Fsimilar-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleon%2Fsimilar-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleon%2Fsimilar-object/lists"}