From 9985ceaa5c7dcdabf929462a25143e90340cd125 Mon Sep 17 00:00:00 2001 From: Christoph Anderson Date: Mon, 25 Sep 2023 20:35:10 +0200 Subject: [PATCH] Added isEmptyObject() --- src/PoliciesTable.jsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/PoliciesTable.jsx b/src/PoliciesTable.jsx index 2725127..6d0463a 100644 --- a/src/PoliciesTable.jsx +++ b/src/PoliciesTable.jsx @@ -122,10 +122,28 @@ export class PoliciesTable extends Component { policySummary(policies) { let bits = []; + /** + * Check if the object is empty + * @param {*} obj + * @returns true if the object is empty + */ + function isEmptyObject(obj) { + return ( + Object.getPrototypeOf(obj) === Object.prototype && + Object.getOwnPropertyNames(obj).length === 0 && + Object.getOwnPropertySymbols(obj).length === 0 + ); + } + /** + * Check if object has it's key as a property. + * However, if the object itself is a set of sets, it has to be checked by isEmptyObject() + * @param {*} obj + * @returns + */ function isEmpty(obj) { for (var key in obj) { if (obj.hasOwnProperty(key)) - return false; + return isEmptyObject(obj[key]); } return true; }