
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
object-looks-like
Advanced tools
An utility function for comparing if object A looks like object B.
objectLooksLike
is not shallow comparing nor deep comparing object A and object B. Rather, it iterates properties of object B and checks if they are matching object A properties.
const objectLooksLike = require('./index');
const objectA = {
name: 'Mike',
age: 21,
height: '180cm',
weight: '60kg',
hobbies: ['basketball', 'football', 'swimming'],
parent: {
name: 'Daniel',
age: 55,
height: '175cm',
weight: '50kg',
hobbies: ['reading'],
parent: null,
},
};
const objectB = {
name: 'Mike',
age: 21,
hobbies: ['basketball', 'football', 'swimming'],
parent: {
name: 'Daniel',
age: 55,
},
};
// Returns true because objectB is a subset of objectA.
objectLooksLike(objectA, objectB);
const objectC = {
name: 'Mike',
age: age => age < 50, // value can be a function
parent: {
name: 'Daniel',
age: 55,
},
};
// Returns true because objectC is a subset of objectA.
objectLooksLike(objectA, objectC);
const objectD = {
name: 'Mike',
age: 21,
parent: {
name: 'Sam', // unmatching property value
age: 55,
},
};
// Returns false because objectD has unmatching property value.
objectLooksLike(objectA, objectD);
const objectE = {
name: 'Mike',
age: 21,
skin: 'white', // unknown property
parent: {
name: 'Daniel',
age: 55,
},
};
// Returns false because objectE has unknown property.
objectLooksLike(objectA, objectE);
FAQs
An utility function for comparing if object A looks like object B.
We found that object-looks-like demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.