API reference
Public functions, types and errors for reading and generating DOCX, with signatures generated from source.
The signatures and descriptions below are extracted automatically from the public entry of @quirekit/lit-docx. For LitAST node types, see The LitAST node model.
Reading
parseDocx
@quirekit/lit-docxCommercial licenseParses DOCX bytes into LitAST. Runs in browsers and Node; no file-system access is needed. @param buffer - Complete DOCX file bytes. @param options - Optional parsing behavior. @returns The document tree and non-fatal warnings. @throws DocxPackageError when the bytes are not a ZIP package, or are an OLE container such as an encrypted document or legacy `.doc`.
function parseDocx(buffer: Uint8Array, options?: ParseOptions): Promise<ParseResult>ParseOptions
@quirekit/lit-docxCommercial licenseOptions accepted by `parseDocx`.
interface ParseOptions {
preserveRawXml?: boolean;
plugins?: ParserPlugin[];
chartSourceLimits?: ChartSourceLimits;
numberingMode?: NumberingParseMode;
malformedFieldMode?: 'best-effort' | 'strict';
}ParseResult
@quirekit/lit-docxCommercial licenseResult of `parseDocx`: the document tree and every non-fatal problem found while reading it.
interface ParseResult {
ast: LitNode;
warnings: ParseWarning[];
}ParseWarning
@quirekit/lit-docxCommercial licenseOne non-fatal problem found while parsing.
interface ParseWarning {
code: string;
message: string;
location?: string;
element?: string;
}DocxPackageError
@quirekit/lit-docxCommercial licenseTyped failure raised before document-part parsing begins.
export class DocxPackageError extends Error {
readonly code: DocxPackageErrorCode;
constructor(code: DocxPackageErrorCode, message: string, options?: ErrorOptions);
}Generating
generateDocx
@quirekit/lit-docxCommercial licenseGenerates a complete DOCX file from LitAST, rebuilding the whole package from the tree. Runs in browsers and Node. @param ast - Document AST root. @returns Complete DOCX ZIP bytes.
function generateDocx(ast: LitAstNode): Promise<Uint8Array<ArrayBuffer>>