/node-unrtf

Asynchronous node.js wrapper for the UnRTF RTF conversion program

Primary LanguageRich Text FormatMIT LicenseMIT

node-unrtf

GitHub Release npm version Build Status Coverage Status Known Vulnerabilities code style: prettier

Asynchronous node.js wrapper for the UnRTF RTF conversion program

Intro

UnRTF is a CLI program that allows for the manipulation and extraction of data from RTF documents such as converting RTF files to HTML or TXT.

The node-unrtf module provides an asynchronous node.js wrapper around said CLI program for easier use. It was created out of a need for an RTF-to-HTML conversion module at Yeovil District Hospital NHS Foundation Trust to convert clinical documents.

Installation

Install using npm:

npm install node-unrtf

Or yarn:

yarn add node-unrtf

node-unrtf's test scripts use npm commands.

Linux and macOS/Darwin Support

A Windows binary (v0.19.3) is provided with this repository. For Linux and Mac users, you will need to download the unrtf binary separately.

An example of downloading the binary on a Debian system:

sudo apt-get install unrtf

For macOS, the binary can be installed with Homebrew:

brew install unrtf

Once they have been installed, you will need to pass the unrtf installation directory in as parameters to an instance of the UnRTF class:

const { UnRTF } = require("node-unrtf");
const unRtf = new UnRTF("./usr/bin");

API

const { UnRTF } = require("node-unrtf");

API Documentation can be found here

Examples

Async Await

Example of an async await call to convert an RTF file to HTML, and then output the result to console:

const { UnRTF } = require("node-unrtf");

const file = "test_document.rtf";
const unRtf = new UnRTF();
const options = {
	outputHtml: true,
};

const res = await unRtf.convert(file, options);
console.log(res);

Promise Chaining

Example of calling unRTF.convert with a promise chain:

const { UnRTF } = require("node-unrtf");

const file = "test_document.rtf";
const unRtf = new UnRTF("./usr/bin");
const options = {
	outputHtml: true,
};

unRTF.convert(file, options).then((res) => {
	console.log(res);
});

Contributing

Please see CONTRIBUTING.md for more details regarding contributing to this project.

License

node-unrtf is licensed under the MIT license.