本文整理匯總了TypeScript中jsdom.JSDOM.fragment方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript JSDOM.fragment方法的具體用法?TypeScript JSDOM.fragment怎麽用?TypeScript JSDOM.fragment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jsdom.JSDOM
的用法示例。
在下文中一共展示了JSDOM.fragment方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test_fragment
function test_fragment() {
const frag = JSDOM.fragment(`<p>Hello</p><p><strong>Hi!</strong>`);
frag.childNodes.length === 2;
frag.querySelector('strong')!.textContent = 'Why hello there!';
// etc.
}
示例2: test_fragment_serialization
function test_fragment_serialization() {
const frag = JSDOM.fragment(`<p>Hello</p>`);
if (frag instanceof Element) {
if (frag.firstChild instanceof Element) {
console.log(frag.firstChild.outerHTML); // logs "<p>Hello</p>"
}
}
}
示例3: fetchIDL
async function fetchIDL(source: IDLSource) {
const response = await fetch(source.url);
if (source.url.endsWith(".idl")) {
return { idl: await response.text() };
}
const dom = JSDOM.fragment(await response.text());
const elements = Array.from(dom.querySelectorAll(idlSelector))
.filter(el => {
if (el.parentElement && el.parentElement.classList.contains("example")) {
return false;
}
const previous = el.previousElementSibling;
if (!previous) {
return true;
}
return !previous.classList.contains("atrisk") && !previous.textContent!.includes("IDL Index");
});
if (!elements.length) {
throw new Error(`Found no IDL code from ${source.url}`);
}
const idl = elements.map(element => trimCommonIndentation(element.textContent!).trim()).join('\n\n');
const comments = processComments(dom);
return { idl, comments };
}
示例4: fragment
export function fragment(template: string): DocumentFragment {
return JSDOM.fragment(template);
}