@igorskyflyer/adblock-filter-counter
v1.1.0
Published
🐲 A lightweight npm module for counting ad-block filter rules, ultra-simple, fast, and perfect for list maintainers, filter testers, and privacy tool developers.🦘
Maintainers
Readme
📃 Table of Contents
🤖 Features
- ⚡ Counts ad-block rules from strings or files instantly
- 🧠 Ignores comments and metadata for clean totals
- 🧼 Syntax-agnostic - no parser, no dependencies
- 📁 Reads UTF-8 files with a single call
- 🧪 Type-safe - returns exact rule count as number
- 🚫 Throws clear errors for invalid input or missing files
- 🧵 Works with EasyList, AdVoid, and custom filters
- 🧩 Ideal for audits, benchmarks, and list hygiene
- 🐇 Fast - handles tens of thousands of rules in milliseconds
- 🔒 No network, no fetch, no async - pure local logic
🕵🏼 Usage
Install it by executing any of the following, depending on your preferred package manager:
pnpm add @igorskyflyer/adblock-filter-counteryarn add @igorskyflyer/adblock-filter-counternpm i @igorskyflyer/adblock-filter-counter🤹🏼 API
countRules(rules: string): numberCounts ad-block filter rules found in the provided string.
rules - The ad-block filter string to count rules in.
Throws if the input is not a string.
Returns the number of filter rules.
countFileRules(path: PathLike): numberCounts ad-block filter rules found in the provided file.
path - The path to the file that contains the filter rules to count.
Throws if the file cannot be read or is not a valid UTF-8 string.
Returns the number of filter rules.
🗒️ Examples
index.ts
import { countFileRules, countRules } from '@igorskyflyer/adblock-filter-counter'
const total: number = countFileRules('./AdVoid.Full.txt')
console.log(`AdVoid.Full contains ${total} rules.`) // AdVoid.Full contains 7,916 rules.
const raw: string = `
||ads.example.com^
||tracker.net^
! this is a comment
##.ad-banner
`
const count: number = countRules(raw)
console.log(`Inline list contains ${count} rules.`) // Inline list contains 3 rules.📝 Changelog
📑 Read about the latest changes in the CHANGELOG.
🪪 License
Licensed under the MIT license.
💖 Support
🧬 Related
🧬 Meet Aria, an efficient ad-block filter list compiler, with many features that make your maintenance of ad-block filter lists a breeze! 🦖
@igorskyflyer/adblock-header-extract
✂️ An npm module that provides ways to extract header and metadata from an ad-block filter file. 📃
🥞 Removes HTML code from the given string. Can even extract text-only from the given an HTML string. ✨
@igorskyflyer/astro-saferesource
🎐 Adds CSP-compliant inline scripts and styles to Astro! 🎠
@igorskyflyer/astro-easynav-button
🧭 Add an easy-to-use navigational button (jump to top/bottom) to your Astro site. 🔼
👨🏻💻 Author
Created by Igor Dimitrijević (@igorskyflyer).
