The regex /^http?:\/\// will match http:// but also htt://.
Is this really intended, or should the ? be removed on this line? (It is ofcourse needed later in the https? replace regex.)
It probably misses an s before that question mark.
update: sorry, I see the purpose now. Maybe this could be an easier and more standard way of getting the protocol
Yes that sounds like a good idea
URL wasn't always available as a global in Node nor browsers so I would guess manually parsing the string is the best way to ensure the best compatibility without adding dependencies.
Ah ok, yeah sounds fair. but then it's just a matter of removing the ? in that specific line?
https://nodejs.org/api/url.html#url_class_url
If I understand this correctly, URL is supported since Node 10, which is the lowest supported node version anyway, so I think it is safe to use now. Am I wrong?
Good point! In browsers however, people who need to support Internet Explorer would have to include a polyfill.
@JohnProto Perhaps the original author had a reason to do it this way? Otherwise, I agree the ? doesn't seem to serve a purpose 馃
Next.js includes polyfills for IE11, I assume URL is no different. Or wouldn't that cut it, even though this package will always be used together with next?