UNPKG

locusbuilder-utility

Version:

Locusbuilder Utility server for asset scraping and processing

48 lines (36 loc) 1.25 kB
/** * Optimizer.js * * Optimizer is a function parser that loads a html parsed site through Cheerio to allow for multiple asset targetting * @author Richard Abear <owchzzz@gmail.com> * * */ // Disable jshint for async programming // jshint ignore: start const cheerio = require('cheerio'); module.exports = async (opts) => { let content = opts.content; let $ = cheerio.load(content); // function declarations let getAttr = (q) => { return $(this).attr(q) } return { 'content': $, findAll: async (opts) => { var self = this; let results = []; // Define the search parameter let searchParam = ( opts.search !== undefined ) ? opts.search : opts; let searchAttr = ( opts.searchattr !== undefined ) ? opts.searchattr : ''; await $('body').find(searchParam).each(function(i, elem) { let element = $(this).attr(searchAttr); // bind functions to element getAttr.bind(element); results.push(element) }); return results; }, } }