Created
June 23, 2022 08:33
-
-
Save fgarcia/a5f4ccefd384d2865d3ece711a233efa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function toLines(s1: Observable<{ toString() }>) { | |
let lines$ = new Subject<string>() | |
let acu = '' | |
s1.subscribe({ | |
next: x => { | |
acu += x.toString() | |
if (!acu.includes('\n')) return | |
let lines = acu.split('\n') | |
let last = lines.pop() | |
lines.forEach(x => lines$.next(x)) | |
acu = last | |
}, | |
error: error => { | |
throw error | |
}, | |
complete: () => { | |
if (acu.length > 0) { | |
lines$.next(acu) | |
} | |
}, | |
}) | |
return lines$ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment