process-line.ts 705 B

123456789101112131415161718192021222324252627282930313233343536
  1. export const processLine = (line: string): string | null => {
  2. if (!line) {
  3. return null;
  4. }
  5. const trimmed: string = line.trim();
  6. if (trimmed.length === 0) {
  7. return null;
  8. }
  9. const line_0: string = trimmed[0];
  10. if (
  11. line_0 === '#'
  12. || line_0 === ' '
  13. || line_0 === '\r'
  14. || line_0 === '\n'
  15. || line_0 === '!'
  16. || (line_0 === '/' && trimmed[1] === '/')
  17. ) {
  18. return null;
  19. }
  20. return trimmed;
  21. };
  22. export const processLineFromReadline = async (rl: AsyncIterable<string>): Promise<string[]> => {
  23. const res: string[] = [];
  24. for await (const line of rl) {
  25. const l: string | null = processLine(line);
  26. if (l) {
  27. res.push(l);
  28. }
  29. }
  30. return res;
  31. };