From 79446ca52cea0864ebe2540ba774cc386ee2f8bc Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Mon, 13 Dec 2021 21:09:21 +0100 Subject: add `is_object_empty` utility function --- common/misc.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'common') diff --git a/common/misc.js b/common/misc.js index a960d35..4d4b346 100644 --- a/common/misc.js +++ b/common/misc.js @@ -149,6 +149,17 @@ const matchers = { ] }; +/* + * Facilitates checking if there aren't any keys in object. This does *NOT* + * account for pathological cases like redefined properties of Object prototype. + */ +function is_object_empty(object) +{ + for (const key in object) + return false; + return true; +} + /* * EXPORTS_START * EXPORT gen_nonce @@ -158,5 +169,6 @@ const matchers = { * EXPORT open_in_settings * EXPORT is_privileged_url * EXPORT matchers + * EXPORT is_object_empty * EXPORTS_END */ -- cgit v1.2.3