1
2
3
4
5
6
7
8
9
10
11
// SPDX-License-Identifier: 0BSD
export function appendFragment(fragment: string, html: string) {
if (!fragment) return html;
let offset = Math.min(
html.lastIndexOf("</body>"),
html.lastIndexOf("</html>"),
);
if (offset === -1) offset = html.length;
return html.slice(0, offset) + fragment + html.slice(offset);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
March 8, 2024