Require multiple modules at once. Modules can be returned as properties of an object, as an array or iterated over with a callback.
npm install require-many
paths options iterator callback
paths can either be a path to a directory or file, or an array of paths.
options can contain any of the following:
asArray- boolean indicating whether to return modules as an array rather than within an object
predicate- a function that will be called for each file or directory to allow unwanted modules to be filtered out
recurse- boolean indicating whether to recurse down through any sub-directories
lazyLoad- boolean indicating whether to wrap module require in a function for delayed execution
iterator will be called for each required module and is passed the module, the path to the file and a callback.
callback will be called once all modules have been required.
var path =requireMany =modules;// Return all modules from a single directory as properties of an object// (property name is exported function name if specified, otherwise the filename)modules = ;// Return all modules from a single directory as an arraymodules = ;// Return specific modules from different locationsmodules = ;// Recurse down through directory and require modules from sub-directoriesmodules = ;// Return all modules from multiple directoriesmodules = ;// Pass a predicate to only require certain files within the directorymodules =;// Apply an iterator to each module and pass a callback;// Lazy load modules;
At the moment, if multiple modules are included with the same name (e.g. within different directories), last wins when returning as an object. When using an iterator or returning as an array, each instance will be included.
Not yet :( #ashamed
Copyright (c) 2015 Luke Bennett <email@example.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.