import Adapter from "../Adapter" ; export type Logger = ( data : string ) => void ; export default class Console extends Adapter { private logger : Logger ; private numbersPerLine : number ; constructor ( logger = console . log , numbersPerLine = 16 ) { super ( ) ; this . logger = logger ; this . numbersPerLine = numbersPerLine ; } public async open ( ) { return ; } public async write ( data ) { const regex = new RegExp ( `(.{${ this . numbersPerLine * 3 }})` , "g" ) ; const dataString = this . toHexString ( data ) ; this . logger ( dataString . replace ( /(.{2})/g , "$1 " ) . replace ( regex , "$1\n" ) ) ; return ; } public async close ( ) { return ; } private toHexString ( byteArray ) { return Array . from ( byteArray , ( byte ) => ( "0" + byte . toString ( 16 ) ) . slice ( - 2 ) ) . join ( "" ) ; } }