summaryrefslogtreecommitdiff
path: root/bin/wiki/ImportarDesdeURL/node_modules/prepend-http/index.js
blob: 82b3a6b27a5d5f058e1648eefcbca6d9c0f218d6 (plain)
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://');
};