@stringsync/vexml
Version:
MusicXML to Vexflow
28 lines (27 loc) • 798 B
JavaScript
import { DEFAULT_CONFIG } from '../config';
import { Stopwatch } from '../debug';
/**
* A formatter that tracks how long its child formatter takes to format a document.
*/
export class MonitoredFormatter {
formatter;
config;
log;
constructor(formatter, logger, opts) {
this.formatter = formatter;
this.config = { ...DEFAULT_CONFIG, ...opts?.config };
this.log = logger;
}
format(document) {
const stopwatch = Stopwatch.start();
const formatted = this.formatter.format(document);
const lap = stopwatch.lap();
if (lap < 1) {
this.log.info(`formatted score in <1ms`);
}
else {
this.log.info(`formatted score in ${Math.round(lap)}ms`);
}
return formatted;
}
}