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

@anmjin/docx-importer

v1.0.1

Published

Convert Word .docx files into Tiptap/ProseMirror JSON (and Payload Lexical state), with embedded images and human-readable import errors

Readme

@anmjin/docx-importer

Converts Word .docx files into Tiptap/ProseMirror JSON, extracts the embedded images, and explains failures in plain language for the person who uploaded the file. An optional second entry point turns the result into Lexical editor state for Payload CMS.

Built for Dhivehi (Thaana, right-to-left) publishing, but nothing in it is language-specific.

What it handles: headings (Word heading styles, and outline levels on custom styles), paragraphs, bold/italic/underline/strike/code/sub/superscript, hyperlinks, bullet and numbered lists, tables (flattened to cell | cell rows), manual line breaks, tracked changes (insertions kept, deletions dropped), embedded images with the caption paragraph after them, and a suggested title.

Installing

npm install @anmjin/docx-importer

Node 20 or newer. Versions before 1.0.1 were published only to GitHub Packages. If your project's .npmrc still maps @anmjin to npm.pkg.github.com, remove that line.

Usage

import { readFile } from 'node:fs/promises'
import { importDocx, DocxImportError } from '@anmjin/docx-importer'

try {
  const result = await importDocx(await readFile('essay.docx'), 'my-essay')

  result.tiptapJson      // { type: 'doc', content: [...] } — Tiptap/ProseMirror JSON
  result.images          // [{ filename, buffer }] — embedded images, in document order
  result.suggestedTitle  // "Title"-style text, else the first Heading 1, else the first heading
  result.warnings        // non-fatal problems, e.g. a skipped .emf drawing
  result.headingCount
  result.imageCount
} catch (err) {
  if (err instanceof DocxImportError) {
    // safe to show to the uploader as-is
    console.log(err.userMessage, err.where, err.recoverable)
  } else {
    throw err
  }
}

Images

Each image becomes a figureImage node whose src is a placeholder built from the image's filename; by default /images/articles/<slug>/<filename>. Upload the buffers from result.images wherever you store media, then swap the placeholders for real URLs. To choose the placeholder format:

await importDocx(buffer, 'my-essay', {
  imageSrc: (filename, slug) => `pending-upload://${slug}/${filename}`,
})

Payload CMS (Lexical)

import { tiptapToLexical } from '@anmjin/docx-importer/lexical'

// map each figureImage src to the id of the media document you uploaded
const { state, warnings } = tiptapToLexical(result.tiptapJson, (src) => mediaIdBySrc.get(src) ?? null)

await payload.create({ collection: 'articles', data: { title, content: state }, draft: true })

Images whose src resolves to null are dropped and reported in warnings. Text direction (rtl/ltr) is detected per block from its script.

Developing

npm install
npm test                                  # builds, then runs the regression suite
DOCX_FIXTURES_DIR=path/to/docs npm test   # also imports a folder of real .docx files

Real-world fixtures aren't committed: they tend to be unpublished articles.

Releasing

Bump the version and push the tag; the CI workflow runs the tests and publishes to npm (via npm trusted publishing, so no token is stored in the repo):

npm version patch        # or minor / major
git push --follow-tags

License

MIT