Files: 49c6e5459b68f2a30bcecf7727b8c9a99cfe4e79 / lib / mapModules.js
553 bytesRaw
1 | const { set } = require('libnested') |
2 | const isModule = require('depject/is') |
3 | |
4 | module.exports = mapModules |
5 | |
6 | function mapModules (obj, iter) { |
7 | var o = {} |
8 | eachModule(obj, (v, path) => { |
9 | set(o, path, iter(v, path)) |
10 | }) |
11 | return o |
12 | } |
13 | |
14 | function eachModule (obj, iter, path) { |
15 | path = path || [] |
16 | for (var k in obj) { |
17 | if (isObject(obj[k])) { |
18 | if (isModule(obj[k])) iter(obj[k], path.concat(k)) |
19 | else eachModule(obj[k], iter, path.concat(k)) |
20 | } |
21 | } |
22 | } |
23 | |
24 | function isObject (o) { |
25 | return o && 'object' === typeof o && !Array.isArray(o) |
26 | } |
27 |
Built with git-ssb-web