| 18 | const output = {} |
| 19 | |
| 20 | function step (object, prev, currentDepth) { |
| 21 | currentDepth = currentDepth || 1 |
| 22 | Object.keys(object).forEach(function (key) { |
| 23 | const value = object[key] |
| 24 | const isarray = opts.safe && Array.isArray(value) |
| 25 | const type = Object.prototype.toString.call(value) |
| 26 | const isbuffer = isBuffer(value) |
| 27 | const isobject = ( |
| 28 | type === '[object Object]' || |
| 29 | type === '[object Array]' |
| 30 | ) |
| 31 | |
| 32 | const newKey = prev |
| 33 | ? prev + delimiter + transformKey(key) |
| 34 | : transformKey(key) |
| 35 | |
| 36 | if (!isarray && !isbuffer && isobject && Object.keys(value).length && |
| 37 | (!opts.maxDepth || currentDepth < maxDepth)) { |
| 38 | return step(value, newKey, currentDepth + 1) |
| 39 | } |
| 40 | |
| 41 | output[newKey] = value |
| 42 | }) |
| 43 | } |
| 44 | |
| 45 | step(target) |
| 46 | |