@dooboostore/dom-parser

A lightweight and efficient HTML DOM parser for server-side rendering and DOM manipulation

서버 사이드 렌더링과 DOM 조작을 위한 경량이고 효율적인 HTML DOM 파서

GitHubNPM

Installation

Install the package with your preferred package manager

선호하는 패키지 매니저로 패키지를 설치하세요

Overview

@dooboostore/dom-parser provides a complete DOM implementation for Node.js environments, enabling server-side HTML parsing and manipulation with browser-compatible APIs.

@dooboostore/dom-parser는 Node.js 환경을 위한 완전한 DOM 구현을 제공하여, 브라우저 호환 API로 서버 사이드 HTML 파싱과 조작을 가능하게 합니다.

🚀 Server-Side DOM

Complete DOM implementation for Node.js without browser dependencies

브라우저 의존성 없이 Node.js를 위한 완전한 DOM 구현

🔧 HTML Parsing

Parse HTML strings into fully navigable DOM tree structures

HTML 문자열을 완전히 탐색 가능한 DOM 트리 구조로 파싱

🌐 Browser API Compatible

Implements standard DOM APIs like document, window, Element

document, window, Element 같은 표준 DOM API 구현

⚡ Lightweight & Fast

Minimal dependencies with fast parsing performance

빠른 파싱 성능과 최소한의 의존성

Architecture Overview

Understanding dom-parser's HTML parsing and DOM construction process

dom-parser의 HTML 파싱 및 DOM 구성 과정 이해하기

HTML Parsing Flow

How HTML strings are transformed into navigable DOM structures

HTML 문자열이 탐색 가능한 DOM 구조로 변환되는 과정

graph TB
    A[HTML String Input] -->|Parse| B[HTML Tokenizer]
    B -->|Tokens| C[DOM Tree Builder]
    C -->|Create| D[Document Node]
    D -->|Contains| E[HTML Element]
    E -->|Contains| F[Head Element]
    E -->|Contains| G[Body Element]
    F -->|Contains| H[Title, Meta, etc.]
    G -->|Contains| I[Div, P, H1, etc.]
    
    J[DomParser Constructor] -->|Initialize| K[Document Object]
    K -->|Setup| L[Window Object]
    K -->|Provide| M[DOM APIs]
    
    M -->|querySelector| N[Element Selection]
    M -->|createElement| O[Element Creation]
    M -->|appendChild| P[DOM Manipulation]
    
    style A fill:#e1f5ff
    style D fill:#fff4e6
    style K fill:#f3e8ff
    style M fill:#dcfce7
    linkStyle default stroke:#aaaaaa,stroke-width:2px

DOM Tree Structure

Visual representation of the parsed DOM hierarchy

파싱된 DOM 계층 구조의 시각적 표현

