Skip to content

Instantly share code, notes, and snippets.

@evenfrost
Last active September 9, 2021 07:43
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 evenfrost/379bf44af216aea2a900345b558ffd89 to your computer and use it in GitHub Desktop.
Save evenfrost/379bf44af216aea2a900345b558ffd89 to your computer and use it in GitHub Desktop.
Form TS interface from Zendesk API page
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