Created
October 24, 2023 04:05
-
-
Save CMessinides/b5648daf2e742de2c70675e637440ab8 to your computer and use it in GitHub Desktop.
Parse the type table on https://utopia.fyi into a JS object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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