makit
Version:
Make in JavaScript done right!
30 lines (29 loc) • 855 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Recipe = void 0;
const string_1 = require("../utils/string");
const inspectSymbol = Symbol.for('nodejs.util.inspect.custom') || 'inspect';
class Recipe {
constructor(fn) {
this.fn = fn;
}
async make(context) {
// Case: make('foo')
if (this.fn.length < 2) {
return this.fn.call(context, context);
}
// Case: make('foo', cb)
return new Promise((resolve, reject) => {
this.fn.call(context, context, (err, data) => {
if (err)
reject(err);
else
resolve(data);
});
});
}
[inspectSymbol]() {
return string_1.limit(string_1.inline(this.fn.toString()));
}
}
exports.Recipe = Recipe;