{"id":13508970,"url":"https://github.com/livoras/list-diff","last_synced_at":"2025-04-06T15:13:04.633Z","repository":{"id":57105320,"uuid":"46201212","full_name":"livoras/list-diff","owner":"livoras","description":"Diff two lists in O(n).","archived":false,"fork":false,"pushed_at":"2019-06-01T08:52:32.000Z","size":25,"stargazers_count":183,"open_issues_count":4,"forks_count":70,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-30T13:09:40.537Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/livoras.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":"2015-11-15T02:35:08.000Z","updated_at":"2025-03-02T21:28:24.000Z","dependencies_parsed_at":"2022-08-21T03:00:38.432Z","dependency_job_id":null,"html_url":"https://github.com/livoras/list-diff","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/livoras%2Flist-diff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livoras%2Flist-diff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livoras%2Flist-diff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livoras%2Flist-diff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/livoras","download_url":"https://codeload.github.com/livoras/list-diff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247500469,"owners_count":20948880,"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-08-01T02:01:01.167Z","updated_at":"2025-04-06T15:13:04.607Z","avatar_url":"https://github.com/livoras.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"list-diff \n=================\n\n[![build](https://circleci.com/gh/livoras/list-diff/tree/master.png?style=shield)](https://circleci.com/gh/livoras/list-diff) [![codecov.io](https://codecov.io/github/livoras/list-diff/coverage.svg?branch=master)](https://codecov.io/github/livoras/list-diff?branch=master) [![npm version](https://badge.fury.io/js/list-diff2.svg)](https://badge.fury.io/js/list-diff2) [![Dependency Status](https://david-dm.org/livoras/list-diff.svg)](https://david-dm.org/livoras/list-diff) \n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\n## Introduction\n\nDiff two lists in time O(n). \nI\nThe algorithm finding the minimal amount of moves is [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) which is O(n*m). This algorithm is not the best but is enougth for front-end DOM list manipulation. \n\nThis project is mostly influenced by [virtual-dom](https://github.com/Matt-Esch/virtual-dom/blob/master/vtree/diff.js) algorithm.\n\n## Install\n\n    $ npm install list-diff2 --save\n\n## Usage\n\n```javascript\nvar diff = require(\"list-diff2\")\nvar oldList = [{id: \"a\"}, {id: \"b\"}, {id: \"c\"}, {id: \"d\"}, {id: \"e\"}]\nvar newList = [{id: \"c\"}, {id: \"a\"}, {id: \"b\"}, {id: \"e\"}, {id: \"f\"}]\n\nvar moves = diff(oldList, newList, \"id\")\n// `moves` is a sequence of actions (remove or insert): \n// type 0 is removing, type 1 is inserting\n// moves: [\n//   {index: 3, type: 0},\n//   {index: 0, type: 1, item: {id: \"c\"}}, \n//   {index: 3, type: 0}, \n//   {index: 4, type: 1, item: {id: \"f\"}}\n//  ]\n\nmoves.moves.forEach(function(move) {\n  if (move.type === 0) {\n    oldList.splice(move.index, 1) // type 0 is removing\n  } else {\n    oldList.splice(move.index, 0, move.item) // type 1 is inserting\n  }\n})\n\n// now `oldList` is equal to `newList`\n// [{id: \"c\"}, {id: \"a\"}, {id: \"b\"}, {id: \"e\"}, {id: \"f\"}]\nconsole.log(oldList) \n```\n\n## License \n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Livoras\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivoras%2Flist-diff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flivoras%2Flist-diff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivoras%2Flist-diff/lists"}