@usejunior/docx-core for direct use when you need fine-grained control over document structure.
Most users work with the MCP tools or
compareDocuments rather than primitives directly. Use primitives when building custom tooling on top of the library.DocxDocument and DocxZip
The two primary container classes.DocxZip
Low-level DOCX zip container. Reads and writes named XML parts within the .docx package.
Additional standalone helpers:
DocxDocument
High-level document object providing typed access to paragraphs, text, comments, footnotes, and layout. Used internally by the MCP session layer.
Text operations
Exported fromprimitives/text.ts.
replaceParagraphTextRange accepts either a plain string or a ReplacementPart[] array for multi-segment replacements with per-segment formatting overrides.
Run normalization
Exported fromprimitives/merge_runs.ts.
w:r elements with identical w:rPr formatting. Takes a W3C DOM Document. Run fragmentation is common in documents edited in Word and can cause text-search mismatches.
Comment operations
Exported fromprimitives/comments.ts.
The
Comment type returned by getComments:
Footnote operations
Exported fromprimitives/footnotes.ts.
Layout operations
Exported fromprimitives/layout.ts.
All layout mutations accept twip (twentieth of a point) values consistent with OOXML.
Revision operations
Accept changes
Document (parsed with parseXml) and mutates it in place.
Reject changes
Document.
Extract revisions
before_text, after_text, revision entries (type, text, author), and associated comments.
RevisionType values: 'INSERTION' | 'DELETION' | 'MOVE_FROM' | 'MOVE_TO' | 'FORMAT_CHANGE'
Utilities
XML helpers (xml.ts)
Document and serialize it back. These are thin wrappers around @xmldom/xmldom.
DOM helpers (dom-helpers.ts)
getElementsByTagName traversal overhead.

