requirements-mapper
Auto-require all matching files within a directory recursively and return them as single object, representing the directory's structure.
Usage
var ReqMapper =dataMapper = './data')dataMap = dataMapper;
Example
Assuming that ./data
is a directory containing multiple files using subfolders
like this:
data/├─╸ other/│ ├─╸ bar.js│ └─╸ baz.json└─╸ foo.js
An object of which every node contains the require
d contents of the respective
file will be returned by RequirementsMapper.map()
:
other:bar: …baz: …foo: …
Options
The constructor of RequirementsMapper
accepts 3 parameters:
dir
- directory to scan; defaults toprocess.cwd()
globPattern
- globbing pattern for finding files; defaults to**/*.js?(on)
clearCache
- clear the require cache for a node, before requiring it; defaults totrue
See node-glob for more details on globbing options.