Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zoubin/require-array
extend native require to handle array inputs based on node-resolve
https://github.com/zoubin/require-array
Last synced: 8 days ago
JSON representation
extend native require to handle array inputs based on node-resolve
- Host: GitHub
- URL: https://github.com/zoubin/require-array
- Owner: zoubin
- Created: 2015-06-12T02:51:44.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-18T03:27:20.000Z (over 9 years ago)
- Last Synced: 2024-09-25T23:49:28.691Z (about 2 months ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# require-array
extend native require to handle array inputs based on node-resolve## Example
```
⌘ tree example/
example/
├── files
│ ├── a.js
│ ├── b.js
│ └── exclude.js
└── require.js
```require.js:
```javascript
var arequire = require('..');
var mods = arequire(['path', './a.js'], { basedir: __dirname + '/files' })
console.log(
mods[0].basename('/path/to/a.js', '.js'),
mods[1]
);mods = arequire.glob(['*.js', '!exclude.js'], { cwd: __dirname + '/files' })
console.log(
mods
);```
a.js:
```javascript
module.exports = 'a';
```b.js:
```javascript
module.exports = 'b';
```exclude.js:
```javascript
module.exports = 'exclude';
```output:
```
⌘ node example/require.js
a a
[ 'a', 'b' ]
```## Usage
### arequire(mods, opts)
* **mods**: *String* *Array* module names or paths to resolve by [node-resolve](https://www.npmjs.com/package/resolve)
* **opts**: *Object|Function* *Optional* If *Object*, passed directly to [node-resolve.sync](https://github.com/substack/node-resolve#resolvesyncid-opts). If *Function*, used to resolve the modules like [node-resolve.sync](https://github.com/substack/node-resolve#resolvesyncid-opts)### arequire.resolve(mods, opts)
Resolve the path to be required.
### arequire.glob(patterns, opts, resolveOpts)
* **patterns**: *String* *Array* patterns to locate files by [xglob](https://www.npmjs.com/package/xglob)
* **opts**: *Object* *Optional* passed directly to [xglob](https://www.npmjs.com/package/xglob)
* **resolveOpts**: *Object|Function* *Optional* If *Object*, passed directly to [node-resolve.sync](https://github.com/substack/node-resolve#resolvesyncid-opts). If *Function*, used to resolve the modules like [node-resolve.sync](https://github.com/substack/node-resolve#resolvesyncid-opts)### arequire.glob.resolve(mods, opts, resolveOpts)
Resolve the path to be required.