{"id":22021432,"url":"https://github.com/lamansky/sort-map","last_synced_at":"2026-04-05T21:05:54.011Z","repository":{"id":57366293,"uuid":"118483099","full_name":"lamansky/sort-map","owner":"lamansky","description":"[Node.js] Sorts a Map by its keys and/or values.","archived":false,"fork":false,"pushed_at":"2018-01-22T16:27:56.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T17:50:58.609Z","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":"2018-01-22T16:25:39.000Z","updated_at":"2018-01-22T16:27:57.000Z","dependencies_parsed_at":"2022-08-23T19:40:38.131Z","dependency_job_id":null,"html_url":"https://github.com/lamansky/sort-map","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%2Fsort-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fsort-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fsort-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fsort-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/sort-map/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244951876,"owners_count":20537460,"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:12:03.161Z","updated_at":"2025-12-30T22:51:53.614Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sort-map\n\nSorts a Map by its keys and/or values.\n\nUnlike [`Array.prototype.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Sort), `sort-map` does **not** sort the Map in-place. It creates a new, sorted Map and returns it.\n\n## Installation\n\nRequires [Node.js](https://nodejs.org/) 7.0.0 or above.\n\n```bash\nnpm install sort-map --save\n```\n\nThe module exports a single function.\n\n## Usage\n\n### Maps\n\nBy default, `sort-map` sorts a Map by its keys:\n\n```javascript\nconst sortMap = require('sort-map')\n\nconst map = new Map([['b', 2], ['a', 1]])\nconst sortedMap = sortMap(map)\nArray.from(sortedMap.keys()) // ['a', 'b']\n```\n\nYou can provide a callback if your sorting needs are more complex. This example sorts the Map by its values:\n\n```javascript\nconst compare = require('3')\nconst sortMap = require('sort-map')\n\nconst map = new Map([['b', 2], ['a', 1]])\nconst sortedMap = sortMap(map, ([k1, v1], [k2, v2]) =\u003e compare(v1, v2))\nArray.from(sortedMap.values()) // [1, 2]\n```\n\nThe above example makes use of the [`3`](https://github.com/lamansky/3) module in the sort callback.\n\n### Objects\n\n`sort-map` can also sort an Object (but remember that JavaScript technically does not guarantee that Object keys will be enumerated in any particular order).\n\n```javascript\nconst sortMap = require('sort-map')\nsortMap({b: 2, a: 1}) // {a: 1, b: 2}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fsort-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Fsort-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fsort-map/lists"}