UNPKG

489 BJavaScriptView Raw
1// Returns ALL of an object's keys (even nested ones) as an array of dot notation.
2const isObject = require('./is-object')
3const keys = require('lodash/keys')
4
5function objectDeepKeys(obj) {
6 if (!isObject(obj)) return []
7
8 return keys(obj)
9 .filter(key => isObject(obj[key]))
10 .map(key => objectDeepKeys(obj[key]).map(k => `${key}.${k}`))
11 .reduce(
12 (x, y) => x.concat(y),
13 Object.keys(obj).filter(key => !isObject(obj[key]))
14 )
15}
16
17module.exports = objectDeepKeys