Skip to content

Commit

Permalink
Fix #554 is empty with Symbol as property name (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
ginoemiliozzi committed May 6, 2023
1 parent ccba923 commit 06e0e7d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/object-is-empty/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function isEmpty(obj) {
var type = {}.toString.call(obj);

if (type == '[object Object]') {
return !Object.keys(obj).length;
return !Object.keys(obj).length && !Object.getOwnPropertySymbols(obj).length;
}

if (type == '[object Map]' || type == '[object Set]') {
Expand Down
2 changes: 1 addition & 1 deletion packages/object-is-empty/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function isEmpty(obj) {
var type = {}.toString.call(obj);

if (type == '[object Object]') {
return !Object.keys(obj).length;
return !Object.keys(obj).length && !Object.getOwnPropertySymbols(obj).length;
}

if (type == '[object Map]' || type == '[object Set]') {
Expand Down
3 changes: 2 additions & 1 deletion test/object-is-empty/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ test('empty object, array, map or set', function(t) {
});

test('non-empty object, array, map or set', function(t) {
t.plan(6);
t.plan(7);
t.notOk(isEmpty({a: 3, b: 5}));
t.notOk(isEmpty({[Symbol('a')]: "some-value"}));
t.notOk(isEmpty([1, 2]));
t.notOk(isEmpty(['a', 'b']));
t.notOk(isEmpty(new Array(4)));
Expand Down

0 comments on commit 06e0e7d

Please sign in to comment.