eugeneware / eugeneware/replacestream
Does not work for `$`
- Dominant language
- JavaScript
- Stars
- 177
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to replace each newline with ``, and to also add `` to the very end. However if it ends with a newline I only want one ``.
I wrote a regular expression for this using $, however this does not seem supported.
Some sample code (TS):
```ts
(async function test() {
console.log('runnig test');
const text = `
first line
second line
third line`.trimStart();
let result = '';
const readStream = Readable
.from(text)
.pipe(replaceStream(/\s*[\n\r]+|$/g, ' '));
const writable = new Writable({
write(chunk: string) {
result += chunk;
}
});
readStream.pipe(writable);
await finished(readStream);
console.log('Done! Result:');
console.log('---')
console.log(result);
console.log('---')
})();
```
Contributor guide
Assessment
This issue has not been assessed yet.