blob: 5c36ff769baa5549e37efd99a3e2b3c6efd3c251 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001module.exports = parseArguments
2
3function isWritable(stream) {
4 return typeof stream.write === "function" &&
5 typeof stream.end === "function"
6}
7
8function parseArguments(req, res, opts, callback) {
9 // (req, cb)
10 if (typeof res === "function") {
11 callback = res
12 opts = {}
13 res = null
14 }
15
16 // (req, res, cb)
17 if (typeof opts === "function") {
18 callback = opts
19 opts = {}
20 }
21
22 // (req, opts, cb)
23 if (res && !isWritable(res)) {
24 opts = res
25 res = null
26 }
27
28 // default (req, res, opts, cb)
29 return { req: req, res: res, opts: opts, callback: callback }
30}