import { CSSFormatter } from './CSSFormatter' ; import { ScriptFormatter } from './ScriptFormatter' ; /**
 * Helper class to format the code.
 */ export class CodeFormatter { param rawCSS public formatCSS ( rawCSS ) { let cssFormatter = new CSSFormatter ( ) ; return cssFormatter . css_beautify ( rawCSS , null ) ; } param rawScript public formatScript ( rawScript ) { let scriptFormatter = new ScriptFormatter ( ) ; return scriptFormatter . js_beautify ( rawScript , null ) ; } param rawXML public formatXML ( rawXML ) { let tab = '\t' ; let result = '' ; let indent = '' ; rawXML . split ( />\s*</ ) . forEach ( element => { if ( element . match ( /^\/\w/ ) ) { indent = indent . substring ( tab . length ) ; } result += indent + '<' + element + '>\r\n' ; if ( element . match ( /^<?\w[^>]*[^\/]$/ ) ) { indent += tab ; } } ) ; return result . substring ( 1 , result . length - 3 ) ; } param rawHTML public formatHTML ( rawHTML ) { return this . formatXML ( rawHTML ) ; } param rawJSON public formatJSON ( rawJSON ) { return JSON . stringify ( JSON . parse ( rawJSON ) , null , 2 ) ; } }