{"id":19257555,"url":"https://github.com/ericvera/sort-updates","last_synced_at":"2025-07-31T00:04:42.464Z","repository":{"id":57366279,"uuid":"105511383","full_name":"ericvera/sort-updates","owner":"ericvera","description":"A JavaScript utility library to determine updates needed to re-order an item in a sorted list.","archived":false,"fork":false,"pushed_at":"2017-10-05T16:16:21.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T17:48:08.430Z","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/ericvera.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-02T08:08:12.000Z","updated_at":"2018-08-15T04:56:24.000Z","dependencies_parsed_at":"2022-08-23T20:10:40.340Z","dependency_job_id":null,"html_url":"https://github.com/ericvera/sort-updates","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ericvera/sort-updates","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fsort-updates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fsort-updates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fsort-updates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fsort-updates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericvera","download_url":"https://codeload.github.com/ericvera/sort-updates/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fsort-updates/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267962117,"owners_count":24172574,"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-07-30T02:00:09.044Z","response_time":70,"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-09T19:10:38.829Z","updated_at":"2025-07-31T00:04:42.434Z","avatar_url":"https://github.com/ericvera.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sort-updates\nA JavaScript utility library to determine updates needed to re-order an item in a sorted list.\n\n\u003cp\u003e\n  \u003ca href=\"https://npmjs.org/package/sort-updates\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/sort-updates.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n# Usage\n\nInstall the module:\n\n```sh\nnpm install sort-updates --save\n```\n\n```js\nsortUpdates(insertAtIndex, itemToInsert, list);\n```\nReturns an array with objects that need to be updated in order to insert an item at the specified location. \n\nWhenever there is space (sortValues have a maximum of 25 decimal places) between the before and after, there will be a single update and the sort value for the item to insert will be approximaltely between the two items.\n\nWhenever there is no space items will be shifted until there is space.\n\n## Sample when there is space\n```js\nimport sortUpdates from 'sort-updates';\n\nconst list = [\n  { key: 'aba348f', sortValue: 0 },\n  { key: '5ba348f', sortValue: 5 }\n]\nconst itemToInsert = { key: '8ba3e8f', sortValue: undefined }\nconst insertAtIndex = 1\n\nconst expectedUpdtes = \n\nlet updates = sortUpdates(insertAtIndex, itemToInsert, list)\n\nconsole.log(updates);\n// Output: [{ key: '8ba3e8f', sortValue: 3 }]\n```\n\n## Sample when there is no space\n```js\nimport sortUpdates from 'sort-updates';\n\nconst list = [\n  { key: 'aba348f', sortValue: 0 },\n  { key: '5ba348f', sortValue: 0.0000000000000000000000001 },\n  { key: '6ba348f', sortValue: 0.0000000000000000000000002 },\n  { key: '9ba348f', sortValue: 0.0000000000000000000000003 }\n]\nconst itemToInsert = { key: '8ba3e8f', sortValue: undefined }\nconst insertAtIndex = 3\n\nlet updates = sortUpdates(insertAtIndex, itemToInsert, list)\n\nconsole.log(updates);\n// Output: [\n//  { key: '8ba3e8f', sortValue: 0.0000000000000000000000002 },\n//  { key: '6ba348f', sortValue: 0.0000000000000000000000001 },\n//  { key: '5ba348f', sortValue: 0 },\n//  { key: 'aba348f', sortValue: -1 }\n//]\n```\n\n# License\n[MIT](https://github.com/ericvera/sort-updates/blob/master/LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericvera%2Fsort-updates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericvera%2Fsort-updates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericvera%2Fsort-updates/lists"}