Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eyeo/abp2dnr

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eyeo/abp2dnr

Adblock Plus filter list to DeclarativeNetRequest conversion

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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.

FAQs

Package last updated on 12 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc