Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work for $ #44

Open
timvandam opened this issue Jul 18, 2022 · 0 comments
Open

Does not work for $ #44

timvandam opened this issue Jul 18, 2022 · 0 comments

Comments

@timvandam
Copy link

timvandam commented Jul 18, 2022

I am trying to replace each newline with </s>, and to also add </s> to the very end. However if it ends with a newline I only want one </s>.

I wrote a regular expression for this using $, however this does not seem supported.

Some sample code (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, ' </s>'));
    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('---')
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant