src/utils.js
/**
 * Load HTML content to Cheerio and process base tag,
 * return a object contain Cheerio object and new base url.
 *
 * @param {string} baseUrl
 * @param {string} text
 * @return {{CheerioStatic|string}}
 */
Load HTML content to Cheerio and process base tag,
return a object contain Cheerio object and new base url.


Load HTML content to Cheerio and process base tag return a object contain Cheerio object and new base url .
function loadTextToCheerio(baseUrl, text) {
	[['first argument (for base URL)', baseUrl], ['second argument (for HTML text)', text]].forEach(ensureValueIsNonEmptyStringIfExist);
	baseUrl = normalizeUrl(baseUrl);
	const $ = cheerio.load(text, {
		decodeEntities: false
	});
	let baseUsed = false;
	$('base').each((_, elm) => {
		const el = $(elm);
		const href = decodeHTML(el.attr('href'));
		if (!baseUsed && href) {
			baseUrl = urlResolve(baseUrl + '/', href);
			baseUsed = true;
		}
	});
	return {
		baseUrl,
		$
	};
}
function loadTextToCheerio ( baseUrl , text ) { [ [ 'first argument (for base URL)' , baseUrl ] , [ 'second argument (for HTML text)' , text ] ] . forEach ( ensureValueIsNonEmptyStringIfExist ) ; baseUrl = normalizeUrl ( baseUrl ) ; const $ = cheerio . load ( text , { decodeEntities : false } ) ; let baseUsed = false ; $ ( 'base' ) . each ( ( _ , elm ) => { const el = $ ( elm ) ; const href = decodeHTML ( el . attr ( 'href' ) ) ; if ( ! baseUsed && href ) { baseUrl = urlResolve ( baseUrl + '/' , href ) ; baseUsed = true ; } } ) ; return { baseUrl , $ } ; }
Load HTML content to Cheerio and process base tag,
 return a object contain Cheerio object and new base url.
Load HTML content to Cheerio and process base tag return a object contain Cheerio object and new base url .
// only the first href value are used // see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base#Usage_notes