import { IExceptionDocumentation } from '../../interfaces' ; export default class MarkdownGenerator { static removeExceptionsWithoutCode ( exception ) { return exception . code !== undefined ; } static sortByCode ( a , b ) { return a . scope - b . scope || a . code - b . code ; } static groupExceptionsByScope ( acc , info ) { const { scope } = info ; const previousInfos = acc [ scope ] || [ ] ; const nextInfos = [ ... previousInfos , info ] ; const accumulated = { ... acc , [ scope ] : nextInfos } ; return accumulated ; } static generate ( loadedExceptions ) { const groupsOfInfosByCode = loadedExceptions . filter ( MarkdownGenerator . removeExceptionsWithoutCode ) . sort ( MarkdownGenerator . sortByCode ) . reduce ( MarkdownGenerator . groupExceptionsByScope , { } ) ; const markdownContent = Object . values ( groupsOfInfosByCode ) ; return markdownContent ; } }