README
Export Directory
Require all files in a directory and export an object.
Installation
$ npm install export-dir-files
Usage
var exportDir = require( 'export-dir-files' );
exportDir( dir )
Require all files in a directory and export an object
.
var out = exportDir( 'path/to/directory' );
// returns {...}
The module will filter a directory's contents for file modules (i.e., files ending in .js
, .json
, or .node
). For example, given the following directory structure
/
└── foo
└── bar
└── beep.js
└── boop.json
└── bap.node
└── bop.txt
└── bip
└── hello.txt
└── index.js
and
$ cd foo
the module will behave as follows:
var out = require( './bar' );
/*
{
'beep': <export>,
'boop': <json>,
'bap': <addon>
}
*/
Notes
Relative paths are resolved relative to the current working directory.
If a directory does not contain any recognized file exports, the module returns an empty
object
. For example, given/ └── foo └── bar └── bop.txt
the module will behave as follows:
var out = exportDir( '/foo/bar' ); // returns {}
Examples
var exportDir = require( 'export-dir-files' );
var out = exportDir( './test/fixtures' );
console.log( out );
To run the example code from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2015. Athan Reines.