hmu-core

1.0.0 • Public • Published

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 of requests.

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


version travis downloads license follow

Readme

Keywords

Package Sidebar

Install

npm i hmu-core

Weekly Downloads

6

Version

1.0.0

License

MIT

Last publish

Collaborators

  • npm