{"id":17448309,"url":"https://github.com/mesqueeb/compare-anything","last_synced_at":"2025-08-10T19:19:26.987Z","repository":{"id":33975969,"uuid":"164896281","full_name":"mesqueeb/compare-anything","owner":"mesqueeb","description":"Compares objects and tells you which props are duplicate, and props are only present once.","archived":false,"fork":false,"pushed_at":"2025-02-19T18:48:09.000Z","size":682,"stargazers_count":10,"open_issues_count":8,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T05:40:06.511Z","etag":null,"topics":["compare","compare-arrays","compare-objects","count-if","countif","duplicates","find-duplicates","javascript","remove-duplicates","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/compare-anything","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/mesqueeb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"mesqueeb","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2019-01-09T16:16:05.000Z","updated_at":"2025-02-19T18:48:13.000Z","dependencies_parsed_at":"2024-06-04T11:48:40.417Z","dependency_job_id":"d1c61d59-f34b-493a-8023-c8491b6944c5","html_url":"https://github.com/mesqueeb/compare-anything","commit_stats":{"total_commits":61,"total_committers":4,"mean_commits":15.25,"dds":0.3770491803278688,"last_synced_commit":"e0e315c2821e2ec879fac70e28bab4003da0fbee"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcompare-anything","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcompare-anything/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcompare-anything/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcompare-anything/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mesqueeb","download_url":"https://codeload.github.com/mesqueeb/compare-anything/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248764199,"owners_count":21158040,"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":["compare","compare-arrays","compare-objects","count-if","countif","duplicates","find-duplicates","javascript","remove-duplicates","typescript"],"created_at":"2024-10-17T20:06:57.666Z","updated_at":"2025-04-13T18:40:34.684Z","avatar_url":"https://github.com/mesqueeb.png","language":"TypeScript","funding_links":["https://github.com/sponsors/mesqueeb"],"categories":[],"sub_categories":[],"readme":"# Compare anything 🛰\n\n\u003ca href=\"https://www.npmjs.com/package/compare-anything\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/compare-anything.svg\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/compare-anything\"\u003e\u003cimg src=\"https://img.shields.io/npm/dw/compare-anything.svg\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\n```\nnpm i compare-anything\n```\n\nCompares objects and arrays and tells you which props or values are duplicates, and which are only present once.\n\nIt works just like you would compare two columns in excel! But who needs excel when you've got JavaScript, am I right? 😃\n## Meet the family (more tiny utils with TS support)\n\n- [is-what 🙉](https://github.com/mesqueeb/is-what)\n- [is-where 🙈](https://github.com/mesqueeb/is-where)\n- [merge-anything 🥡](https://github.com/mesqueeb/merge-anything)\n- [check-anything 👁](https://github.com/mesqueeb/check-anything)\n- [remove-anything ✂️](https://github.com/mesqueeb/remove-anything)\n- [getorset-anything 🐊](https://github.com/mesqueeb/getorset-anything)\n- [map-anything 🗺](https://github.com/mesqueeb/map-anything)\n- [filter-anything ⚔️](https://github.com/mesqueeb/filter-anything)\n- [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)\n- [case-anything 🐫](https://github.com/mesqueeb/case-anything)\n- [flatten-anything 🏏](https://github.com/mesqueeb/flatten-anything)\n- [nestify-anything 🧅](https://github.com/mesqueeb/nestify-anything)\n\n## Usage\n\nIt works just like you would expect. You `compare(objectA, objectB)` and it gives you all kind of info.\n\nYou can do all kind of things with compare-anything!\n\n- Compare object props, to see which props are present in which objects\n  \u003c!-- 2. (WIP) Compare object values, to see which prop values are equal in all objects and which not --\u003e\n  \u003c!-- 3. (WIP) Compare arrays, to see which values are present in all arrays and which not --\u003e\n\n## Compare object props\n\nWhich props are present in which objects. Remember, **this function only looks at the prop-names!** Not the values.\n\nWill return an info object with:\n\n- `props` - an array with all props of all objects\n- `presentInAll` - is the prop present in all passed objects? `true`/`false` per prop\n- `perProp` - an array of objects per prop that had that specific prop\n- `presentIn` - an array of indexes per prop that had that specific prop (indexes of the params you passed to the function)\n\n```js\nimport { compareObjectProps } from 'compare-anything'\n\n// only props 'b' and 'c' are present in both ↓\nconst objectA = {a: '🎴', b: '🎴', c: '🎴'}\nconst objectB = {b: '🀄️', c: '🀄️', d: '🀄️'}\n\ncompareObjectProps(objectA, objectB)\n// returns ↓\n{\n  props: ['a', 'b', 'c', 'd'],\n  presentInAll: { a: false, b: true, c: true, d: false },\n  perProp: { a: [objectA], b: [objectA, objectB], c: [objectA, objectB], d: [objectB] },\n  presentIn: { a: [0], b: [0, 1], c: [0, 1], d: [1] }\n}\n```\n\n### Compare more than two\n\nYou can pass **as many arguments as you want**!\n\n```js\n// keep on adding objects to compare!\ncompareObjectProps(objectA, objectB, objectC, objectD, objectE)\n```\n\n### Compare objects in an array\n\nWhen you need to compare objects in an array you can use destructuring:\n\n```js\n// you can compare an array of objects like so:\ncompareObjectProps(...objectArray)\n```\n\n### Find duplicates based on one prop value\n\nWhen you need to find duplicate objects based on one single prop value of that object, you can easily do so as follows:\n\n```js\ncompareObjectProps(\n  ...arrayOfObjects.map(obj =\u003e {\n    return { [obj.idField]: obj }\n  })\n)\n```\n\nIn the example above you can change `idField` by the actual prop name you need. By making a key out of the value you can easily find duplicates based on just this field.\n\n### Nested props\n\nIf we require to check even **nested props** we can use the [flatten-anything](https://github.com/mesqueeb/flatten-anything) function like shown below:\n\n```js\nimport flatten from 'flatten-anything'\nimport { compareObjectProps } from 'compare-anything'\n\nconst objectA = {nested: {a: '🎴', b: '🎴'}}\nconst objectB = {nested: {a: '🀄️', c: '🀄️'}}\n\nconst flatA = flatten(objectA)\n// →　{'nested.a': '🎴', 'nested.b': '🎴'}\nconst flatB = flatten(objectB)\n// →　{'nested.a': '🀄️', 'nested.c': '🀄️'}\n\ncompareObjectProps(flatA, flatB)\n// returns ↓\n{\n  props: ['nested.a', 'nested.b', 'nested.c'],\n  presentInAll: { 'nested.a': true, 'nested.b': false, 'nested.c': false },\n  perProp: { 'nested.a': [objectA, objectB], 'nested.b': [objectA], 'nested.c': [objectB] },\n  presentIn: { 'nested.a': [0, 1], 'nested.b': [0], 'nested.c': [1] }\n}\n```\n\n\u003c!-- ## Compare object values\n\nWhich values are the same in which objects. Will return an info object with:\n\n- `props` - an array with all props of all objects\n- `sameInAll` - true/false per prop\n- `sameIn` - sets of indexes of the objects where the value was equal\n\n```js\nimport { compareObjectValues } from 'compare-anything'\n\nconst objectA = {a: '', b: 'same', c: 'diff', d: ''}\nconst objectB = {b: 'same', c: 'Diff', e: '', f: ''}\nconst objectC = {b: 'same', c: 'Diff'}\nconst objectE = {b: 'same', c: 'diff'}\n\ncompareObjectValues(objectA, objectB)\n// returns ↓\n{\n  props: ['a', 'b', 'c', 'd', 'e', 'f'],\n  sameInAll: { a: false, b: true, c: false, d: false, e: false, f: false },\n  sameIn: { a: [], b: [[0, 1, 2, 3]], c: [[0, 3], [1, 2]], d: [], e: [], f: [] },\n}\n``` --\u003e\n\n\u003c!--\n## Compare arrays\n\nWhich values are present in which arrays. Will return an info object with:\n\n- `values` - an array with all values of all arrays\n- `presentInAll` - true/false per value\n- `presentIn` - the param indexes of where the prop was present\n\n```js\nimport { compareArrays } from 'compare-anything'\n\nconst arrayA = [1, 2, 'a']\nconst arrayB = [1, 'a', 'b']\n\ncompareArrays(arrayA, arrayB)\n// returns ↓\n{\n  values: [1, 2, 'a', 'b'],\n  presentInAll: new Map([\n    [1, true], [2, false], ['a', true], ['b', false]\n  ]),\n  presentIn: new Map([\n    [1, [0, 1]], [2, [0]], ['a', [0, 1]], ['b', [1]]\n  ]),\n}\n```\n--\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesqueeb%2Fcompare-anything","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmesqueeb%2Fcompare-anything","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesqueeb%2Fcompare-anything/lists"}