npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ohah/hwpjs

v0.1.0-rc.3

Published

HWP parser for Node.js, Web, and React Native

Readme

@ohah/hwpjs

HWP parser for Node.js, Web, and React Native

한글과컴퓨터의 한/글 문서 파일(.hwp)을 읽고 파싱하는 라이브러리입니다. Rust로 구현된 핵심 로직을 Node.js, Web, React Native 환경에서 사용할 수 있도록 제공합니다.

설치

npm install @ohah/hwpjs
# 또는
yarn add @ohah/hwpjs
# 또는
pnpm add @ohah/hwpjs
# 또는
bun add @ohah/hwpjs

사용법

CLI (Command Line Interface)

명령줄에서 직접 HWP 파일을 변환할 수 있습니다:

# 전역 설치
npm install -g @ohah/hwpjs

# JSON 변환
hwpjs to-json document.hwp -o output.json --pretty

# Markdown 변환
hwpjs to-markdown document.hwp -o output.md --include-images

# 파일 정보 확인
hwpjs info document.hwp

# 이미지 추출
hwpjs extract-images document.hwp -o ./images

# 배치 변환
hwpjs batch ./documents -o ./output --format json --recursive

더 자세한 내용은 CLI 가이드를 참고하세요.

Node.js

import { readFileSync } from 'fs';
import { toJson, toMarkdown, fileHeader } from '@ohah/hwpjs';

// HWP 파일 읽기
const fileBuffer = readFileSync('./document.hwp');

// JSON으로 변환
const jsonString = toJson(fileBuffer);
const document = JSON.parse(jsonString);
console.log(document);

// Markdown으로 변환
const { markdown, images } = toMarkdown(fileBuffer, {
  image: 'blob', // 또는 'base64'
  use_html: true,
  include_version: true,
  include_page_info: true,
});

// FileHeader만 추출
const headerString = fileHeader(fileBuffer);
const header = JSON.parse(headerString);
console.log(header);

Web (Browser)

import { toJson, toMarkdown } from '@ohah/hwpjs';

// File input에서 HWP 파일 읽기
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', async (e) => {
  const file = e.target.files[0];
  const arrayBuffer = await file.arrayBuffer();
  const uint8Array = new Uint8Array(arrayBuffer);

  // JSON으로 변환
  const jsonString = toJson(uint8Array);
  const document = JSON.parse(jsonString);

  // Markdown으로 변환 (base64 이미지 포함)
  const { markdown } = toMarkdown(uint8Array, {
    image: 'base64',
  });

  // 결과 표시
  document.getElementById('output').innerHTML = markdown;
});

React Native

import { toJson, toMarkdown } from '@ohah/hwpjs';
import * as FileSystem from 'expo-file-system';

// HWP 파일 읽기
const fileUri = 'file:///path/to/document.hwp';
const base64 = await FileSystem.readAsStringAsync(fileUri, {
  encoding: FileSystem.EncodingType.Base64,
});
const uint8Array = Uint8Array.from(atob(base64), c => c.charCodeAt(0));

// JSON으로 변환
const jsonString = toJson(uint8Array);
const document = JSON.parse(jsonString);

// Markdown으로 변환
const { markdown, images } = toMarkdown(uint8Array, {
  image: 'blob',
});

API

toJson(data: Buffer | Uint8Array): string

HWP 파일을 JSON 문자열로 변환합니다.

Parameters:

  • data: HWP 파일의 바이트 배열 (Buffer 또는 Uint8Array)

Returns:

  • JSON 문자열 (파싱된 HWP 문서)

Example:

const fileBuffer = readFileSync('./document.hwp');
const jsonString = toJson(fileBuffer);
const document = JSON.parse(jsonString);

toMarkdown(data: Buffer | Uint8Array, options?: ToMarkdownOptions): ToMarkdownResult

HWP 파일을 Markdown 형식으로 변환합니다.

Parameters:

  • data: HWP 파일의 바이트 배열 (Buffer 또는 Uint8Array)
  • options: 변환 옵션 (선택)
    • image: 이미지 형식 ('base64' 또는 'blob', 기본값: 'blob')
    • use_html: HTML 태그 사용 여부 (기본값: false)
    • include_version: 버전 정보 포함 여부 (기본값: false)
    • include_page_info: 페이지 정보 포함 여부 (기본값: false)

Returns:

  • ToMarkdownResult 객체:
    • markdown: Markdown 문자열
    • images: 이미지 데이터 배열 (blob 형식인 경우)

Example:

// Base64 이미지 포함
const { markdown } = toMarkdown(fileBuffer, {
  image: 'base64',
  use_html: true,
});

// Blob 이미지 (별도 배열로 반환)
const { markdown, images } = toMarkdown(fileBuffer, {
  image: 'blob',
});
// images 배열에서 이미지 데이터 사용
images.forEach(img => {
  console.log(`Image ${img.id}: ${img.format}, ${img.data.length} bytes`);
});

fileHeader(data: Buffer | Uint8Array): string

HWP 파일의 FileHeader만 추출하여 JSON 문자열로 반환합니다.

Parameters:

  • data: HWP 파일의 바이트 배열 (Buffer 또는 Uint8Array)

Returns:

  • JSON 문자열 (FileHeader 정보)

Example:

const fileBuffer = readFileSync('./document.hwp');
const headerString = fileHeader(fileBuffer);
const header = JSON.parse(headerString);
console.log(header.version);

예제

더 자세한 예제는 예제 디렉토리를 참고하세요.

지원 플랫폼

Node.js

  • Windows (x64, x86, arm64)
  • macOS (x64, arm64)
  • Linux (x64)

Web

  • WASM (WebAssembly)

React Native

  • iOS
  • Android

라이선스

MIT