gift-card-server/node_modules/prepend-http/index.js
Rodrigo Pedroso 3ac017a5ad Commit project
2019-06-19 10:46:14 -04:00

14 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://');
};