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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nosferatu500/textract-lite

v9.0.0

Published

Extracting text from .docx and plain text files.

Readme

textract-lite

A small, dependency-light text extraction module for node. ESM only.

This is a trimmed-down fork of textract. Everything that required an external binary (antiword, tesseract, pdftotext, unzip, …) has been removed, so there is nothing to install beyond the package itself.

Currently Extracts...

  • .docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
  • Anything with a text/* mime type — .txt, .csv, .html, .md, …
  • application/csv
  • application/javascript

What textract-lite cares about is the mime type, not the extension. Any extension that maps to one of the types above will extract. The mime type is resolved from the file name via mime, and can be overridden — see typeOverride below.

Need a type that isn't listed? Open an issue or a pull request.

Requirements

  • Node.js >= 24.11

Install

npm i @nosferatu500/textract-lite

Usage

The package is ESM only, so use import. There is no CLI.

import { fromFileWithPath, fromFileWithMimeAndPath } from "@nosferatu500/textract-lite";

APIs

Both functions are async and resolve to either the extracted text or an Error. options is optional.

File

const text = await fromFileWithPath(filePath);

The mime type is derived from filePath.

File + mime type

const text = await fromFileWithMimeAndPath(type, filePath);

Use this when the file name doesn't reflect its contents, or when you already know the type.

Error handling

Extraction failures are reported two different ways, so handle both: most failures resolve with an Error (unsupported mime type, undeterminable mime type, missing file, undetectable text encoding, a file that isn't really a zip), while a .docx with no extractable content rejects.

try {
    const result = await fromFileWithPath(filePath);
    if (result instanceof Error) {
        // unsupported/unknown type, missing file, unknown encoding, not a zip
        console.error(result.message);
    } else {
        console.log(result);
    }
} catch (error) {
    // .docx containing no extractable content
    console.error(error);
}

TypeScript

The package ships its own types. ExtractOptions is exported for annotating a shared config object:

import { fromFileWithPath, type ExtractOptions } from "@nosferatu500/textract-lite";

const options: ExtractOptions = { preserveLineBreaks: true };
const text = await fromFileWithPath(filePath, options);

Configuration

The second argument to both functions accepts:

  • preserveLineBreaks: Defaults to false, which strips all line breaks from the output. Pass true to keep them.
  • preserveOnlyMultipleLineBreaks: Defaults to false. When true, single line breaks are collapsed into spaces but consecutive line breaks are preserved. Note that this does not reliably preserve paragraphs unless the source actually uses multiple breaks between them. Setting this implies preserveLineBreaks.
  • typeOverride: Only used by fromFileWithPath. When set, this mime type is used instead of the one derived from the file name.
const text = await fromFileWithPath(filePath, { preserveLineBreaks: true });
const csv = await fromFileWithPath("data.dat", { typeOverride: "application/csv" });

Notes on extraction

  • Text files have their encoding detected with jschardet and are decoded with iconv-lite. If the encoding cannot be detected, an Error is returned rather than a best-effort guess.
  • All extracted text is passed through a cleansing step that normalizes typographic quotes, ellipses and long hyphens, collapses runs of whitespace, and decodes XML entities.

Development

The build targets ES2025 and the package is ESM only. Tests run straight from the TypeScript source using Node's built-in type stripping, so there is no transpiling test loader to configure.

npm install
npm run build     # clean + tsc + prune internal .d.ts files
npm test          # mocha, tests live in tests/
npm run lint      # eslint (flat config)
npm run docs      # typedoc into docs/

License

MIT. See LICENSE.