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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mtfm/docx-to-html

v2.1.0

Published

A converter which converts DOCX files to HTML

Downloads

12

Readme

@mtfm/docx-to-html

Provides a converter which converts .docx files (documents created by Microsoft Word) to HTML.

This package is part of the Mutaforma monorepo.

Table of contents

Installation

npm install @mtfm/docx-to-html

Usage

Minimum example

The conversion result is not persisted to disk, requiring programmatic handling to store or further process the output.

import { DocxToHtmlConverter } from "@mtfm/docx-to-html";

const converter = new DocxToHtmlConverter({
    input: "path/to/the/docx/file.docx",
});

const execOpResult = converter.execute();

if (execOpResult.isErr()) {
    const error = execOpResult.error;
    // Handle error during execution
    return;
}

const finalResult = execOpResult.value;

// Handle the conversion result

Persisting result to disk

To persist the conversion result to disk, simply provide the desired output folder path via the output property of the options object passed to the converter.

If the specified folder structure does not yet exist, it will be automatically created. Furthermore, the conversion result can still be processed programmatically.

import { DocxToHtmlConverter } from "@mtfm/docx-to-html";

const converter = new DocxToHtmlConverter({
    input: "path/to/the/docx/file.docx",
    output: "path/to/output/folder",
});

// Same as in minimum example

Customizing conversion configuration

To customize the default conversion configuration, you can specify the path to a custom configuration file in JSON format using the config property of the options object passed to the converter.

For a comprehensive overview of all available configuration settings and the required structure of the configuration file, please refer to the official Mutaforma documentation.

import { DocxToHtmlConverter } from "@mtfm/docx-to-html";

const converter = new DocxToHtmlConverter({
    input: "path/to/the/docx/file.docx",
    output: "path/to/output/folder",
    config: "path/to/custom/config/file.json",
});

// Same as in minimum example

API

DocxToHtmlConverter

Methods

| Name | Parameters | Returns | | --- | --- | --- | | constructor | IDocumentConverterOpts<...> | DocxToHtmlConverter | | execute | | Promise<Result<IDocumentConverterResult, Error>> |

IDocumentConverterOpts<string | Buffer>

Properties

| Name | Type | Mandatory | Description | | --- | --- | --- | --- | | input | string or Buffer | yes | Either a path to a *.docx file on disk or an already buffered *.docx file | | output | string | no | A path to a folder to which the output should be saved | | config | string | no | Path to a custom configuration file in JSON format |

IDocumentConverterResult

Properties

| Name | Type | Mandatory | Description | | --- | --- | --- | --- | | images | IAsset[] | yes | All images contained within the *.docx file | | document | IAsset | yes | The HTML document |

IAsset

Properties

| Name | Type | Mandatory | Description | | --- | --- | --- | --- | | id | string | yes | The asset id | | data | string | yes | The asset data | | dataEncoding | string | yes | The asset data encoding | | name | string | yes | The name of the asset | | ext | string | yes | The file extension of the asset |

License

MIT