Skip to content

Instantly share code, notes, and snippets.

@fgarcia
Created June 23, 2022 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fgarcia/a5f4ccefd384d2865d3ece711a233efa to your computer and use it in GitHub Desktop.
Save fgarcia/a5f4ccefd384d2865d3ece711a233efa to your computer and use it in GitHub Desktop.
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