<commit_before>export default function readData(image) {

	let img = image.dom.img;

	image.data = {
		img: img && {
			src: img.getAttribute('src'),
			srcset: parseSrcset(img.getAttribute('srcset')),
			sizes: parseSizes(img.getAttribute('sizes')),
		},
		sources: image.dom.sources.map(source => {
			return {
				srcset: parseSrcset(source.getAttribute('srcset')),
				sizes: parseSizes(source.getAttribute('sizes')),
				media: parseMedia(source.getAttribute('media')),
				type: source.getAttribute('type') || undefined,
			};
		}),
	};

	return image;

}
function parseSrcset(attribute) {
	if (!attribute) {
		return [];
	}
	return attribute.split(',').map(source => {
		let [src, descriptor] = source.trim().split(/\s+/);
		return {src, descriptor};
	});
}

function parseSizes(attribute) {
	if (!attribute) {
		return [];
	}
	return attribute.split(',').map(size => {
		size = size.trim();
		let media, pos;
		if ((pos = size.lastIndexOf(' ')) !== -1) {
			media = parseMedia(size.substr(0, pos).trim());
			size = size.substr(pos).trim();
		}
		return {size, media};
	});
}

function parseMedia(attribute) {
	if (!attribute) {
		return undefined;
	}
	let matches = attribute
		.trim()
		.toLowerCase()
		.match(/^\(\s*((?:max|min)-width):\s*([0-9a-z]+)\s*\)$/i);
	if (!matches) {
		return attribute.trim();
	}
	return {
		[matches[1]]: matches[2],
	};
}<commit_msg>Fix bug with sizes parsing for calc()<commit_after>export default function readData(image) {

	let img = image.dom.img;

	image.data = {
		img: img && {
			src: img.getAttribute('src'),
			srcset: parseSrcset(img.getAttribute('srcset')),
			sizes: parseSizes(img.getAttribute('sizes')),
		},
		sources: image.dom.sources.map(source => {
			return {
				srcset: parseSrcset(source.getAttribute('srcset')),
				sizes: parseSizes(source.getAttribute('sizes')),
				media: parseMedia(source.getAttribute('media')),
				type: source.getAttribute('type') || undefined,
			};
		}),
	};

	return image;

}
function parseSrcset(attribute) {
	if (!attribute) {
		return [];
	}
	return attribute.split(',').map(source => {
		let [src, descriptor] = source.trim().split(/\s+/);
		return {src, descriptor};
	});
}

function parseSizes(attribute) {
	if (!attribute) {
		return [];
	}
	return attribute.split(',').map(size => {
		size = size.trim();
		let media;
		size = size.replace(/^\(.+?\)\s+/, match => {
			media = parseMedia(match.trim());
			return '';
		});
		return {size, media};
	});
}

function parseMedia(attribute) {
	if (!attribute) {
		return undefined;
	}
	let matches = attribute
		.trim()
		.toLowerCase()
		.match(/^\(\s*((?:max|min)-width):\s*([0-9a-z]+)\s*\)$/i);
	if (!matches) {
		return attribute.trim();
	}
	return {
		[matches[1]]: matches[2],
	};
}
{'fraction_non_alphanumeric': 0.20818115412710006, 'fraction_numerical': 0.003652300949598247, 'mean_word_length': 3.8910714285714287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '484938', 'n_tokens_mistral': 1057, 'n_tokens_neox': 977, 'n_words': 176}