Commit 8282ce71 authored by Jérome Perrin's avatar Jérome Perrin

core/gadget_global.js: make isEmpty supports empty object

Co-authored-by: Romain Courteaud's avatarRomain Courteaud <romain@nexedi.com>
parent a683986f
...@@ -9,10 +9,14 @@ ...@@ -9,10 +9,14 @@
Calling isEmpty(x) is more robust than expression !x. Calling isEmpty(x) is more robust than expression !x.
*/ */
function isEmpty(value) { function isEmpty(value) {
return (value === undefined || return (
value === null || (value === undefined) ||
value.length === 0 || (value === null) ||
(typeof value === "number" && isNaN(value))); ((typeof value === "number") ?
isNaN(value) :
(Object.keys(value).length === 0)
)
);
} }
window.isEmpty = isEmpty; window.isEmpty = isEmpty;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment