百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

doma

> 编程语言
开源

将 HTML 字符串解析为 `DocumentFragment` 或一个 `Element`, 占用很少字节(在浏览器中)

99 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

将 HTML 字符串解析为 `DocumentFragment` 或一个 `Element`, 占用很少字节(在浏览器中)

doma (size)

Parse an HTML string into DocumentFragment or one Element, in a few bytes (in browser or jsdom)

Install

bash
npm install doma

Setup

javascript
// This module is only offered as a ES Module
import doma from 'doma';

Usage

javascript
doma('
Cats
 and dogs');
//=>  DocumentFragment[
, Text(' and dogs')]

doma('the cow');
//=>  DocumentFragment[Text('the cow')]

doma.one('beautiful bird');
//=>  

doma.one('wild animal');
//=>  null

More examples

Example: AJAXed page

Note: script tags are not executed, but other on* handlers will run normally once attached to the document.

javascript
const response = await fetch('page.html');
const html = await response.text();
const dom = doma(html);
const ajaxedContent = dom.querySelector('#ajax-container').childNodes;

const ajaxedContainer = document.querySelector('#ajax-container');
ajaxedContainer.append(...ajaxedContent);

Example: Parse images from HTML

Note: images are not fetched when the HTML is parsed. The elements only become "active" (and start loading) once appended to the document.

javascript
const html = 'They say it’s round  but actually it’s banana-shaped ';
const dom = doma(html);
// =>  DocumentFragment[Text('They say it’s round '), , Text(' but actually it’s banana-shaped ', ]

const images = dom.querySelectorAll('img');
// =>  NodeList[, ]

Example: Drop HTML tags from string

javascript
const html = 'Never gonna give you up, never gonna let you down';
const string = doma(html).textContent;
// =>  'Never gonna give you up, never gonna let you down'

Related

  • select-dom - Lightweight querySelector/All wrapper that outputs an Array.
  • delegate-it - DOM event delegation, in <1KB.
  • Refined GitHub - Uses this module.

License

MIT © Federico Brigante

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言