import Color from './../color' ; import { IColorStrategy } from '../color-extractor' ; import { LineExtraction , DocumentLine } from '../../util/color-util' ; type RegexpResultExtractor = ( match : RegExpExecArray ) => Color ; export default class ColorStrategy implements IColorStrategy { constructor ( public name , private REGEXP , private REGEXP_ONE , private colorFromRegexp ) { } async extractColors ( fileLines ) { return fileLines . map ( ( { line , text } ) => { let match = null ; const colors = [ ] ; while ( ( match = this . REGEXP . exec ( text ) ) !== null ) { const color = this . colorFromRegexp ( match ) ; if ( color ) { colors . push ( color ) ; } } return { line , colors } ; } ) ; } extractColor ( text ) { const match = this . REGEXP_ONE . exec ( text ) ; if ( match ) { return this . colorFromRegexp ( match ) ; } return null ; } }