Last active
September 9, 2021 07:43
-
-
Save evenfrost/379bf44af216aea2a900345b558ffd89 to your computer and use it in GitHub Desktop.
Form TS interface from Zendesk API page
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 formInterface() { | |
const categoryName = document.querySelector('[class^="contentHeader__Container"] h1').textContent.slice(0, -1); | |
const table = document.querySelector('[class^="documentContent__DocumentContent"] [class^="renderToHtmlWithGarden__TableContainer"] table'); | |
const getTsType = zendeskType => { | |
let tsType = null; | |
switch (zendeskType) { | |
case 'integer': | |
tsType = 'number'; | |
break; | |
case 'date': | |
tsType = 'Date'; | |
break; | |
case 'array': | |
tsType = 'Array'; | |
break; | |
default: | |
tsType = zendeskType; | |
} | |
return tsType; | |
}; | |
const interface = categoryName; | |
const typesArray = [...table.querySelectorAll('tbody > tr')].map(row => { | |
const [name, type] = [...row.querySelectorAll('td')].slice(0, 2).map(el => el.textContent); | |
return `${name}: ${getTsType(type)};`; | |
}); | |
return `interface ${categoryName} {\n ${typesArray.join('\n ')}\n}`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment