Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

doma

> 编程语言
Open source

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

99 stars0 likes0 views
WebsiteGitHub

About

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

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 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

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