git ssb

1+

dinoworm ๐Ÿ› / catstack



Tree: 49c6e5459b68f2a30bcecf7727b8c9a99cfe4e79

Files: 49c6e5459b68f2a30bcecf7727b8c9a99cfe4e79 / lib / mapModules.js

553 bytesRaw
1const { set } = require('libnested')
2const isModule = require('depject/is')
3
4module.exports = mapModules
5
6function mapModules (obj, iter) {
7 var o = {}
8 eachModule(obj, (v, path) => {
9 set(o, path, iter(v, path))
10 })
11 return o
12}
13
14function 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
24function isObject (o) {
25 return o && 'object' === typeof o && !Array.isArray(o)
26}
27

Built with git-ssb-web