requirements-mapper
v1.0.1
Published
Auto-require all matching files within a directory recursively and return them as single object, representing the directory's structure.
Downloads
11
Readme
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 = require('requirements-mapper'),
dataMapper = new ReqMapper('./data')),
dataMap = dataMapper.map();Example
Assuming that ./data is a directory containing multiple files using subfolders
like this:
data/
├─╸ other/
│ ├─╸ bar.js
│ └─╸ baz.json
└─╸ foo.jsAn object of which every node contains the required 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.
