All files / src/formatter formatterFactory.ts

100% Statements 8/8
100% Branches 2/2
100% Functions 1/1
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  1x 1x       4x   4x         4x 2x     4x       1x  
import { IFormat } from "./interface";
import { SimpleFormat } from "./formats/simple";
import { JsonFormat } from "./formats/json";
 
class FormatterFactory {
  public build(format: string): IFormat {
    let formatter: IFormat = new SimpleFormat();
 
    const formatMap: { [key: string]: IFormat } = {
      simple: new SimpleFormat(),
      json: new JsonFormat()
    };
 
    if (Object.keys(formatMap).includes(format)) {
      formatter = formatMap[format];
    }
 
    return formatter;
  }
}
 
export { FormatterFactory };