aseemk / requireDir

Node.js helper to require() directories.
MIT License
484 stars 60 forks source link

Add option to "flatten" when recursing #54

Closed devmattrick closed 6 years ago

devmattrick commented 6 years ago

It'd be great to have some sort of way to "flatten" a requireDir call so all modules are on the same level. I imagine either adding a flatten option or allowing users to specify recurse: 'flatten' in the options object.

stephenlacy commented 6 years ago

This would have an undesirable effect if two directories have the same name in a nested structure

test
├── one
│   └── two
└── two
    └── two

Would be flattened to:

test: {
  one: fn,
  two: fn
}

Thus omitting two entire folders. The only other option is to convert to an array, that would have an entire different API and use case.

devmattrick commented 6 years ago

Perhaps there can be namespacing such as one/two/module.js?

yocontra commented 6 years ago

You can do this with userland modules like lodash, don't think its something we want to support with an option.