cm

complex-module

Simple tool for creating complex node js modules

Showing:

Popularity

Downloads/wk

1

Maintenance

No Maintenance Data Available

Package

Dependencies

1

Size (min+gzip)

1.5KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

complex-module

Converts directory structure to exported object.

Travis CI build

Please overview tests to see what that tool does: https://github.com/amuzalevskiy/complex-module/tree/master/test

Sample:

Directory structure

tools/
    usefullTool.js
exportedClass.js

will be converted to

module.exports = {
    tools: {
        usefullTool: require('./tools/usefullTool.js'),
    },
    exportedClass: require('./exportedClass.js')
}

Using following script (e.g. index.js):

// will populate all modules in current directory to module.exports object
require('complex-module').make(module);

Or if your library is placed in sub-folder:

var complexModule = require('complex-module');
complexModule.make(complexModule.baseDir(module.filename) + '/lib', module.exports);

baseDir(str) ⇒ string

Removes filename from full filename leaving base dir only

Kind: global function

ParamType
strstring

make(moduleInfoOrDir, [res], [filter]) ⇒ Object

Finds all javascripts inside folder and inserts into result. Converts directory structure to object structure

Usual use case:

// will populate all modules in current directory to module.exports object
require('complex-module').make(module);

If your library is in subfolder (shorthand - makeFromDirectory() fn):

var complexModule = require('complex-module');
complexModule.make(complexModule.baseDir(module.filename) + '/lib', module.exports);

Kind: global function
Returns: Object - object passed as an argument or new object populated with all modules inside baseDir

ParamTypeDescription
moduleInfoOrDirstring | Objectmodule information or directory where search files
[res]Objectresult where to store found modules, uses moduleInfoOrDir.exports if not defined
[filter]Objectsee fs-walker filter for details.
                    Default behaviour is to add all `*.js` files, ignoring files placed in `node_modules`, `test`
                    and dot-started directories |

makeFromDirectory(moduleInfo, innerPath) ⇒ Object

Shorthand for creating modules from sub directory

Kind: global function

ParamType
moduleInfoObject
innerPathstring

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100