Opal-Estate-Pro/node_modules/body/parse-arguments.js
2019-09-13 11:27:52 +07:00

31 lines
645 B
JavaScript

module.exports = parseArguments
function isWritable(stream) {
return typeof stream.write === "function" &&
typeof stream.end === "function"
}
function parseArguments(req, res, opts, callback) {
// (req, cb)
if (typeof res === "function") {
callback = res
opts = {}
res = null
}
// (req, res, cb)
if (typeof opts === "function") {
callback = opts
opts = {}
}
// (req, opts, cb)
if (res && !isWritable(res)) {
opts = res
res = null
}
// default (req, res, opts, cb)
return { req: req, res: res, opts: opts, callback: callback }
}