1.0.2 • Published 9 years ago

complex-module v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

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
resObjectresult where to store found modules, uses moduleInfoOrDir.exports if not defined
filterObjectsee 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
1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago