(line: string)
| 1 | import { TransformStream } from 'node:stream/web'; |
| 2 | |
| 3 | export function processLine(line: string): string | null { |
| 4 | const trimmed: string = line.trim(); |
| 5 | if (trimmed.length === 0) { |
| 6 | return null; |
| 7 | } |
| 8 | |
| 9 | const line_0 = trimmed.charCodeAt(0); |
| 10 | |
| 11 | if ( |
| 12 | // line_0 === 32 /** [space] */ |
| 13 | // || line_0 === 13 /** \r */ |
| 14 | // || line_0 === 10 /** \n */ |
| 15 | line_0 === 33 /** ! */ |
| 16 | || (line_0 === 47 /** / */ && trimmed.charCodeAt(1) === 47 /** / */) |
| 17 | ) { |
| 18 | return null; |
| 19 | } |
| 20 | |
| 21 | if (line_0 === 35 /** # */) { |
| 22 | if (trimmed.charCodeAt(1) !== 35 /** # */) { |
| 23 | // # Comment |
| 24 | // AdGuard Rule like #@.not_ad |
| 25 | return null; |
| 26 | } |
| 27 | if (trimmed.charCodeAt(2) === 35 /** # */ && trimmed.charCodeAt(3) === 35 /** # */) { |
| 28 | // ################## EOF ################## |
| 29 | return null; |
| 30 | } |
| 31 | /** |
| 32 | * AdGuard Filter can be: |
| 33 | * |
| 34 | * ##.class |
| 35 | * ##tag.class |
| 36 | * ###id |
| 37 | */ |
| 38 | } |
| 39 | |
| 40 | return trimmed; |
| 41 | } |
| 42 | |
| 43 | export class ProcessLineStream extends TransformStream<string, string> { |
| 44 | // private __buf = ''; |
no outgoing calls
no test coverage detected