export interface IStrategy { name : string ; } export class Extractor { public strategies : IStrategy [ ] ; protected enabledStrategies : IStrategy [ ] ; constructor ( ) { this . strategies = [ ] ; } public enableStrategies ( strategiesToEnable ) { this . enabledStrategies = this . strategies . filter ( strategy => { if ( strategiesToEnable . find ( _ => _ === strategy . name ) ) { const constructor = strategy . constructor ; return new constructor ( ) ; } } ) ; } public registerStrategy ( strategy ) { if ( ! this . has ( strategy ) ) { this . strategies . push ( strategy ) ; } } public has ( strategy ) { if ( typeof strategy === 'string' ) { return this . strategies . some ( _ => _ . name === strategy ) ; } return this . strategies . some ( _ => _ . name === strategy . name ) ; } public get ( strategy ) { if ( this . has ( strategy ) === false ) { return null ; } return this . strategies . find ( _ => _ . name === strategy ) ; } }