{"id":22021601,"url":"https://github.com/lamansky/unique-map-by","last_synced_at":"2025-03-23T10:19:31.634Z","repository":{"id":57386316,"uuid":"114898012","full_name":"lamansky/unique-map-by","owner":"lamansky","description":"[Node.js] Filters a Map or Object by testing entry uniqueness with a callback.","archived":false,"fork":false,"pushed_at":"2017-12-20T15:23:54.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T15:44:51.060Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/lamansky.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}},"created_at":"2017-12-20T14:44:12.000Z","updated_at":"2017-12-20T15:23:55.000Z","dependencies_parsed_at":"2022-09-02T00:42:23.182Z","dependency_job_id":null,"html_url":"https://github.com/lamansky/unique-map-by","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Funique-map-by","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Funique-map-by/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Funique-map-by/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Funique-map-by/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/unique-map-by/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245085101,"owners_count":20558334,"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-11-30T06:13:12.123Z","updated_at":"2025-03-23T10:19:31.609Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unique-map-by\n\nFilters a Map or Object by testing entry uniqueness with a callback.\n\n(If you merely want a Map/Object with no duplicate values, use the [`unique-map`](https://github.com/lamansky/unique-map-by) module instead.)\n\nOptionally lets you set a numeric limit on total entries in the returned Map/Object.\n\n## Installation\n\n```bash\nnpm install unique-map-by --save\n```\n\nThe module exports a single function.\n\n## Usage Example\n\nLet’s say you have a Map with person objects and you only want one person with any given name.\n\n```javascript\nconst uniqueMapBy = require('unique-map-by')\n\nconst map = new Map([\n  [1, {name: 'John'}],\n  [2, {name: 'John'}],\n  [3, {name: 'Stephen'}],\n])\n\nconst u = uniqueMapBy(map, (key, value) =\u003e value.name)\nu.size // 2\nu.get(1) // {name: 'John'}\nu.get(2) // undefined\nu.get(3) // {name: 'Stephen'}\n```\n\nAlthough the above example uses the `name` property of the value as the basis for testing uniqueness, you could just as well test a property of the key.\n\nYou can use the `limit` argument to cap the number of total entries returned:\n\n```javascript\nconst u = uniqueMapBy(map, (key, value) =\u003e value.name, {limit: 1})\nu.size // 1\nu.get(1) // {name: 'John'}\nu.get(2) // undefined\nu.get(3) // undefined\n```\n\nThe module also works just as well with Objects:\n\n```javascript\nconst uniqueMapBy = require('unique-map-by')\n\nconst obj = {\n  1: {name: 'John'},\n  2: {name: 'John'},\n  3: {name: 'Stephen'},\n}\n\nconst u = uniqueMapBy(obj, (key, value) =\u003e value.name)\nu[1] // {name: 'John'}\nu[2] // undefined\nu[3] // {name: 'Stephen'}\n```\n\n## Related Projects\n\n* [deduplicate](https://github.com/lamansky/deduplicate)\n* [unique-array-by](https://github.com/lamansky/unique-array-by)\n* [unique-iterable](https://github.com/lamansky/unique-iterable)\n* [unique-iterable-by](https://github.com/lamansky/unique-iterable-by)\n* [unique-map](https://github.com/lamansky/unique-map)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Funique-map-by","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Funique-map-by","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Funique-map-by/lists"}