Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

equal object support #262

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions is.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,29 @@
if (is.all.boolean(value, other)) {
return value === other;
}
// check object
if (is.all.object(value, other)) {
var keys = Object.keys(value),
length = keys.length,
key;

if (is.empty(value) && is.empty(other)) {
return true;
}

if (length !== Object.keys(other).length) {
return false;
}

while(length--) {
key = keys[length];
if (is.not.propertyDefined(other, key)) {
return false;
}
}
return true;
}

return false;
};
// equal method does not support 'all' and 'any' interfaces
Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,30 @@
it('should return false if given two boolean are not same', function() {
expect(is.equal(false, true)).to.be.false;
});
it('should return true if given two object are empty', function() {
expect(is.equal({},{})).to.be.true;
});
it('should return false if given two object are not same number of property', function() {
var obj1 = {
test: 'test',
is: 'is'
};
var obj2 = {
is: 'is'
};
expect(is.equal(obj1, obj2)).to.be.false;
});
it('should return true if given two object are the same number of the same properties', function() {
var obj3 = {
test: 'test',
is: 'is'
};
var obj4 = {
test: true,
is: 4
};
expect(is.equal(obj3, obj4)).to.be.true;
});
});
checkApi('equal', ['not']);

Expand Down