| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | |
| 3 | |
| 4 | |
| 5 | // Copied from https://github.com/nodejs/node/blob/master/lib/internal/url.js |
| 6 | |
| 7 | function urlToOptions(url) { |
| 8 | var options = { |
| 9 | protocol: url.protocol, |
| 10 | hostname: url.hostname, |
| 11 | hash: url.hash, |
| 12 | search: url.search, |
| 13 | pathname: url.pathname, |
| 14 | path: `${url.pathname}${url.search}`, |
| 15 | href: url.href |
| 16 | }; |
| 17 | if (url.port !== '') { |
| 18 | options.port = Number(url.port); |
| 19 | } |
| 20 | if (url.username || url.password) { |
| 21 | options.auth = `${url.username}:${url.password}`; |
| 22 | } |
| 23 | return options; |
| 24 | } |
| 25 | |
| 26 | |
| 27 | |
| 28 | module.exports = urlToOptions; |