
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
compare-anything
Advanced tools
Compares objects and arrays and tells you which props or values are duplicates, and which are only present once.
npm i compare-anything
Compares objects and arrays and tells you which props or values are duplicates, and which are only present once.
It works just like you would compare two columns in excel! But who needs excel when you've got JavaScript, am I right? 😃
It works just like you would expect. You compare(objectA, objectB) and it gives you all kind of info.
You can do all kind of things with compare-anything!
Which props are present in which objects. Remember, this function only looks at the prop-names! Not the values.
Will return an info object with:
props - an array with all props of all objectspresentInAll - is the prop present in all passed objects? true/false per propperProp - an array of objects per prop that had that specific proppresentIn - an array of indexes per prop that had that specific prop (indexes of the params you passed to the function)import { compareObjectProps } from 'compare-anything'
// only props 'b' and 'c' are present in both ↓
const objectA = {a: '🎴', b: '🎴', c: '🎴'}
const objectB = {b: '🀄️', c: '🀄️', d: '🀄️'}
compareObjectProps(objectA, objectB)
// returns ↓
{
props: ['a', 'b', 'c', 'd'],
presentInAll: { a: false, b: true, c: true, d: false },
perProp: { a: [objectA], b: [objectA, objectB], c: [objectA, objectB], d: [objectB] },
presentIn: { a: [0], b: [0, 1], c: [0, 1], d: [1] }
}
You can pass as many arguments as you want!
// keep on adding objects to compare!
compareObjectProps(objectA, objectB, objectC, objectD, objectE)
When you need to compare objects in an array you can use destructuring:
// you can compare an array of objects like so:
compareObjectProps(...objectArray)
When you need to find duplicate objects based on one single prop value of that object, you can easily do so as follows:
compareObjectProps(
...arrayOfObjects.map(obj => {
return { [obj.idField]: obj }
})
)
In 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.
If we require to check even nested props we can use the flatten-anything function like shown below:
import flatten from 'flatten-anything'
import { compareObjectProps } from 'compare-anything'
const objectA = {nested: {a: '🎴', b: '🎴'}}
const objectB = {nested: {a: '🀄️', c: '🀄️'}}
const flatA = flatten(objectA)
// → {'nested.a': '🎴', 'nested.b': '🎴'}
const flatB = flatten(objectB)
// → {'nested.a': '🀄️', 'nested.c': '🀄️'}
compareObjectProps(flatA, flatB)
// returns ↓
{
props: ['nested.a', 'nested.b', 'nested.c'],
presentInAll: { 'nested.a': true, 'nested.b': false, 'nested.c': false },
perProp: { 'nested.a': [objectA, objectB], 'nested.b': [objectA], 'nested.c': [objectB] },
presentIn: { 'nested.a': [0, 1], 'nested.b': [0], 'nested.c': [1] }
}
FAQs
Compares objects and arrays and tells you which props or values are duplicates, and which are only present once.
The npm package compare-anything receives a total of 615 weekly downloads. As such, compare-anything popularity was classified as not popular.
We found that compare-anything demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.