graph TD
    A[Document] -->|documentElement| B[HTML]
    B -->|head| C[Head]
    B -->|body| D[Body]
    
    C -->|children| E[Title]
    C -->|children| F[Meta Tags]
    C -->|children| G[Link Tags]
    
    D -->|children| H[Div#app]
    D -->|children| I[Script Tags]
    
    H -->|children| J[H1]
    H -->|children| K[P.content]
    H -->|children| L[Ul]
    
    L -->|children| M[Li Item 1]
    L -->|children| N[Li Item 2]
    
    J -->|textContent| O["Hello World"]
    K -->|textContent| P["Paragraph text"]
    M -->|textContent| Q["List item 1"]
    N -->|textContent| R["List item 2"]
    
    style A fill:#ff6b6b,color:#fff
    style B fill:#4ecdc4,color:#fff
    style C fill:#45b7d1,color:#fff
    style D fill:#45b7d1,color:#fff
    style H fill:#96ceb4,color:#fff
    style J fill:#feca57,color:#000
    style K fill:#feca57,color:#000
    style L fill:#feca57,color:#000
    linkStyle default stroke:#333,stroke-width:2px

API Interaction Flow

How different DOM APIs interact with the parsed structure

다양한 DOM API가 파싱된 구조와 상호작용하는 방식

sequenceDiagram
    participant User
    participant DomParser
    participant Document
    participant Element
    participant Node

    User->>DomParser: new DomParser(htmlString)
    DomParser->>DomParser: Parse HTML
    DomParser->>Document: Create document
    DomParser->>User: Return parser instance

    User->>DomParser: parser.document
    DomParser->>User: Return document object

    User->>Document: querySelector('.app')
    Document->>Element: Find matching element
    Element->>User: Return element or null

    User->>Document: createElement('div')
    Document->>Element: Create new element
    Element->>User: Return new element

    User->>Element: appendChild(childNode)
    Element->>Node: Add to children
    Node->>Element: Update parent reference
    Element->>User: Return appended node

    User->>Element: getAttribute('id')
    Element->>User: Return attribute value

    User->>Element: textContent = 'New text'
    Element->>Node: Update text nodes
    Node->>Element: Confirm update

Common Use Case Flow

Typical workflow for server-side HTML processing

서버 사이드 HTML 처리를 위한 일반적인 워크플로우

flowchart LR
    A[HTML Template] -->|Read| B[DomParser]
    B -->|Parse| C[DOM Tree]
    
    C -->|Query| D[Find Elements]
    C -->|Create| E[New Elements]
    C -->|Modify| F[Update Content]
    
    D -->|getElementById| G[Specific Element]
    D -->|querySelector| H[CSS Selector Match]
    D -->|getElementsByTagName| I[Tag Collection]
    
    E -->|createElement| J[New Element]
    J -->|setAttribute| K[Add Attributes]
    J -->|textContent| L[Set Text]
    
    F -->|innerHTML| M[Update HTML]
    F -->|appendChild| N[Add Children]
    F -->|removeChild| O[Remove Children]
    
    G --> P[Final DOM]
    H --> P
    I --> P
    K --> P
    L --> P
    M --> P
    N --> P
    O --> P
    
    P -->|Serialize| Q[Output HTML]
    
    style A fill:#e3f2fd
    style B fill:#fff3e0
    style C fill:#f3e5f5
    style P fill:#e8f5e8
    style Q fill:#fff8e1
    linkStyle default stroke:#666,stroke-width:2px

Quick Start

Get started with basic HTML parsing in just a few lines

몇 줄의 코드로 기본 HTML 파싱 시작하기

Basic Usage

Parse HTML and access DOM elements using familiar browser APIs

친숙한 브라우저 API를 사용하여 HTML 파싱 및 DOM 요소 접근

Core Features

Essential DOM parsing and manipulation capabilities

필수 DOM 파싱 및 조작 기능

DomParser Class

Main parser class with document and window access

document와 window 접근을 제공하는 메인 파서 클래스

DOM Manipulation

Create, modify, and manipulate DOM elements programmatically

프로그래밍 방식으로 DOM 요소 생성, 수정 및 조작

Element Queries

Find elements using CSS selectors and DOM traversal methods

CSS 선택자와 DOM 탐색 메서드를 사용하여 요소 찾기

Use Cases

Common scenarios where dom-parser excels

dom-parser가 뛰어난 성능을 발휘하는 일반적인 시나리오

Server-Side Rendering (SSR)

Set up global DOM environment for SSR applications

SSR 애플리케이션을 위한 글로벌 DOM 환경 설정

HTML Processing & Transformation

Process and transform HTML content programmatically

프로그래밍 방식으로 HTML 콘텐츠 처리 및 변환

Web Scraping & Data Extraction

Extract structured data from HTML content

HTML 콘텐츠에서 구조화된 데이터 추출

API Reference

Complete API documentation for all classes and methods

모든 클래스와 메서드에 대한 완전한 API 문서

DomParser

Main parser class constructor and properties

메인 파서 클래스 생성자 및 속성

CONSTRUCTOR & PROPERTIES생성자 및 속성
  • constructor(html: string, options?: DomParserOptions)Create new DomParser instance with HTML string and optional configurationHTML 문자열과 선택적 설정으로 새 DomParser 인스턴스 생성
  • document: DocumentGet the parsed document object with full DOM API support완전한 DOM API 지원을 가진 파싱된 document 객체 가져오기
  • window: WindowGet the window object for server-side rendering compatibility서버 사이드 렌더링 호환성을 위한 window 객체 가져오기

Supported DOM APIs

Standard DOM methods and properties available

사용 가능한 표준 DOM 메서드 및 속성

DOCUMENT METHODSDocument 메서드
  • querySelector(selector: string): Element | nullFind first element matching CSS selectorCSS 선택자와 일치하는 첫 번째 요소 찾기
  • querySelectorAll(selector: string): NodeListFind all elements matching CSS selectorCSS 선택자와 일치하는 모든 요소 찾기
  • getElementById(id: string): Element | nullFind element by ID attributeID 속성으로 요소 찾기
  • getElementsByClassName(className: string): HTMLCollectionFind elements by class name클래스 이름으로 요소 찾기
  • getElementsByTagName(tagName: string): HTMLCollectionFind elements by tag name태그 이름으로 요소 찾기
  • createElement(tagName: string): ElementCreate new element with specified tag name지정된 태그 이름으로 새 요소 생성
  • createTextNode(text: string): TextCreate new text node with specified content지정된 내용으로 새 텍스트 노드 생성
ELEMENT METHODSElement 메서드
  • appendChild(child: Node): NodeAdd child node to element요소에 자식 노드 추가
  • removeChild(child: Node): NodeRemove child node from element요소에서 자식 노드 제거
  • setAttribute(name: string, value: string): voidSet attribute value속성 값 설정
  • getAttribute(name: string): string | nullGet attribute value속성 값 가져오기
  • innerHTML: stringGet or set inner HTML content내부 HTML 콘텐츠 가져오기 또는 설정
  • textContent: stringGet or set text content텍스트 콘텐츠 가져오기 또는 설정

Interactive Demo

Try dom-parser in an interactive environment

인터랙티브 환경에서 dom-parser 체험하기

INTERACTIVE DEMO

인터랙티브 데모

Learn More

Additional resources and documentation

추가 리소스 및 문서

📚 GitHub Repository

View source code, report issues, and contribute

소스 코드 보기, 이슈 리포트, 기여하기

Visit Repository →

📦 NPM Package

Install and view package information

패키지 설치 및 정보 보기

View on NPM →

🏗️ Related Packages

Explore other dooboostore packages

다른 dooboostore 패키지 탐색

Browse Packages →