process-line.ts 685 B

1234567891011121314151617181920212223242526272829303132333435
  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. ) {
  17. return null;
  18. }
  19. return trimmed;
  20. };
  21. export const processLineFromReadline = async (rl: AsyncGenerator<string> | ReadableStream<string>): Promise<string[]> => {
  22. const res: string[] = [];
  23. for await (const line of rl) {
  24. const l: string | null = processLine(line);
  25. if (l) {
  26. res.push(l);
  27. }
  28. }
  29. return res;
  30. };