| 72 | } |
| 73 | |
| 74 | async filter(expression: string | RegExp) { |
| 75 | const result = new Array<string>(); |
| 76 | const stream = this.tee(); |
| 77 | if (expression instanceof RegExp) { |
| 78 | for await (const line of stream) { |
| 79 | const check = expression.exec(line); |
| 80 | if (check) { |
| 81 | result.push(check[1] || check[0]); |
| 82 | } |
| 83 | } |
| 84 | return result; |
| 85 | } |
| 86 | for await (const line of stream) { |
| 87 | if (line.includes(expression)) { |
| 88 | result.push(line); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return result; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Splits the iterator into two, and advances the new iterator to the line that matches the expression. |