generated from shgysk8zer0/npm-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml.js
32 lines (26 loc) · 1.1 KB
/
html.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { sanitizer } from '@aegisjsproject/sanitizer/config/base.js';
import { stringify } from './utils.js';
export function createHTMLParser(config = sanitizer, { mapper = stringify } = {}) {
return (strings, ...values) => {
const frag = document.createDocumentFragment();
const tmp = document.createElement('div');
tmp.setHTML(String.raw(strings, ...values.map(mapper)).trim(), config);
frag.append(...tmp.childNodes);
return frag;
};
}
export const html = createHTMLParser(sanitizer, { mapper: stringify });
export function htmlUnsafe(strings, ...values) {
const frag = document.createDocumentFragment();
const tmp = document.createElement('div');
tmp.setHTMLUnsafe(String.raw(strings, ...values.map(stringify)).trim());
frag.append(...tmp.childNodes);
return frag;
}
export const el = (...args) => html.apply(null, args).firstElementChild;
export function doc(strings, ...values) {
return Document.parseHTML(String.raw(strings, ...values.map(stringify)), sanitizer);
}
export function docUnsafe(strings, ...values) {
return Document.parseHTMLUnsafe(String.raw(strings, ...values.map(stringify)));
}