Bones/node_modules/prepend-http/index.js
SOUTHERNCO\x2mjbyrn 7efe7605b8 Template Upload
2017-05-17 13:45:25 -04:00

15 lines
288 B
JavaScript

'use strict';
module.exports = function (url) {
if (typeof url !== 'string') {
throw new TypeError('Expected a string, got ' + typeof url);
}
url = url.trim();
if (/^\.*\/|^(?!localhost)\w+:/.test(url)) {
return url;
}
return url.replace(/^(?!(?:\w+:)?\/\/)/, 'http://');
};