https://github.com/seangenabe/require-glob-array
require node modules and place their exported values in an array
https://github.com/seangenabe/require-glob-array
Last synced: 7 months ago
JSON representation
require node modules and place their exported values in an array
- Host: GitHub
- URL: https://github.com/seangenabe/require-glob-array
- Owner: seangenabe
- License: mit
- Created: 2016-03-22T09:40:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-26T03:56:38.000Z (over 7 years ago)
- Last Synced: 2025-03-03T06:04:27.933Z (7 months ago)
- Language: JavaScript
- Size: 23.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# require-glob-array
require node modules and place their exported values in an array
[](https://www.npmjs.com/package/require-glob-array)
[](https://travis-ci.org/seangenabe/require-glob-array)
[](https://david-dm.org/seangenabe/require-glob-array)## Usage
```
- dir
- unicorn.js: module.exports = 'foo'
- cake.js: module.exports = 'bar'
- rainbow.js: module.exports = 'baz'
``````javascript
const requireGlobArray = require('require-glob-array')
let out = requireGlobArray({ cwd: 'dir' })
out //=> ['bar', 'baz', 'foo']
```## API
### requireGlobArray([patterns], [options])
Returns an array containing all of the exported values of the modules that
are globbed.Parameters:
* `patterns: string|array`: `minimatch` [patterns](https://github.com/isaacs/minimatch#usage) passed to `globby`. Defaults to `**/*.js`.
* `options: object`: `glob` [options](https://github.com/isaacs/node-glob#options) passed to globby.
* `options.returnPath`: Include the path in the return value. If `true`, instead of each export value, each item in the return array will now be `[path, export]`, where:
* `path`: The globbed path
* `export`: The export value
Default: `undefined`.Returns:
* `Array`: The exported modules.### requireGlobArray.async([patterns], [options])
Run asynchronously. Has similar options to `requireGlobArray` (the synchronous version above).
The synchronous version is the default because it's probably what they'd want when they `require` a bunch of files.
Returns:
* `Promise`: The exported modules.## NOT compatible with Browserify
Obviously, this module is not compatible with Browserify since it uses dynamic `require` calls.
## License
MIT