From 055a50a055c75a5872057250809d46da3ad40508 Mon Sep 17 00:00:00 2001 From: Sean Hamilton Date: Thu, 29 Nov 2018 16:41:08 +0000 Subject: [PATCH] feat(empty): add empty function --- src/empty.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/empty.js diff --git a/src/empty.js b/src/empty.js new file mode 100644 index 00000000..bf474133 --- /dev/null +++ b/src/empty.js @@ -0,0 +1,24 @@ +// o +import is from './is'; +import size from './size'; + +/** + * Check if an object is empty (has no keys) + * + * @param {object} object The object to check + * + * @returns {boolean} Whether it is empty + */ +function empty(object) { + // check if the object specified is an object + if (is(object)) { + // if it is get the size of the object and return true if it + // is larger then 0 meaning it isn't empty + return !(size(object) > 0); + } + + // return false if the object isn't an object + return false; +} + +export default empty;