Comparing version 0.0.0 to 0.1.0
'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; |
{ | ||
"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(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5638
85