Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
export function scriptTag(attr: Record<string, string> = {}, contents: string[] = []) {
const strContents = contents.join(" ");
// returns an array of attribute strings
const attrStrings = Object.entries(attr).map((kv) => {
const attrStr = `${kv[0]}="${kv[1]}"`;
return attrStr;
});
const attributes = attrStrings.join(" ");
return `<script ${attributes}>${strContents}</script>`;
}
October 23, 2023