export class BufferedSearch { terms : { [ index ] : { buffer : string ; matched : boolean ; } ; } = { } ; term ( term , string ) { if ( ! this . terms [ term ] ) { this . terms [ term ] = { buffer : '' , matched : false } ; } else if ( this . terms [ term ] . matched ) { return true ; } this . terms [ term ] . buffer += string . replace ( /\s+/g , '' ) ; let search = '' ; const characters = term . split ( '' ) ; for ( let i = 0 ; i < characters . length ; i ++ ) { search += characters [ i ] ; if ( search . length > this . terms [ term ] . buffer . length ) { return false ; } const index = this . terms [ term ] . buffer . indexOf ( search ) ; if ( index === - 1 ) { this . terms [ term ] . buffer = '' ; this . terms [ term ] . matched = false ; return false ; } else if ( index > 0 ) { this . terms [ term ] . buffer = this . terms [ term ] . buffer . substring ( index ) ; } } return true ; } }