Index Module
Automatically export all other modules in the same directory. No configuration, no dependencies.
Install
$ npm install --save index-module
Standard Usage
Add the following line of code to an index.js
file in any directory to add all other .js
and .json
files in that directory to module.exports
. The module names will be camelCase and will not begin with a number or have any special characters.
module;
Note that your file does not need to be called index.js
, this is just the standard use so you can require all files in a directory by requiring the relative path of the directory.
Custom Filter
You can pass a custom filename filter function as the second argument, to control which filenames or file extensions are exported.
const customFilter = { return fileExt === '.js'; // ignore .json and all other file types}; module customFilter;
Custom Mapper
You can pass a custom module name mapper function as the third argument, to control how a filename is converted to an exported module name.
const _ = ; const customMapper = { let moduleName = _; let startsWithCapitalLetter = fileName === fileName; if startsWithCapitalLetter && fileExt !== '.json' moduleName = _; return moduleName;}; module null customMapper;
Tests
$ npm test