npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@eyeo/abp2dnr

v1.1.1

Published

Adblock Plus filter list to DeclarativeNetRequest conversion

Downloads

75

Readme

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.