mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
49 lines
833 B
JavaScript
49 lines
833 B
JavaScript
/* eslint-disable camelcase -- cache index access */
|
|
|
|
/**
|
|
* If line is commented out or empty, return null.
|
|
* Otherwise, return trimmed line.
|
|
*
|
|
* @param {string} line
|
|
*/
|
|
const processLine = (line) => {
|
|
if (!line) {
|
|
return null;
|
|
}
|
|
|
|
const line_0 = line[0];
|
|
|
|
if (
|
|
line_0 === '#'
|
|
|| line_0 === ' '
|
|
|| line_0 === '\r'
|
|
|| line_0 === '\n'
|
|
|| line_0 === '!'
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
const trimmed = line.trim();
|
|
if (trimmed === '') {
|
|
return null;
|
|
}
|
|
|
|
return trimmed;
|
|
};
|
|
module.exports.processLine = processLine;
|
|
|
|
/**
|
|
* @param {import('readline').ReadLine} rl
|
|
*/
|
|
module.exports.processLineFromReadline = async (rl) => {
|
|
/** @type {string[]} */
|
|
const res = [];
|
|
for await (const line of rl) {
|
|
const l = processLine(line);
|
|
if (l) {
|
|
res.push(l);
|
|
}
|
|
}
|
|
return res;
|
|
};
|