1.1.1 • Published 1 year ago

@eyeo/abp2dnr v1.1.1

Weekly downloads
-
License
GPL-3.0
Repository
gitlab
Last release
1 year ago

abp2dnr

npm

This is a script to convert Adblock Plus filter lists to chrome.declarativeNetRequest rulesets.

API docs are available at https://eyeo.gitlab.io/adblockplus/abc/abp2dnr/.

Requirements

Before you begin, make sure to install:

After these prerequisites are met, you can add abp2dnr to your project with npm install.

Installation

abp2dnr is available as a NPM module: @eyeo/abp2dnr.

npm install --save @eyeo/abp2dnr

Usage

Command line interface

abp2dnr can be called on the command line. When you do, it will accept a filter list on stdin and print a DNR ruleset to stdout.

cat easylist.txt | npx @eyeo/abp2dnr > ruleset.json

API

abp2dnr can also be used in a script. This exposes the function convertFilter, which converts a single filter text into one or more DNR rule. Note that, unlike the CLI script, these rules do not have IDs, so assigning IDs and assembling into a ruleset is up to you.

import {convertFilter} from "@eyeo/abp2dnr";

let filters = [
  "-popup-ad."
];

let nextId = 1;
let ruleset = [];

for (let filter of filters)
{
  for (let rule of await convertFilter(filter))
  {
    rule.id = nextId++;
    ruleset.push(rule);
  }
}

console.log(JSON.stringify(ruleset));

You can also use it to just validate the Regular Expressions that can appear in filter texts, to ensure that they will work when used in DNR rules.

import {isRegexSupported} from "@eyeo/abp2dnr";

let validRegexSupportedResult = isRegexSupported({
  regex: "[a-z0-9]+",
  isCaseSensitive: false,
  requireCapturing: false
});

console.log(validRegexSupportedResult);
// { isSupported: true }


let invalidRegexSupportedResult = isRegexSupported({
  regex: "[a-z0-9]{1000,}",
  isCaseSensitive: false,
  requireCapturing: false
});

console.log(invalidRegexSupportedResult);
// { isSupported: false, reason: 'memoryLimitExceeded' }

Contributing / Development

Documentation on how to work with abp2dnr as a developer is in CONTRIBUTING.md.

Other resources

Chromium has a Chromium's built-in filter list converter, however it appears that this has not been kept up to date with changes to the DNR rule syntax and defaults.

1.1.1

1 year ago

1.1.0

2 years ago

1.0.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

4 years ago