MCPcopy
hub / github.com/SukkaW/Surge / processLine

Function processLine

Build/lib/process-line.ts:3–41  ·  view source on GitHub ↗
(line: string)

Source from the content-addressed store, hash-verified

1import { TransformStream } from 'node:stream/web';
2
3export 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
43export class ProcessLineStream extends TransformStream<string, string> {
44 // private __buf = '';

Callers 7

processFileFunction · 0.90
dedupeFileFunction · 0.90
parseGfwListFunction · 0.90
runAgainstSourceFileFunction · 0.90
transformMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected