Comparing version 2.13.0 to 2.13.1
@@ -46,3 +46,5 @@ // Load modules | ||
var proto = Object.getPrototypeOf(obj); | ||
if (!proto || proto.isImmutable) { | ||
if (proto && | ||
proto.isImmutable) { | ||
newObj = obj; | ||
@@ -284,3 +286,3 @@ } | ||
if (obj.length !== ref.length) { | ||
if (!options.part && obj.length !== ref.length) { | ||
return false; | ||
@@ -290,3 +292,15 @@ } | ||
for (var i = 0, il = obj.length; i < il; ++i) { | ||
if (!exports.deepEqual(obj[i], ref[i])) { | ||
if (options.part) { | ||
var found = false; | ||
for (var r = 0, rl = ref.length; r < rl; ++r) { | ||
if (exports.deepEqual(obj[i], ref[r], options, seen)) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
return found; | ||
} | ||
if (!exports.deepEqual(obj[i], ref[i], options, seen)) { | ||
return false; | ||
@@ -333,3 +347,3 @@ } | ||
if (keys.length !== Object.getOwnPropertyNames(ref).length) { | ||
if (!options.part && keys.length !== Object.getOwnPropertyNames(ref).length) { | ||
return false; | ||
@@ -455,4 +469,20 @@ } | ||
var compare = options.deep ? exports.deepEqual : function (a, b) { return a === b; }; | ||
var compare, compareFlags; | ||
if (options.deep) { | ||
compare = exports.deepEqual; | ||
var hasOnly = options.hasOwnProperty('only'), hasPart = options.hasOwnProperty('part'); | ||
compareFlags = { | ||
prototype: hasOnly ? options.only : hasPart ? !options.part : false, | ||
part: hasOnly ? !options.only : hasPart ? options.part : true | ||
}; | ||
} | ||
else { | ||
compare = function (a, b) { | ||
return a === b; | ||
}; | ||
} | ||
var misses = false; | ||
@@ -485,3 +515,3 @@ var matches = new Array(values.length); | ||
for (var j = 0, jl = values.length, matched = false; j < jl && matched === false; ++j) { | ||
matched = compare(ref[i], values[j]) && j; | ||
matched = compare(values[j], ref[i], compareFlags) && j; | ||
} | ||
@@ -504,3 +534,3 @@ | ||
if (valuePairs && | ||
!compare(ref[key], valuePairs[key])) { | ||
!compare(valuePairs[key], ref[key], compareFlags)) { | ||
@@ -507,0 +537,0 @@ return false; |
{ | ||
"name": "hoek", | ||
"description": "General purpose node utilities", | ||
"version": "2.13.0", | ||
"version": "2.13.1", | ||
"repository": "git://github.com/hapijs/hoek", | ||
@@ -21,8 +21,3 @@ "main": "index", | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "BSD", | ||
"url": "http://github.com/hapijs/hoek/raw/master/LICENSE" | ||
} | ||
] | ||
"license": "BSD-3-Clause" | ||
} |
@@ -181,7 +181,13 @@ // Load modules | ||
var a = { | ||
x: function () { return 1; }, | ||
x: function () { | ||
return 1; | ||
}, | ||
y: {} | ||
}; | ||
a.x.z = 'string in function'; | ||
a.x.v = function () { return 2; }; | ||
a.x.v = function () { | ||
return 2; | ||
}; | ||
a.y.u = a.x; | ||
@@ -198,2 +204,3 @@ | ||
it('should copy a buffer', function (done) { | ||
var tls = { | ||
@@ -219,4 +226,7 @@ key: new Buffer([1, 2, 3, 4, 5]), | ||
Obj.prototype.b = function () { return 'c'; }; | ||
Obj.prototype.b = function () { | ||
return 'c'; | ||
}; | ||
var a = new Obj(); | ||
@@ -251,3 +261,6 @@ var b = Hoek.clone(a); | ||
Obj.prototype.b = function () { return 'c'; }; | ||
Obj.prototype.b = function () { | ||
return 'c'; | ||
}; | ||
Obj.prototype.isImmutable = true; | ||
@@ -1133,3 +1146,6 @@ | ||
configurable: true, | ||
get: function () { return 1; } | ||
get: function () { | ||
return 1; | ||
} | ||
}); | ||
@@ -1141,3 +1157,6 @@ | ||
configurable: true, | ||
get: function () { return 2; } | ||
get: function () { | ||
return 2; | ||
} | ||
}); | ||
@@ -1156,4 +1175,7 @@ | ||
Obj.prototype.b = function () { return this.a; }; | ||
Obj.prototype.b = function () { | ||
return this.a; | ||
}; | ||
var Ref = function () { | ||
@@ -1164,4 +1186,7 @@ | ||
Ref.prototype.b = function () { return this.a; }; | ||
Ref.prototype.b = function () { | ||
return this.a; | ||
}; | ||
expect(Hoek.deepEqual(new Obj(), new Ref())).to.be.false(); | ||
@@ -1203,2 +1228,11 @@ expect(Hoek.deepEqual(new Obj(), new Obj())).to.be.true(); | ||
}); | ||
it('compares an object ignoring the prototype recursively', function (done) { | ||
var a = [Object.create(null)]; | ||
var b = [{}]; | ||
expect(Hoek.deepEqual(a, b, { prototype: false})).to.be.true(); | ||
done(); | ||
}); | ||
}); | ||
@@ -1351,2 +1385,7 @@ | ||
expect(Hoek.contain({ a: [1], b: [2], c: [3] }, { a: [1], c: [3] }, { deep: true })).to.be.true(); | ||
expect(Hoek.contain({ a: [{ b: 1 }, { c: 2 }, { d: 3, e: 4 }] }, { a: [{ b: 1 }, { d: 3 }] }, { deep: true })).to.be.true(); | ||
expect(Hoek.contain({ a: [{ b: 1 }, { c: 2 }, { d: 3, e: 4 }] }, { a: [{ b: 1 }, { d: 3 }] }, { deep: true, part: true })).to.be.true(); | ||
expect(Hoek.contain({ a: [{ b: 1 }, { c: 2 }, { d: 3, e: 4 }] }, { a: [{ b: 1 }, { d: 3 }] }, { deep: true, part: false })).to.be.false(); | ||
expect(Hoek.contain({ a: [{ b: 1 }, { c: 2 }, { d: 3, e: 4 }] }, { a: [{ b: 1 }, { d: 3 }] }, { deep: true, only: true })).to.be.false(); | ||
expect(Hoek.contain({ a: [{ b: 1 }, { c: 2 }, { d: 3, e: 4 }] }, { a: [{ b: 1 }, { d: 3 }] }, { deep: true, only: false })).to.be.true(); | ||
@@ -1362,2 +1401,29 @@ expect(Hoek.contain({ a: 1, b: 2, c: 3 }, 'd')).to.be.false(); | ||
expect(Hoek.contain({ a: [1], b: [2], c: [3] }, { a: [1], c: [3] })).to.be.false(); | ||
expect(Hoek.contain({ a: { b: { c: 1, d: 2 }}}, { a: { b: { c: 1 }}})).to.be.false(); | ||
expect(Hoek.contain({ a: { b: { c: 1, d: 2 }}}, { a: { b: { c: 1 }}}, { deep: true })).to.be.true(); | ||
expect(Hoek.contain({ a: { b: { c: 1, d: 2 }}}, { a: { b: { c: 1 }}}, { deep: true, only: true })).to.be.false(); | ||
expect(Hoek.contain({ a: { b: { c: 1, d: 2 }}}, { a: { b: { c: 1 }}}, { deep: true, only: false })).to.be.true(); | ||
expect(Hoek.contain({ a: { b: { c: 1, d: 2 }}}, { a: { b: { c: 1 }}}, { deep: true, part: true })).to.be.true(); | ||
expect(Hoek.contain({ a: { b: { c: 1, d: 2 }}}, { a: { b: { c: 1 }}}, { deep: true, part: false })).to.be.false(); | ||
// Getter check | ||
var Foo = function (bar) { | ||
this.bar = bar; | ||
}; | ||
Object.defineProperty(Foo.prototype, 'baz', { | ||
enumerable: true, | ||
get: function () { | ||
return this.bar; | ||
} | ||
}); | ||
expect(Hoek.contain({ a: new Foo('b') }, { a: new Foo('b') }, { deep: true })).to.be.true(); | ||
expect(Hoek.contain({ a: new Foo('b') }, { a: new Foo('b') }, { deep: true, part: true })).to.be.true(); | ||
expect(Hoek.contain({ a: new Foo('b') }, { a: { baz: 'b' }}, { deep: true })).to.be.true(); | ||
expect(Hoek.contain({ a: new Foo('b') }, { a: { baz: 'b' }}, { deep: true, only: true })).to.be.false(); | ||
expect(Hoek.contain({ a: new Foo('b') }, { a: { baz: 'b' }}, { deep: true, part: false })).to.be.false(); | ||
expect(Hoek.contain({ a: new Foo('b') }, { a: { baz: 'b' }}, { deep: true, part: true })).to.be.true(); | ||
done(); | ||
@@ -1741,2 +1807,3 @@ }); | ||
it('throws the same Error that is passed to it if there is only one error passed', function (done) { | ||
var error = new Error('ruh roh'); | ||
@@ -2017,4 +2084,7 @@ var error2 = new Error('ruh roh'); | ||
var orig = Path.isAbsolute; | ||
Path.isAbsolute = function (path) { return path[0] === '/'; }; | ||
Path.isAbsolute = function (path) { | ||
return path[0] === '/'; | ||
}; | ||
expect(Hoek.isAbsolutePath('', 'linux')).to.equal(false); | ||
@@ -2200,2 +2270,3 @@ expect(Hoek.isAbsolutePath('a', 'linux')).to.equal(false); | ||
expect(function () { | ||
var result = Hoek.transform(source, { | ||
@@ -2202,0 +2273,0 @@ lineOne: {} |
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
149737
2596