• File: index.js
  • Full Path: /var/www/nodejs/daily_store_reports_nodejs/node_modules/prepend-http/index.js
  • Date Modified: 02/04/2023 9:31 PM
  • File size: 387 bytes
  • MIME-type: text/plain
  • Charset: utf-8
'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://');
};