1 | export default function prependHttp(url, {https = true} = {}) {
|
2 | if (typeof url !== 'string') {
|
3 | throw new TypeError(`Expected \`url\` to be of type \`string\`, got \`${typeof url}\``);
|
4 | }
|
5 |
|
6 | url = url.trim();
|
7 |
|
8 | if (/^\.*\/|^(?!localhost)\w+?:/.test(url)) {
|
9 | return url;
|
10 | }
|
11 |
|
12 | return url.replace(/^(?!(?:\w+?:)?\/\/)/, https ? 'https://' : 'http://');
|
13 | }
|