Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zoubin/resolve-and-call
Resolve a module and call the function it exports
https://github.com/zoubin/resolve-and-call
Last synced: 8 days ago
JSON representation
Resolve a module and call the function it exports
- Host: GitHub
- URL: https://github.com/zoubin/resolve-and-call
- Owner: zoubin
- License: mit
- Created: 2015-09-25T06:44:44.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-01T14:16:04.000Z (about 9 years ago)
- Last Synced: 2024-04-24T04:32:11.155Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 160 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# resolve-and-call [![Build Status](https://travis-ci.org/zoubin/resolve-and-call.svg?branch=master)](https://travis-ci.org/zoubin/resolve-and-call)
Resolve a module and call the function it exports.## example
```
⌘ tree example/
example/
├── call.js
├── lib
│ └── subtract
│ └── index.js
└── node_modules
└── add
└── index.js
````call.js`:
```javascript
var call = require('..');console.log(
'Expect: 3',
'\n',
'Actual: ',
call('add', 1, 2)
);console.log(
'Expect: 1',
'\n',
'Actual: ',
call({ basedir: __dirname + '/lib' }, './subtract', 2, 1)
);```
output:
```
⌘ node example/call.js
Expect: 3
Actual: 3
Expect: 1
Actual: 1
```## res = call([opts, ]fn, arg,...)
### opts
Type: `Object`
Passed to [resolve](https://github.com/substack/node-resolve).
### fn
Type: `Function`, `String`
The function to be called.
If `String`, it will be resolved to the path of a module,
which exports the function to be called.### args
All arguments that follow `fn` will be passed to `fn` when it is called.
### res
The result of calling `fn`.