Skip to content

Instantly share code, notes, and snippets.

@rviscomi
Created May 4, 2017 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rviscomi/31916a648679b64532d3612356807792 to your computer and use it in GitHub Desktop.
Save rviscomi/31916a648679b64532d3612356807792 to your computer and use it in GitHub Desktop.
parseReleaseHistory = (table) => {
const rows = Array.from(table.querySelectorAll('tbody tr'));
return rows.reduce((dates, row) => {
let version = getVersion(row.querySelector('td:nth-child(1)').innerText);
let date = getDate(row.querySelector('td:nth-child(2)').innerText);
dates.push({version, date});
const patch = row.querySelector('td:nth-child(3)').innerText;
if (patch) {
let _;
[_, version, date] = patch.match(/([\d\.]+) \((.*)\)/)
version = getVersion(version);
date = getDate(date);
dates.push({version, date});
}
return dates;
}, []);
};
getVersion = (versionStr) => versionStr.match(/\d+\.?\d+\.?\d*/)[0];
getDate = (dateStr) => {
const d = new Date(dateStr.replace(/\u00A0/g, ' '));
return `${d.getFullYear()}-${d.getMonth()+1}-${d.getDate()}`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment