Swiftpack.co - Package - AdguardTeam/SafariConverterLib

Swift Safari Converter

Content Blocker converter swift code

Safari Content Blocker

Converts filter rules in AdGuard format to the format supported by Safari.

  • https://webkit.org/blog/3476/content-blockers-first-look/

How to build:

    swift build


    swift test

How to use converter:

    let result: ConversionResult? = ContentBlockerConverter.convertArray(
        rules: [String], limit: Int = 0, optimize: Bool = false, advancedBlocking: Bool = false

The result contains following properties:

  • totalConvertedCount: length of content blocker
  • convertedCount: length after reducing to limit if provided
  • errorsCount: errors count
  • overLimit: is limit exceeded flag
  • converted: json string of content blocker rules
  • advancedBlocking: json string of advanced blocking rules

How to use converter from command line:

    ./ConverterTool -limit=0 -optimize=true -advancedBlocking=false <<STDIN -o other --options

The tool then reads stdin line by line for rule until an empty line.

How to release on Github

Push a new tag in v*.*.* format, then provided github action is intended to build and publish new release with an asset binary.

Supported AdGuard rules types:

Basic content blocker format:

  • Elemhide rules (##)
  • Elemhide exceptions
  • Url blocking rules
  • Url blocking exceptions

Extended Advanced blocking types:

  • Script rules (#%#)
  • Script rules exceptions
  • Extended css elemhide rules (##)
  • Scriptlet rules (#%#//scriptlet)
  • Scriptlet rules exceptions

Third-party dependencies

  • Punycode (https://github.com/gumob/PunycodeSwift.git)


Stars: 0


Used By

Total: 0


v1.0.1 - 2020-10-20 12:48:53

  • Feature Request: Support uBO's filter rules: #1

v1.0.0 - 2020-10-16 14:44:18

Performance is greatly improved

v0.1.1 - 2020-09-24 13:42:10

  • Added log message

v0.1.0 - 2020-09-23 15:10:07

Converter binary