const RegList = { before : { head : '<head>' , body : '<body>' , } , after : { head : '</head>' , body : '</body>' , } , } ; class TemplateAPI { private content : string ; constructor ( content ) { this . content = content ; } public get ( ) { return this . content ; } public set ( content ) { this . content = content ; } public prependHead ( fragment ) { const { head } = RegList . before ; return this . replace ( head , `${ head }${ fragment }` ) ; } public appendHead ( fragment ) { const { head } = RegList . after ; return this . replace ( head , `${ fragment }${ head }` ) ; } public prependBody ( fragment ) { const { body } = RegList . before ; return this . replace ( body , `${ body }${ fragment }` ) ; } public appendBody ( fragment ) { const { body } = RegList . after ; return this . replace ( body , `${ fragment }${ body }` ) ; } public replace ( reg , text ) { this . content = this . content . replace ( reg , text ) ; return this ; } } export const createTemplateAPI = ( content ) => new TemplateAPI ( content ) ;