From a12e3ed32e36ab08f5c2321c4a5217c6c29a912e Mon Sep 17 00:00:00 2001 From: GinoE Date: Mon, 1 May 2023 14:41:42 +0200 Subject: [PATCH] Fix #554 is empty with Symbol as property name --- packages/object-is-empty/index.cjs | 2 +- packages/object-is-empty/index.mjs | 2 +- test/object-is-empty/index.cjs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/object-is-empty/index.cjs b/packages/object-is-empty/index.cjs index 5e679b7c5..39a8c6fc8 100644 --- a/packages/object-is-empty/index.cjs +++ b/packages/object-is-empty/index.cjs @@ -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]') { diff --git a/packages/object-is-empty/index.mjs b/packages/object-is-empty/index.mjs index 224f14fff..a814e6f88 100644 --- a/packages/object-is-empty/index.mjs +++ b/packages/object-is-empty/index.mjs @@ -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]') { diff --git a/test/object-is-empty/index.cjs b/test/object-is-empty/index.cjs index 9f8cdc5af..3dfb88d08 100644 --- a/test/object-is-empty/index.cjs +++ b/test/object-is-empty/index.cjs @@ -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)));