I've been working a lot with Cheerio and tables. Say I have used Cheerio to select a table row, and then get all the tds, and want to grab text out of some of them.
var tds = tableRow.children('td');
Yes, to get text from the nth td I can go
tds.eq(n).text();
but that requires an (unnecessary, looking at the code) .make() and object allocation. So, in perhaps a bit of over optimization, I've been doing
$.text(tds[n].children);
Which works fine, but it is extra typing and requires "inner knowldege" of the .children field. I'd prefer to use something like:
$text(tds[n]);
Now, tds[n] does not have a .length field, so you'd have to slightly modify static.js. I think that doing
var text = exports.text = function(elems) {
if (!elems) return '';
if (!elems.length) return text(elems.children);
would do the trick? But you could implement how you prefer...
I've been working a lot with Cheerio and tables. Say I have used Cheerio to select a table row, and then get all the tds, and want to grab text out of some of them.
var tds = tableRow.children('td');Yes, to get text from the nth td I can go
tds.eq(n).text();but that requires an (unnecessary, looking at the code) .make() and object allocation. So, in perhaps a bit of over optimization, I've been doing
$.text(tds[n].children);Which works fine, but it is extra typing and requires "inner knowldege" of the .children field. I'd prefer to use something like:
$text(tds[n]);Now, tds[n] does not have a .length field, so you'd have to slightly modify static.js. I think that doing
would do the trick? But you could implement how you prefer...