{"id":15368242,"url":"https://github.com/keithamus/sort-object-keys","last_synced_at":"2025-04-07T10:19:16.259Z","repository":{"id":57366256,"uuid":"47143028","full_name":"keithamus/sort-object-keys","owner":"keithamus","description":"Sort an object's keys, including an optional key list","archived":false,"fork":false,"pushed_at":"2025-03-02T18:47:35.000Z","size":45,"stargazers_count":31,"open_issues_count":4,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T09:03:09.629Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/keithamus.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}},"created_at":"2015-11-30T20:08:07.000Z","updated_at":"2025-03-02T18:47:39.000Z","dependencies_parsed_at":"2022-08-23T20:10:26.683Z","dependency_job_id":null,"html_url":"https://github.com/keithamus/sort-object-keys","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keithamus%2Fsort-object-keys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keithamus%2Fsort-object-keys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keithamus%2Fsort-object-keys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keithamus%2Fsort-object-keys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keithamus","download_url":"https://codeload.github.com/keithamus/sort-object-keys/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247631834,"owners_count":20970069,"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-10-01T13:28:49.196Z","updated_at":"2025-04-07T10:19:16.238Z","avatar_url":"https://github.com/keithamus.png","language":"JavaScript","readme":"# Sort Object\n\n\n\n[![Build Status](https://travis-ci.org/keithamus/sort-object-keys.svg)](https://travis-ci.org/keithamus/sort-object-keys)\n\nReturns a copy of an object with all keys sorted.\n\nThe second argument is optional and is used for ordering - to provide custom sorts. You can either pass an array containing ordered keys or a function to sort the keys (same signature as in [`Array.prototype.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)).\n\n```js\nconst assert = require('assert');\nconst sortObject = require('sort-object-keys');\n\nassert.equal(JSON.stringify({\n  c: 1,\n  b: 1,\n  d: 1,\n  a: 1,\n}), JSON.stringify({\n  a: 1,\n  b: 1,\n  c: 1,\n  d: 1,\n}));\n\nassert.equal(JSON.stringify(sortObject({\n  c: 1,\n  b: 1,\n  d: 1,\n  a: 1,\n}, ['b', 'a', 'd', 'c'])), JSON.stringify({\n  b: 1,\n  a: 1,\n  d: 1,\n  c: 1,\n}));\n\nfunction removeKeyAncCompareIndex(keyA, keyB){\n  var a = parseInt(keyA.slice(4));\n  var b = parseInt(keyB.slice(4));\n  return a - b;\n}\n\nassert.equal(JSON.stringify(sortObject({\n  \"key-1\": 1,\n  \"key-3\": 1,\n  \"key-10\": 1,\n  \"key-2\": 1,\n}, removeKeyAncCompareIndex)), JSON.stringify({\n  \"key-1\": 1,\n  \"key-2\": 1,\n  \"key-3\": 1,\n  \"key-10\": 1,\n}));\n```\n","funding_links":[],"categories":["Utilities"],"sub_categories":["Data Structures"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeithamus%2Fsort-object-keys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeithamus%2Fsort-object-keys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeithamus%2Fsort-object-keys/lists"}