UNPKG

696 BJavaScriptView Raw
1const co = require('co');
2const loader = require('./loader');
3const is = require('is_js');
4
5/**
6 * Run a report from a path or function
7 *
8 * @param {String | Function} report
9 * - fully qualified url to bundled module
10 * - file path to module (absolute or relative)
11 * - report function (ordinary or yieldable)
12 * @param {*} [parameters = {}]
13 */
14const run = co.wrap(function * (report, parameters) {
15 if (!report) throw new TypeError('report: must be defined');
16 parameters = parameters || {};
17 if (is.string(report)) report = yield loader.load(report);
18 if(!is.function(report)) throw new TypeError('report: must be a Function');
19 return report(parameters);
20});
21module.exports = run;