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

16 lines
387 B
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
'use strict';
module.exports = (url, opts) => {
if (typeof url !== 'string') {
throw new TypeError(`Expected \`url\` to be of type \`string\`, got \`${typeof url}\``);
}
url = url.trim();
opts = Object.assign({https: false}, opts);
if (/^\.*\/|^(?!localhost)\w+:/.test(url)) {
return url;
}
return url.replace(/^(?!(?:\w+:)?\/\/)/, opts.https ? 'https://' : 'http://');
};