It receives such html:
text = `<b>AAA</b>
<random fb="2000"/>
<i>BBB</i>
<random fb="9000"/>
CCC
<random fb="2000"/>
DDD
<img src=""/>`
I am trying to achieve this effect:
result = [
{fb: null, html: '<b>AAA</b>'},
{fb:'2000',html: '<i>BBB</i>'},
{fb:'9000',html: 'CCC'},
{fb:'2000',html: 'DDD'},
{fb: null, html: ' <img src=""/>'}
]
I try, but its not working
import { get } from 'lodash';
const $ = cheerio.load(text);
const $random = $('random');
const elements = $random.map((i, item) => {
const { attribs, next } = item;
const getFB = attribs.fb.trim();
const data= get(next, 'data', null);
const message = { html: data && data.trim() };
const fb = { fb: Number(getFB) };
return Object.assign({}, fb, message);
}).get();
elements = [
{fb:2000, html: 'BBB'},
{fb:9000,html: 'CCC'},
{fb:2000,html: 'DDD'}]