function isValidResource ( resource ) { return ( resource . startsWith ( "https://" ) || resource . startsWith ( "http://" ) || resource . startsWith ( "//" ) ) ; } param { string } line returns { ( string | undefined ) } function getCssResource ( line ) { const cssRegex = /<link[^]*href="(.*\.css)"/ ; const match = line . match ( cssRegex ) ; if ( match && match [ 1 ] ) { const resource = match [ 1 ] ; if ( ! isValidResource ( resource ) ) { return ; } return resource ; } } param { string } line returns { ( string | undefined ) } function getJsResource ( line ) { const jsRegex = /<script[^]*src="(.*)"/ ; const match = line . match ( jsRegex ) ; if ( match && match [ 1 ] ) { const resource = match [ 1 ] ; if ( ! isValidResource ( resource ) ) { return ; } return resource ; } } param { string } html function getExternalResources ( html ) { return html . split ( "\n" ) . map ( ( line ) => getCssResource ( line ) || getJsResource ( line ) ) . filter ( ( x ) => x ) ; } param { string } html function getBodyContent ( html ) { const bodyRegex = /<body>([^]*)<\/body>/ ; const match = html . match ( bodyRegex ) ; if ( match ) { return match [ 1 ] ; } } export param { string } html export default function parseHTML ( html ) { const externalResources = getExternalResources ( html ) ; const bodyContent = getBodyContent ( html ) ; return { body : bodyContent || '<div id="root"></div>' , externalResources , } ; }