24 lines
509 B
JavaScript
24 lines
509 B
JavaScript
const getAttributes = (elements) => {
|
|
const ret =
|
|
elements
|
|
.reduce(
|
|
((current, { type, name, elements }) => ({
|
|
...current,
|
|
...type === 'element' && elements && {
|
|
[name]: elements
|
|
.find(
|
|
({
|
|
type,
|
|
}) =>
|
|
type === 'text'
|
|
)?.text || getAttributes(elements),
|
|
}
|
|
})
|
|
),
|
|
{},
|
|
)
|
|
return ret
|
|
}
|
|
|
|
export default getAttributes
|