import { inject , injectable } from 'inversify' ; import json5 from 'json5' ; import { BaselineSchemaValidator } from './baseline-schema' ; import { BaselineFileContent } from './baseline-types' ; @ injectable ( ) export class BaselineFileFormatter { constructor ( @ inject ( BaselineSchemaValidator ) private readonly baselineSchemaValidator ) { } public parse ( rawBaselineContent ) { const unvalidatedContent = json5 . parse ( rawBaselineContent ) ; return this . baselineSchemaValidator . validate ( unvalidatedContent ) ; } public format ( baselineContent ) { return json5 . stringify ( baselineContent , null , 2 ) ; } }