UI for Zipcoin Blue

parse-arguments.js 645B

12345678910111213141516171819202122232425262728293031
  1. module.exports = parseArguments
  2. function isWritable(stream) {
  3. return typeof stream.write === "function" &&
  4. typeof stream.end === "function"
  5. }
  6. function parseArguments(req, res, opts, callback) {
  7. // (req, cb)
  8. if (typeof res === "function") {
  9. callback = res
  10. opts = {}
  11. res = null
  12. }
  13. // (req, res, cb)
  14. if (typeof opts === "function") {
  15. callback = opts
  16. opts = {}
  17. }
  18. // (req, opts, cb)
  19. if (res && !isWritable(res)) {
  20. opts = res
  21. res = null
  22. }
  23. // default (req, res, opts, cb)
  24. return { req: req, res: res, opts: opts, callback: callback }
  25. }