1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/prepend-http/index.js

15 lines
288 B
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
'use strict';
2024-01-16 21:26:16 +08:00
module.exports = function (url) {
2023-12-18 13:12:25 +08:00
if (typeof url !== 'string') {
2024-01-16 21:26:16 +08:00
throw new TypeError('Expected a string, got ' + typeof url);
2023-12-18 13:12:25 +08:00
}
url = url.trim();
if (/^\.*\/|^(?!localhost)\w+:/.test(url)) {
return url;
}
2024-01-16 21:26:16 +08:00
return url.replace(/^(?!(?:\w+:)?\/\/)/, 'http://');
2023-12-18 13:12:25 +08:00
};