function extractProductAvailability()

in parsers/locations/about-locations-parser.js [36:66]


function extractProductAvailability(row) {

	const tHeader = row.querySelector("th");
	if (!tHeader) {
		console.error('Cannot extract product name');
		return;
	}

	let	product = tHeader.textContent.trim();

	// if product ends with a digit, remove it. (These are footnotes)
	while(product.match(/.*\d/) || product.match(/.*,/)) {
		product = product.slice(0, -1).trim();
	}

	const availability = [];
	const cells = row.querySelectorAll("td");
	if(cells.length === 0) {
		return;
	}
	for (const cell of cells) {
		// check if cell contains a <span> with aria-label="available"
		const available = cell.querySelector("span[aria-label='available']");
		if (available) {
			availability.push(true);
		} else {
			availability.push(false);
		}
	}
	return {product, availability};
}