import-all-from
A util helps importing all utils from given directory path
Installation
$ npm install import-all-from --save
Usage
const importAllFrom =// return an array containing all modules right under given directoryconst utils =utils// orfor const util of utils// do something ...
NOTE: Directory path should be an absolute path from system root. For node.js, you can use ___dirname
to get absolute path of the directory where current file is located in.
// assume __dirname here refers to '/system/absolute/path/to'const modules =
Options
Examples
(1) Writing Tests
This util makes an easy way to manage structure of test files, you can thus handle each function test with separate file.
/* unit-tests/unit-test1.js *//* unit-tests/unit-test2.js */// ...
(2) Handlers / Checkers
Perhaps you might have some state handlers / checkers which have same return data format, for better management, you can separate each condition with different modules with this util.
let stateconst checkers =for const checker of checkersstate =if state // or satisfied specific condition// do something ...
Tests
- unit-test & integration-test
$ npm test
- unit-test only
$ npm run test-unit
- integration-test only
$ npm run test-integration
License
MIT