node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org »

requirements-mapper

requirements-mapper

Auto-require all matching files within a directory recursively and return them as single object, representing the directory's structure.

npm Package Version MIT License Travis Build Status Code Climate GPA Code Climate Test Coverage

Dependencies Status devDependencies Status


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.js

An 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 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 for more details on globbing options.

License

MIT Simon Lepel 2015