hmu-core v1.0.0
hmu-core
Run HMU requests and get raw output
hmu([
// A request:
{ target: require('hmu-npm'),
input: [ 'foo', 'bar', 'baz' ],
options: { filter: 'free' } }
], function (err, res) {
// Handle results however
// Display in whatever environment
// e.g. terminal, chat, web
})
This module is for running HMU requests (otherwise called plugins) and getting raw output.
If you are looking for a CLI version, see hmu
.
This module is for using the same easy function for different displays like chat, web, email, etc.
Installation
$ npm install --save hmu-core
Usage
hmu(requests, [callback])
Runs the given requests
and gives the mapped results in callback
.
Parameters
requests
(Array
): An array of "request objects" in the form{ target, input, options }
callback
(Function
): Collected results. Called with params(err, res)
.res
being a map ofrequests
.
Examples
hmu([
{ target: require('hmu-npm'),
input: [ 'foo', 'bar', 'baz' ] },
{ target: require('hmu-gh'),
input: [ 'foojs', 'barjs', 'bazjs' ],
options: { filter: 'free' } }
], function (err, res) {
t.same(res, [
[ 'foo taken', 'bar taken', 'baz taken' ],
[ 'barjs free', 'bazjs free' ]
])
})
request
A request
is a plain object in the form:
{
target: Function,
input: Array, // optional (undefined, null)
options: Array // optional
}
A target
is otherwise called a "plugin". A plugin is more on the front-end side as it gets resolved into a target (which then gets ran). This is so you can do dynamic plugins, e.g. a function loaded as a target from chat messages.
plugin
A plugin gets called with target(input, options, callback)
. input
and options
are from request
if ran with hmu-core
, but this form makes them reusable as any normal function.
The callback
is called in (err, output)
. You can think of output
as a map or reduce of input
, and your options
can trigger varying output alongside that.
Examples
// Simple HTTP fetch plugin using `pull-stream` and `pull-fetch`
function plugin (input, opts, cb) {
pull(
values(input),
asyncMap((item, done) => {
// pull-fetch on url
pull(fetch.result(item, opts), collect(done))
}),
collect(cb)
)
}
License
MIT © Jamen Marz