МС
Size: a a a
МС
МС
МС
DE
let el = document.getElementById('telegram-passport').parentElement
const code = []
let cls = ''
let comment = ''
while (el.nextElementSibling && el.nextElementSibling.tagName !== 'H3') {
if (el.nextElementSibling.tagName === 'H4') {
cls = `${cls}export type ${el.nextElementSibling.innerText}`
}
if (el.nextElementSibling.tagName === 'P') {
comment = comment + `/**${el.nextElementSibling.innerText.replace(/(.{1,72}\s)\s*?/g, '\n * $1')}\n */\n`
comment = comment.replace(/\n \*\/\n\/\*\*/g, '\n *')
}
if (el.nextElementSibling.tagName === 'TABLE') {
const keys = Array.from(el.nextElementSibling.querySelectorAll('tr:first-child td'))
.map((td) => td.innerText)
const values = Array.from(el.nextElementSibling.querySelectorAll('tr:not(:first-child) td'))
.map((td, idx) => [keys[idx % keys.length].toLowerCase(), td.innerText])
.reduce((acc, cur, idx) => {
acc[parseInt(idx / keys.length)] = acc[parseInt(idx / keys.length)] || {}
acc[parseInt(idx / keys.length)][cur[0]] = cur[1]
return acc
}, [])
cls += '\n{\n\n' + values.map((prop) => ` /**${prop.description.replace(/“|”/g, '`').replace(/(.{1,72}\s)\s*?/g, '\n * $1')}\n */\n ${prop.parameters || prop.field}: ${prop.type.replace(/Array of (\w+)/, '$1[]')};\n`).join('\n')
code.push(`${comment}${cls}\n}\n`)
cls = ''
comment = ''
}
el = el.nextElementSibling
}
console.log(code.join('\n'))
DE
DE
DE
DE
DE
МС
DE
DE
let el = document.getElementById('telegram-passport').parentElement
const code = []
let cls = ''
let comment = ''
while (el.nextElementSibling && el.nextElementSibling.tagName !== 'H3') {
if (el.nextElementSibling.tagName === 'H4') {
cls = `${cls}export type ${el.nextElementSibling.innerText}`
}
if (el.nextElementSibling.tagName === 'P') {
comment = comment + `/**${el.nextElementSibling.innerText.replace(/(.{1,72}\s)\s*?/g, '\n * $1')}\n */\n`
comment = comment.replace(/\n \*\/\n\/\*\*/g, '\n *')
}
if (el.nextElementSibling.tagName === 'TABLE') {
const keys = Array.from(el.nextElementSibling.querySelectorAll('tr:first-child td'))
.map((td) => td.innerText)
const values = Array.from(el.nextElementSibling.querySelectorAll('tr:not(:first-child) td'))
.map((td, idx) => [keys[idx % keys.length].toLowerCase(), td.innerText])
.reduce((acc, cur, idx) => {
acc[parseInt(idx / keys.length)] = acc[parseInt(idx / keys.length)] || {}
acc[parseInt(idx / keys.length)][cur[0]] = cur[1]
return acc
}, [])
cls += '\n{\n\n' + values.map((prop) => ` /**${prop.description.replace(/“|”/g, '`').replace(/(.{1,72}\s)\s*?/g, '\n * $1')}\n */\n ${prop.parameters || prop.field}: ${prop.type.replace(/Array of (\w+)/, '$1[]')};\n`).join('\n')
code.push(`${comment}${cls}\n}\n`)
cls = ''
comment = ''
}
el = el.nextElementSibling
}
console.log(code.join('\n'))
МС
DE
DE
DE
N
МС