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

node-unrtf

v5.0.4

Published

Asynchronous node.js wrapper for the UnRTF RTF conversion program

Downloads

3,638

Readme

Note An UnRTF v0.19.3 Windows binary is included with this module which, due to its age, has several issues, such as the inability to convert RTF documents generated from 2007 onwards, and a bug in the noPictures option that still generates pictures. It is recommended that whatever application is using the node-unrtf module is run in a Linux environment using the latest available UnRTF binaries, which do not have these bugs.

node-unrtf

GitHub release npm version Build status Coverage status code style: Prettier

Asynchronous node.js wrapper for the UnRTF RTF conversion program

Overview

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.

Installation

Install using npm:

npm i node-unrtf

Linux and macOS/Darwin support

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

Example usage

Please refer to the JSDoc comments in the source code or the generated type definitions for information on the available options.

Async Await

Example of an async await call to convert an RTF file to HTML in an ESM environment:

import { UnRTF } from "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 in a CJS environment:

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);
		return res;
	})
	.catch((err) => {
		console.error(err);
		throw err;
	});

Removing images generated by UnRTF

As mentioned in the note block at the top of this README, the noPictures option does not remove images when used with UnRTF < v0.20.4 and will write them to the current working directory. To remove images generated by UnRTF it is recommended to use a globbing module such as glob in conjunction with the node:fs/promises module to find and remove them:

import { unlink } from "node:fs/promises";
import { UnRTF } from "node-unrtf";
import { glob } from "glob";

const file = "test_resources/test_files/test-rtf-complex.rtf";
const unRtf = new UnRTF();
const options = {
	outputHtml: true,
	noPictures: true,
};

await unRtf.convert(file, options);

const files = await glob("*.{emf,wmf}");
await Promise.all(files.map((filed) => unlink(filed)));

Contributing

Contributions are welcome, and any help is greatly appreciated!

See the contributing guide for details on how to get started. Please adhere to this project's Code of Conduct when contributing.

License

node-unrtf is licensed under the MIT license.