Skip to content

Commit 06e0e7d

Browse files
Fix #554 is empty with Symbol as property name (#555)
1 parent ccba923 commit 06e0e7d

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

packages/object-is-empty/index.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function isEmpty(obj) {
3939
var type = {}.toString.call(obj);
4040

4141
if (type == '[object Object]') {
42-
return !Object.keys(obj).length;
42+
return !Object.keys(obj).length && !Object.getOwnPropertySymbols(obj).length;
4343
}
4444

4545
if (type == '[object Map]' || type == '[object Set]') {

packages/object-is-empty/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function isEmpty(obj) {
3939
var type = {}.toString.call(obj);
4040

4141
if (type == '[object Object]') {
42-
return !Object.keys(obj).length;
42+
return !Object.keys(obj).length && !Object.getOwnPropertySymbols(obj).length;
4343
}
4444

4545
if (type == '[object Map]' || type == '[object Set]') {

test/object-is-empty/index.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ test('empty object, array, map or set', function(t) {
1313
});
1414

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

0 commit comments

Comments
 (0)