import { HelmetData } from 'react-helmet' ; const RE_HTML_ATTR = /<html[^>]*>/ ; const RE_BODY_ATTR = /<body[^>]*>/ ; const RE_LAST_IN_HEAD = /<\/head>/ ; const RE_TITLE = /<title[^>]*>([\s\S\n\r]*?)<\/title>/ ; export default function helmet ( content , helmetData ) { let result = content ; const bodyAttributes = helmetData . bodyAttributes . toString ( ) ; if ( bodyAttributes ) { result = result . replace ( RE_BODY_ATTR , `<body ${ bodyAttributes }>` ) ; } const htmlAttributes = helmetData . htmlAttributes . toString ( ) ; if ( htmlAttributes ) { result = result . replace ( RE_HTML_ATTR , `<html ${ htmlAttributes }>` ) ; } const base = helmetData . base . toString ( ) ; const link = helmetData . link . toString ( ) ; const meta = helmetData . meta . toString ( ) ; const noscript = helmetData . noscript . toString ( ) ; const script = helmetData . script . toString ( ) ; const style = helmetData . style . toString ( ) ; const title = helmetData . title . toString ( ) ; const hasHelmetTitle = RE_TITLE . exec ( title ) ; if ( hasHelmetTitle ?. [ 1 ] ) { result = result . replace ( RE_TITLE , title ) ; } return result . replace ( RE_LAST_IN_HEAD , `
    ${ base }
    ${ link }
    ${ meta }
    ${ noscript }
    ${ script }
    ${ style }
    ${ title }
    </head>
  ` ) ; }