abp-filter-parser

    0.2.0 • Public • Published

    abp-filter-parser

    JavaScript Adblock Plus filter parser for lists like EasyList

    Build Status

    Parses filter rules as per:

    Usage

    Babel / ES6:

    import * as ABPFilterParser from 'abp-filter-parser.js';

    Node:

    let ABPFilterParser = require('abp-filter-parser');

    Primary API:

    let ABPFilterParser = require('abp-filter-parser');
    var fs = require('fs');
     
    let easyListTxt = fs.readFileSync('./test/data/easylist.txt', 'utf-8');
    let parsedFilterData = {};
    let urlToCheck = 'http://static.tumblr.com/dhqhfum/WgAn39721/cfh_header_banner_v2.jpg';
     
    // This is the site who's URLs are being checked, not the domain of the URL being checked.
    let currentPageDomain = 'slashdot.org';
     
    ABPFilterParser.parse(easyListTxt, parsedFilterData);
    // ABPFilterParser.parse(someOtherListOfFilters, parsedFilterData);
     
    if (ABPFilterParser.matches(parsedFilterData, urlToCheck, {
          domain: currentPageDomain,
          elementTypeMaskMap: ABPFilterParser.elementTypes.SCRIPT,
        })) {
      console.log('You should block this URL!');
    } else {
      console.log('You should NOT block this URL!');
    }

    Secondary APIs

    You probably won't need these directly, they are used by the parimary API above.

    • parseDomains
    • parseOptions
    • parseHTMLFilter
    • parseFilter
    • matchesFilter

    Keywords

    none

    Install

    npm i abp-filter-parser

    DownloadsWeekly Downloads

    58

    Version

    0.2.0

    License

    MPL-2.0

    Last publish

    Collaborators

    • brianbondy