insert-html-content
Insert contents into an HTML of a response body
const createServer = ;const fetch = ;const insertHtmlContent = ; ;
Installation
npm install insert-html-content
API
const insertHtmlContent = ;
insertHtmlContent(response, content [, options])
response: http.ServerResponse
content: string
options: Object
If the media type of the response is text/html
, it inserts a given content into the response body as the first child of <body>
tag once, with increasing the value of content-length
header if necessary.
const createServer = ;const fetch = ;const injectBody = ; const html = Buffer;const inserted = '<h1>🏄</h1>'; ;
If the media type is not text/html
, or the response body has no <body>
tag, it does nothing.
options.tagName
Type: string
Default: 'body'
Change the insertion target to the given tag.
;
options.insertToEnd
Type: boolean
Default: false
When this option is true
, it inserts a content to the last child of the target tag instead.
Default:
existing contentinserted content
insertToEnd: true
:
inserted contentexisting content
class insertHtmlContent.InsertHtmlContent(contents [, options])
content: string
options: Object
Return: Function
Create a new insertHtmlContent
function with the fixed content
and options
. Use this class if a server will insert the same contents into every HTML response many times.
const InsertHtmlContent = ; const injectStyle = '<style>body {color: red}</style>';
License
ISC License © 2018 - 2019 Shinnosuke Watanabe