import { Observable , Subject } from 'rxjs' ; import { filter } from 'rxjs/operators' ; /**
 * Receives observable that emits strings, and returns a new observable
 * that also returns strings separated by delimiter.
 *
 * Input stream:
 *
 *     asdf.f -> df..aaa. -> dfsdf
 *
 * Output stream, assuming "." is used as delimiter:
 *
 *     asdf -> fdf -> aaa -> dfsdf
 *
 */ export const split = ( delimiter = '\n' ) => ( in$ ) : Observable < string > => { const out$ = new Subject < string > ( ) ; let startingText = '' ; in$ . subscribe ( ( chunk ) => { const messages = ( startingText + chunk ) . split ( delimiter ) ; messages . slice ( 0 , - 1 ) . forEach ( out$ . next . bind ( out$ ) ) ; startingText = messages . length ? messages [ messages . length - 1 ] : '' ; } , out$ . error . bind ( out$ ) , ( ) => { out$ . next ( startingText ) ; out$ . complete ( ) ; } ) ; return out$ . pipe ( filter < string > ( Boolean ) ) ; } ;