import { injectable } from 'inversify' ; import { padStart } from 'lodash' ; @ injectable ( ) export class ReportNameGeneratorBuilder { public getDateSegment ( scanDate ) { return `${ scanDate . getFullYear ( ) }${ this . padStartWithZero ( scanDate . getMonth ( ) + 1 , 2 ) }${ this . padStartWithZero ( scanDate . getDate ( ) , 2 ) }` ; } public getTitleSegment ( pageTitle ) { return Array . from ( pageTitle ) . filter ( this . isValidCharForTitle ) . slice ( 0 , 20 ) . join ( '' ) ; } public getTimeSegment ( scanDate ) { return ( this . padStartWithZero ( scanDate . getHours ( ) , 2 ) + this . padStartWithZero ( scanDate . getMinutes ( ) , 2 ) + this . padStartWithZero ( scanDate . getSeconds ( ) , 2 ) ) ; } private padStartWithZero ( num , digits ) { return padStart ( num . toString ( ) , digits , '0' ) ; } private isValidCharForTitle ( character ) { return /[A-Za-z0-9]/ . test ( character ) ; } }