UNPKG

288 BJavaScriptView Raw
1'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};