Document loader for Microsoft Word (.docx) files.

Uses mammoth.extractRawText() to strip all styling and return plain prose text, which is then stored as the content field. The metadata block includes an approximate wordCount.

Implements

Example

const loader = new DocxLoader();
const doc = await loader.load('/docs/spec.docx');
console.log(doc.metadata.wordCount); // e.g. 1842

Implements

Constructors

Methods

Properties

Constructors

Methods

  • Returns true when this loader is capable of handling source.

    For string sources the check is purely extension-based. For Buffer sources the loader may inspect magic bytes when relevant.

    Parameters

    • source: string | Buffer<ArrayBufferLike>

      Absolute file path or raw bytes.

    Returns boolean

  • Parses source and returns a normalised LoadedDocument.

    When source is a string the loader treats it as an absolute (or resolvable) file path and reads the file from disk. When source is a Buffer the loader parses the bytes directly and derives as much metadata as possible from the buffer content alone.

    Parameters

    • source: string | Buffer<ArrayBufferLike>

      Absolute file path OR raw document bytes.

    • Optional _options: LoadOptions

      Optional hints such as a format override.

    Returns Promise<LoadedDocument>

    A promise resolving to the fully-populated LoadedDocument.

    Throws

    When the file cannot be read or the format is not parsable.

Properties

supportedExtensions: string[] = ...

File extensions this loader handles, each with a leading dot.

Used by LoaderRegistry to route file paths to the correct loader.

Example

['.md', '.mdx']