15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'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://');
};