https://github.com/simbo/requirements-mapper
https://github.com/simbo/requirements-mapper
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/simbo/requirements-mapper
- Owner: simbo
- License: mit
- Created: 2015-07-29T08:48:29.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-02-02T20:18:29.000Z (over 10 years ago)
- Last Synced: 2025-02-22T04:19:35.611Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
requirements-mapper
===================
> Auto-require all matching files within a directory recursively and return
> them as single object, representing the directory's structure.
[](https://www.npmjs.com/package/requirements-mapper)
[](http://simbo.mit-license.org)
[](https://travis-ci.org/simbo/requirements-mapper)
[](https://codeclimate.com/github/simbo/requirements-mapper)
[](https://codeclimate.com/github/simbo/requirements-mapper)
[](https://david-dm.org/simbo/requirements-mapper)
[](https://david-dm.org/simbo/requirements-mapper#info=devDependencies)
---
## Usage
``` javascript
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:
``` text
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()`:
``` javascript
{
other: {
bar: …
baz: …
},
foo: …
}
```
### Options
The constructor of `RequirementsMapper` accepts 3 parameters:
- `dir` - directory to scan; defaults to `process.cwd()`
- `globPattern` - globbing pattern for finding files; defaults to
`**/*.js?(on)`
- `clearCache` - clear the require cache for a node, before requiring it; defaults to `true`
See [node-glob](https://github.com/isaacs/node-glob) for more details on
globbing options.
## License
[MIT Simon Lepel 2015](http://simbo.mit-license.org)