utilvo-shield-filters
Zero-dependency JavaScript, TypeScript, Python, and Go parser for Adblock Plus 2.0 ([Adblock Plus 2.0]) and uBlock Origin static network filter rules.
Features
- Parse standard
||domain^$third-party,domain=~example.comnetwork rules - Extract target hostnames,
$third-partymodifiers, and excluded context domains - Fast parent-domain suffix matching (
Set-backed lookup) for hostname verification - Built-in fetcher for the
utilvo-shield-filters.txtblocklist
Installation
Node.js
npm install utilvo-shield-filters
const { parseAbpRule, isHostBlocked, fetchFilterHosts } = require("utilvo-shield-filters");
// Parse a single rule
const rule = parseAbpRule("||01counter.com^$third-party,domain=~youtube.com");
// => { domain: '01counter.com', thirdParty: true, excludedDomains: ['youtube.com'] }
// Match a hostname against a Set of rules
const blocked = new Set(["01counter.com"]);
console.log(isHostBlocked("tracker.01counter.com", blocked)); // true
Python
pip install utilvo-shield-filters
from utilvo_shield_filters import parse_abp_rule, is_host_blocked
rule = parse_abp_rule("||01counter.com^$third-party,domain=~youtube.com")
print(rule)
# {'domain': '01counter.com', 'third_party': True, 'excluded_domains': ['youtube.com']}
blocked = {"01counter.com"}
print(is_host_blocked("sub.01counter.com", blocked)) # True
Go
go get github.com/utilvo/utilvo-shield-filters@latest
package main
import (
"fmt"
shieldfilters "github.com/utilvo/utilvo-shield-filters"
)
func main() {
domain, ok := shieldfilters.ParseAbpDomain("||01counter.com^$third-party")
if ok {
fmt.Println(domain) // 01counter.com
}
}
API Reference
parseAbpRule(line)/parse_abp_rule(line)/ParseAbpDomain(line): Parses a single ABP 2.0 rule line and returns the normalized lowercase domain and rule options. Returnsnull/Nonefor comments (!), headers ([Adblock Plus 2.0]), or cosmetic filters.isHostBlocked(hostname, blockedSet)/is_host_blocked(hostname, blocked_set): Checks whetherhostnameor any of its parent registrable labels exist inblockedSet.fetchFilterHosts(url?)/fetch_filter_hosts(url?): Downloads and parses a remote ABP filter list into aSetof domain strings.
License
Code is licensed under the MIT License. Filter list rules are licensed under CC BY-SA 4.0.
Metadata
Release files for utilvo-shield-filters 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| utilvo_shield_filters-1.0.0.tar.gz | 4.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| utilvo_shield_filters-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.1 kB
Release files / utilvo_shield_filters-1.0.0.tar.gz
| Download URL | utilvo_shield_filters-1.0.0.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ebb604fdb3f5db1ecf6271f84edef95646c7f02f47561299be2f4ed6f9bf0c41
|
|
BLAKE2b-256 checksum How to use checksums |
30b7aa84cc4efe590e865ad6ee3339e306b7de11aca6b34ddc8b59b0dc5804bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.10
|
Release files / utilvo_shield_filters-1.0.0-py3-none-any.whl
| Download URL | utilvo_shield_filters-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d90015babb36d2928242bccc15671cba605cf35d890595faa2034f3f4a701303
|
|
BLAKE2b-256 checksum How to use checksums |
29f22942f32d04540af24b8d9cd97ae7abd7db396912d748bbcca85073a7a963
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.10
|
Security for utilvo-shield-filters 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.