import { compact , flattenDeep , isString } from 'lodash' ; interface StartDeps { document : { title : string ; } ; } example example public export interface ChromeDocTitle { example param newTitle change ( newTitle ) : void ; /**
     * Resets the document title to it's initial value.
     * (meaning the one present in the title meta at application load.)
     */ reset ( ) : void ; } const defaultTitle = [ ] ; const titleSeparator = ' - ' ; internal export class DocTitleService { private document = { title : '' } ; private baseTitle = '' ; public start ( { document } ) { this . document = document ; this . baseTitle = document . title ; return { change : ( title ) => { this . applyTitle ( title ) ; } , reset : ( ) => { this . applyTitle ( defaultTitle ) ; } , } ; } private applyTitle ( title ) { this . document . title = this . render ( title ) ; } private render ( title ) { const parts = [ ... ( isString ( title ) ? [ title ] : title ) , this . baseTitle ] ; return compact ( flattenDeep ( parts ) ) . join ( titleSeparator ) ; } }