{"id":18513142,"url":"https://github.com/yeojz/flat-diff","last_synced_at":"2026-05-14T21:34:43.299Z","repository":{"id":57237976,"uuid":"94903182","full_name":"yeojz/flat-diff","owner":"yeojz","description":" diff algorithm based on the unique key path of each value in an Object / JSON","archived":false,"fork":false,"pushed_at":"2017-06-25T15:45:23.000Z","size":39,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-19T16:28:10.697Z","etag":null,"topics":["diff","json","keypath","object"],"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/yeojz.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-06-20T14:56:23.000Z","updated_at":"2021-03-24T14:16:41.000Z","dependencies_parsed_at":"2022-08-26T15:01:35.047Z","dependency_job_id":null,"html_url":"https://github.com/yeojz/flat-diff","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/yeojz/flat-diff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeojz%2Fflat-diff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeojz%2Fflat-diff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeojz%2Fflat-diff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeojz%2Fflat-diff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yeojz","download_url":"https://codeload.github.com/yeojz/flat-diff/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeojz%2Fflat-diff/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33044185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"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":["diff","json","keypath","object"],"created_at":"2024-11-06T15:36:38.650Z","updated_at":"2026-05-14T21:34:43.277Z","avatar_url":"https://github.com/yeojz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flat-diff\n\n\u003e A naive diff algorithm based on the unique key path of each value in an Object / JSON\n\n[![npm package][npm-badge]][npm-link]\n[![Build Status][build-badge]][build-link]\n[![Coverage Status][codecov-badge]][codecov-link]\n\n## Installation\n\n```\n$ npm install flat-diff --save\n```\n\n## Example\n\nGiven:\n\n```js\n  import diff from 'flat-diff';\n\n  const base = {\n    a: [1, 2, { b: 1 }, 4, 5, 6],\n    b: 'test',\n    c: 'prev'\n  };\n\n  const target = {\n    a: [1, 2, { b: 2 }, 4, 6],\n    b: 'test 2',\n    d: 'new'\n  };\n\n  const metadata = diff(base, target);\n```\n\nwill give a result of:\n\n```js\n  const metadata = [\n    { path: 'a.0', type: 'same', value: 1 },\n    { path: 'a.1', type: 'same', value: 2 },\n    { path: 'a.2.b', type: 'put', prev: 1, value: 2 },\n    { path: 'a.3', type: 'same', value: 4 },\n    { path: 'a.4', type: 'put', prev: 5, value: 6 },\n    { path: 'a.5', type: 'del', value: 6 },\n    { path: 'b', type: 'put', prev: 'test', value: 'test 2' },\n    { path: 'c', type: 'del', value: 'prev' },\n    { path: 'd', type: 'post', value: 'new' }\n  ];\n\n  // Note: path keys will be sorted.\n```\n\n## Caveats\n\nDue to how keys are generated, if you have an array and object with number keys in the same path,\nthere will be a conflict.\n\ni.e.\n\n```js\n// object\n{\n  a: {\n    '0': 'b',\n    '1': 'c'\n  }\n}\n\n// array\n{\n  a: ['b', 'c']\n}\n\n\n// both formats above will result in similar paths:\n[\n  {path: 'a.0', value: 'b'},\n  {path: 'a.1', value: 'c'}\n]\n```\n\n## License\n\n`flat-diff` is [MIT licensed](./LICENSE)\n\n\n[npm-badge]: https://img.shields.io/npm/v/flat-diff.svg?style=flat-square\n[npm-link]: https://www.npmjs.com/package/flat-diff\n\n[build-badge]: https://img.shields.io/circleci/project/github/yeojz/flat-diff/master.svg?style=flat-square\n[build-link]: https://circleci.com/gh/yeojz/flat-diff.svg\n\n[codecov-badge]: https://img.shields.io/codecov/c/github/yeojz/flat-diff/master.svg?style=flat-square\n[codecov-link]: https://codecov.io/gh/yeojz/flat-diff\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeojz%2Fflat-diff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyeojz%2Fflat-diff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeojz%2Fflat-diff/lists"}