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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@habibrosyad/docx-extractor

v0.1.2

Published

Extract and rebuild DOCX documents with full structure preservation. Parse Word documents to structured data and rebuild them programmatically.

Readme

@habibrosyad/docx-extractor

Extract DOCX documents to structured data and rebuild them programmatically. This library provides full round-trip conversion with preservation of formatting, styles, tables, images, and numbering.

Installation

npm install @habibrosyad/docx-extractor

Quick Start

import { DocxExtractor, DocxBuilder } from '@habibrosyad/docx-extractor';
import fs from 'fs';

// Extract DOCX to structured data
const extractor = new DocxExtractor();
const buffer = fs.readFileSync('document.docx');
const document = await extractor.extract(buffer);

// Modify the document structure
document.paragraphs.forEach(para => {
  if (para.runs) {
    para.runs.forEach(run => {
      // Modify text, formatting, etc.
    });
  }
});

// Rebuild DOCX
const builder = new DocxBuilder();
const newBuffer = await builder.build(document);
fs.writeFileSync('output.docx', newBuffer);

Features

  • Full Structure Extraction: Paragraphs, tables, images, styles, numbering
  • Formatting Preservation: Fonts, colors, spacing, alignment, borders
  • Round-Trip Conversion: Extract → Modify → Rebuild without data loss
  • Style Support: All paragraph and character styles with inheritance
  • Table Support: Complete table structure with cell properties
  • Image Support: Extract and embed images in documents
  • Numbering Support: Bullet lists and numbered lists

API

DocxExtractor

Extract a DOCX file to structured data.

const extractor = new DocxExtractor();
const document = await extractor.extract(buffer);

Returns: ExtractedDocument with:

  • paragraphs: Array of paragraphs
  • tables: Array of tables
  • body: Ordered sequence of paragraphs and tables
  • styles: Map of style definitions
  • defaults: Document-wide run formatting defaults
  • paragraphDefaults: Document-wide paragraph defaults (spacing, etc.)
  • numbering: Map of numbering definitions
  • mediaFiles: Map of embedded images/media

DocxBuilder

Build a DOCX file from structured data.

const builder = new DocxBuilder();
const buffer = await builder.build(document);

Parameters: ExtractedDocument (from extractor or construct it yourself)

Returns: Promise<Uint8Array> - DOCX file buffer (compatible with Node.js, browsers, and edge runtimes)

Platform Compatibility

This library works across all JavaScript runtimes:

  • Node.js: Full support (v18+)
  • Cloudflare Workers: Full support
  • Browsers: Full support
  • Deno: Full support
  • Bun: Full support

Using in Cloudflare Workers

export default {
  async fetch(request) {
    // Get DOCX file from request
    const arrayBuffer = await request.arrayBuffer();
    
    // Extract and process
    const extractor = new DocxExtractor();
    const document = await extractor.extract(arrayBuffer);
    
    // Modify document...
    
    // Rebuild
    const builder = new DocxBuilder();
    const outputBuffer = await builder.build(document);
    
    // Return as response
    return new Response(outputBuffer, {
      headers: {
        'Content-Type': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'Content-Disposition': 'attachment; filename="output.docx"'
      }
    });
  }
};

Document Structure

Paragraph

  • runs: Array of text runs with formatting
  • spacing: Paragraph spacing (before, after, line)
  • alignment: Left, center, right, justify
  • indentation: Left, right, firstLine, hanging
  • styleName: Applied paragraph style

Table

  • rows: Array of table rows
  • rows[i].cells: Array of table cells
  • cells[i].runs: Text content with formatting
  • cells[i].width, backgroundColor, borders: Cell properties

Run Formatting

  • bold, italic, underline, strike
  • fontSize, fontFamily, color
  • highlight color

Requirements

  • Modern JavaScript runtime with ES modules support (Node.js >= 18, Deno, Bun, Cloudflare Workers, or modern browsers)

License

MIT