| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | module.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 | }; | ||||