UNPKG

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