{"id":27947817,"url":"https://github.com/deeplay-io/diff-maps","last_synced_at":"2025-05-07T14:37:25.029Z","repository":{"id":111199500,"uuid":"389269392","full_name":"deeplay-io/diff-maps","owner":"deeplay-io","description":"Calculate diff between two Maps","archived":false,"fork":false,"pushed_at":"2021-07-28T10:41:48.000Z","size":54,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T15:18:52.076Z","etag":null,"topics":["changes","diff","map"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/deeplay-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-07-25T05:27:08.000Z","updated_at":"2024-02-08T09:12:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"2c73930f-9995-4ad0-bc9d-a126825184f2","html_url":"https://github.com/deeplay-io/diff-maps","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"dd9b998d24173eed6034289d78fe1dc0cb0a72cb"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeplay-io%2Fdiff-maps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeplay-io%2Fdiff-maps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeplay-io%2Fdiff-maps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeplay-io%2Fdiff-maps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deeplay-io","download_url":"https://codeload.github.com/deeplay-io/diff-maps/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252896777,"owners_count":21821335,"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":["changes","diff","map"],"created_at":"2025-05-07T14:37:24.374Z","updated_at":"2025-05-07T14:37:25.012Z","avatar_url":"https://github.com/deeplay-io.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# diff-maps [![npm version][npm-image]][npm-url] \u003c!-- omit in toc --\u003e\n\nCalculate diff between two `Map`s\n\n- [Installation](#installation)\n- [Usage](#usage)\n\n## Installation\n\n```\nnpm install diff-maps\n```\n\n## Usage\n\nCalculate diff:\n\n```ts\nimport {diffMaps} from 'diff-maps';\n\nexpect(\n  diffMaps(\n    new Map([\n      ['1', 0],\n      ['2', 0],\n    ]),\n    new Map([\n      ['2', 1],\n      ['3', 1],\n    ]),\n  ),\n).toEqual([\n  {type: 'remove', key: '1', prevValue: 0},\n  {type: 'change', key: '2', value: 1, prevValue: 0},\n  {type: 'add', key: '3', value: 1},\n]);\n```\n\nUse custom equality function (default is\n[`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)):\n\n```ts\nimport {diffMaps} from 'diff-maps';\nimport {isEqual} from 'lodash';\n\nexpect(\n  diffMaps(\n    new Map([\n      ['1', {data: 0}],\n      ['2', {data: 0}],\n    ]),\n    new Map([\n      ['1', {data: 0}],\n      ['2', {data: 1}],\n    ]),\n    isEqual,\n  ),\n).toEqual([\n  {\n    type: 'change',\n    key: '2',\n    value: {data: 1},\n    prevValue: {data: 0},\n  },\n]);\n```\n\nApply diff:\n\n```ts\nimport {applyDiff} from 'diff-maps';\n\nconst state = new Map([\n  ['1', 0],\n  ['2', 0],\n]);\n\n// mutates the map\napplyDiff(state, [\n  {type: 'remove', key: '1', prevValue: 0},\n  {type: 'change', key: '2', value: 1, prevValue: 0},\n  {type: 'add', key: '3', value: 1},\n]);\n\nexpect(state).toEqual(\n  new Map([\n    ['2', 1],\n    ['3', 1],\n  ]),\n);\n```\n\nUse with [Immutable.js](https://github.com/immutable-js/immutable-js):\n\n```ts\nimport {Map} from 'immutable';\n\n// calculate diff\n\nexpect(\n  diffMaps(\n    Map({\n      1: 0,\n      2: 0,\n    }),\n    Map({\n      2: 1,\n      3: 1,\n    }),\n  ),\n).toEqual([\n  {type: 'remove', key: '1', prevValue: 0},\n  {type: 'change', key: '2', value: 1, prevValue: 0},\n  {type: 'add', key: '3', value: 1},\n]);\n\n// apply diff\n\nconst state = Map({\n  1: 0,\n  2: 0,\n});\n\nconst nextState = state.withMutations(mutableState =\u003e {\n  applyDiff(mutableState, [\n    {type: 'remove', key: '1', prevValue: 0},\n    {type: 'change', key: '2', value: 1, prevValue: 0},\n    {type: 'add', key: '3', value: 1},\n  ]);\n});\n\nexpect(new Map(nextState)).toEqual(\n  new Map([\n    ['2', 1],\n    ['3', 1],\n  ]),\n);\n```\n\n[npm-image]: https://badge.fury.io/js/diff-maps.svg\n[npm-url]: https://badge.fury.io/js/diff-maps\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeeplay-io%2Fdiff-maps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeeplay-io%2Fdiff-maps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeeplay-io%2Fdiff-maps/lists"}