Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

partof

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

partof - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

23

lib/partOf.js
'use strict';
var partOf = function () {};
var partOf = function (subset, superset) {
if (typeof subset !== 'object') {
return false;
}
if (typeof superset !== 'object') {
return false;
}
if (!!subset && !superset) {
return false;
}
return Object.keys(subset).every(function (key) {
var subsetValue = subset[key],
supersetValue = superset[key];
if (typeof supersetValue === 'object' && supersetValue !== null && subsetValue !== null) {
return partOf(subsetValue, supersetValue);
}
return subsetValue === supersetValue;
});
};
module.exports = partOf;

2

package.json
{
"name": "partof",
"version": "0.0.0",
"version": "0.1.0",
"description": "partof verifies whether one object is part of an other.",

@@ -5,0 +5,0 @@ "contributors": [

@@ -12,2 +12,54 @@ 'use strict';

});
suite('returns true', function () {
test('if subset is part of superset.', function (done) {
var subset = { foo: 'a' },
superset = { foo: 'a', bar: 'b' };
assert.that(partOf(subset, superset)).is.true();
done();
});
test('if subset is part of superset, even for nested objects.', function (done) {
var subset = { bas: { baz: 'c' }},
superset = { foo: 'a', bar: 'b', bas: { baz: 'c' }};
assert.that(partOf(subset, superset)).is.true();
done();
});
test('if subset is part of superset, even for partially nested objects', function (done) {
var subset = { bas: { baz: 'c' }},
superset = { foo: 'a', bar: 'b', bas: { baz: 'c', bax: 'd' }};
assert.that(partOf(subset, superset)).is.true();
done();
});
});
suite('returns false', function () {
test('if subset is not part of superset.', function (done) {
var subset = { foo: 'b' },
superset = { foo: 'a', bar: 'b' };
assert.that(partOf(subset, superset)).is.false();
done();
});
test('if subset is not part of superset, even for nested objects.', function (done) {
var subset = { bax: { baz: 'c' }},
superset = { foo: 'a', bar: 'b', bas: { baz: 'c' }};
assert.that(partOf(subset, superset)).is.false();
done();
});
test('if subset is not part of superset, even for partially nested objects', function (done) {
var subset = { bax: { baz: 'c' }},
superset = { foo: 'a', bar: 'b', bas: { baz: 'c', bax: 'd' }};
assert.that(partOf(subset, superset)).is.false();
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc