blob: 60f532ac59c4144ad1d8225a1bfcdb48a32793d3 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2module.exports = function (url) {
3 if (typeof url !== 'string') {
4 throw new TypeError('Expected a string, got ' + typeof url);
5 }
6
7 url = url.trim();
8
9 if (/^\.*\/|^(?!localhost)\w+:/.test(url)) {
10 return url;
11 }
12
13 return url.replace(/^(?!(?:\w+:)?\/\/)/, 'http://');
14};