mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: more refactor to the bun
This commit is contained in:
35
Build/lib/process-line.ts
Normal file
35
Build/lib/process-line.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
export const processLine = (line: string): string | null => {
|
||||
if (!line) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const line_0: string = line[0];
|
||||
|
||||
if (
|
||||
line_0 === '#'
|
||||
|| line_0 === ' '
|
||||
|| line_0 === '\r'
|
||||
|| line_0 === '\n'
|
||||
|| line_0 === '!'
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const trimmed: string = line.trim();
|
||||
if (trimmed === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return trimmed;
|
||||
};
|
||||
|
||||
export const processLineFromReadline = async (rl: AsyncGenerator<string>): Promise<string[]> => {
|
||||
const res: string[] = [];
|
||||
for await (const line of rl) {
|
||||
const l: string | null = processLine(line);
|
||||
if (l) {
|
||||
res.push(l);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
};
|
||||
Reference in New Issue
Block a user