Skip to content

Instantly share code, notes, and snippets.

@CMessinides
Created October 24, 2023 04:05
Show Gist options
  • Save CMessinides/b5648daf2e742de2c70675e637440ab8 to your computer and use it in GitHub Desktop.
Save CMessinides/b5648daf2e742de2c70675e637440ab8 to your computer and use it in GitHub Desktop.
Parse the type table on https://utopia.fyi into a JS object
function parseTable() {
let rows = $$('.font-table tbody tr')
let step = row => row.querySelector('td:nth-of-type(1) strong')
let min = row => row.querySelector('td:nth-of-type(2)')
let max = row => row.querySelector('td:nth-of-type(3)')
let textContent = cell => cell.textContent
let toFloat = text => parseFloat(text, 10)
let round = number => Math.round(number)
let extractStep = pipe(step, textContent)
let textToRoundNumber = pipe(textContent, toFloat, round)
let extractMin = pipe(min, textToRoundNumber)
let extractMax = pipe(max, textToRoundNumber)
let toObj = row => ({
name: extractStep(row),
min: extractMin(row),
max: extractMax(row)
})
return [...rows].map(toObj)
}
parseTable();
// --- Utils
function pipe(...fns) {
return (value) => {
return fns.reduce((acc, fn) => fn(acc), value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment