diff --git a/index.js b/index.js index c4abc95..a4fb1db 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,10 @@ const isObject = value => { return value !== null && (type === 'object' || type === 'function'); }; +const isEmptyObject = value => { + return isObject(value) && Object.entries(value).length === 0; +}; + const disallowedKeys = new Set([ '__proto__', 'prototype', @@ -326,6 +330,10 @@ function * deepKeysIterator(object, currentPath = []) { for (const [key, value] of entries(object)) { yield * deepKeysIterator(value, [...currentPath, key]); + + if (isEmptyObject(value)) { + yield key; + } } } diff --git a/test.js b/test.js index 556d810..ede6bdb 100644 --- a/test.js +++ b/test.js @@ -420,6 +420,8 @@ test('deepKeys', t => { }], e: '🦄', f: 0, + h: {}, + i: [], }, '': { a: 0, @@ -437,6 +439,8 @@ test('deepKeys', t => { 'a\\.b.c.d[2].g', 'a\\.b.c.e', 'a\\.b.c.f', + 'h', + 'i', 'a\\.b..a', '.a', ]);