import-modules-auto
v1.0.2
Published
Import all modules in a directory smart
Downloads
1
Maintainers
Readme
import-modules-auto
Fork from https://github.com/sindresorhus/import-modules
Add when import Object-Module, merge Object without key-word.
Import all modules in a directory smart
This module is intentionally simple. Not interested in more features.
Install
$ npm install --save import-modules-auto
Usage
.
└── dir
├── foo-bar.js //function
└── baz-faz.js //object {test: 'value'}
const importModules = require('import-modules-auto');
const modules = importModules('dir');
console.log(modules);
//=> {fooBar: [Function], bazFaz: [Function]}
const importModules = require('import-modules-auto');
const modules = importModules('dir',{hasKey: false});
console.log(modules);
//=> {fooBar: [Function], test: 'value'}
API
importModules([directory], [options])
directory
Type: string
Default: __dirname
Directory to import modules from. Unless you've modified require.extensions
, that means any .js
, .json
, .node
files, in that order. Does not recurse. Ignores the caller file and files starting with .
or _
.
options
Type: Object
camelize
Type: boolean
Default: true
Convert dash-style names (foo-bar
) to camel-case (fooBar
).
haskey
Type: boolean
Default: true
Can set module without key words, merge object.
Related
- import-from - Import a module from a given path
- import-cwd - Import a module from the current working directory
- import-lazy - Import a module lazily
License
MIT © webkong