Skip to content

Issue 7360 - Add recommendations module

Manish Jethani requested to merge skipintro/adblockpluscore:recommendations into next

This patch adds a lib/recommendations.js module containing a single *recommendations() generator function. The objects yielded are immutable so they do not affect the underlying data. The unit tests also contain some much needed validation of the values, since they come ultimately from a source foreign to the Core module.

Here is an example of how to use it:

let {Subscription} = require("subscriptionClasses");
let {recommendations} = require("recommendations");
let {filterStorage} = require("filterStorage");

for (let {type, languages, title, url, homepage} of recommendations())
{
  if (type == "ads" && languages.includes("en"))
  {
    let subscription = Subscription.fromURL(url);
    subscription.title = title;
    subscription.url = url;
    subscription.homepage = homepage;

    filterStorage.addSubscription(subscription);
  }
}

Please refer to the JSDoc.

PS: The unit tests may seem a bit overdone, but we should use immutable objects as much as possible, and we likely will end up sharing some of this code across test files in the future.

Edited by Manish Jethani

Merge request reports