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