vtils
Version:
一个面向业务的 JavaScript/TypeScript 实用程序库。
30 lines (27 loc) • 715 B
JavaScript
exports.__esModule = true;
exports.htmlToDocumentFragment = htmlToDocumentFragment;
exports.htmlToElement = htmlToElement;
// https://github.com/fregante/doma/blob/master/index.ts
/**
* 将 HTML 字符串转为 DocumentFragment。
*
* @param html HTML 字符串
*/
function htmlToDocumentFragment(html) {
if (html == null) {
return new DocumentFragment();
}
var template = document.createElement('template');
template.innerHTML = html;
return template.content;
}
/**
* 将 HTML 字符串转为 Element。
*
* @param html HTML 字符串
*/
function htmlToElement(html) {
var _ref;
return (_ref = htmlToDocumentFragment(html).firstElementChild) != null ? _ref : undefined;
}
;