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

ocr-text-extract

v1.0.0

Published

Browser OCR with smart preprocessing, multi-pass recognition, and layout reconstruction — powered by Tesseract.js

Readme

ocr-text-extract

Browser OCR with smart preprocessing, multi-pass recognition, and layout reconstruction — powered by Tesseract.js.

All processing runs in the browser. Images are never sent to a server.

Features

  • Multi-pass OCR with automatic best-result selection
  • Smart image preprocessing (contrast stretch, sharpening, adaptive threshold)
  • Modal/dialog auto-focus for UI screenshots
  • Multi-column layout reconstruction
  • Clean mode with confidence-based word filtering
  • Dark image and logo/single-line fallbacks
  • 12+ language support via Tesseract

Install

npm install ocr-text-extract tesseract.js

tesseract.js is a peer dependency — install it alongside this package.

Usage

import { extractTextFromImage } from "ocr-text-extract";

// From a File input
const file = document.querySelector("input[type=file]").files[0];

const result = await extractTextFromImage(file, {
  language: "eng",
  cleanMode: true,
  output: "text", // or "json"
  onProgress: (pct) => console.log(`${pct}%`),
});

console.log(result.text);        // always plain extracted text
console.log(result.formatted);   // text or JSON string, based on `output`
console.log(result.output);      // "text" or "json"
console.log(result.confidence);  // 0–100 score, or null if empty
console.log(result.passUsed);    // e.g. "enhanced", "focused", "binary"

Output formats

| output | result.formatted | result.text | |----------|-------------------|---------------| | "text" (default) | Plain extracted text | Same plain text | | "json" | JSON string with text, confidence, passUsed, metrics | Plain text (always available) |

// JSON output example
const result = await extractTextFromImage(file, { output: "json" });
const data = JSON.parse(result.formatted);
// { text: "...", confidence: 87, passUsed: "enhanced", metrics: { ... } }

Input types

extractTextFromImage accepts:

  • Data URL string ("data:image/png;base64,...")
  • File or Blob

Options

| Option | Default | Description | |--------|---------|-------------| | language | "eng" | Tesseract language code | | cleanMode | false | Filter low-confidence words; best for screenshots | | targetLongEdge | 2000 | Target image long edge when scaling | | maxLongEdge | 3200 | Maximum long edge when scaling | | ocrDpi | "300" | DPI hint passed to Tesseract | | output | "text" | Result format: "text" or "json" | | onProgress | — | Callback receiving 0–100 progress |

Lower-level API

Individual preprocessing and formatting helpers are exported for advanced use:

import {
  loadScaledCanvas,
  preprocessFromScaled,
  detectModalRegion,
  formatOcrOutput,
  normalizeText,
  scoreOcrResult,
  SUPPORTED_LANGUAGES,
} from "ocr-text-extract";

Browser support

Requires a modern browser with canvas, Image, and FileReader APIs. Designed for client-side use only.

Development

npm install
npm test
npm run build

License

MIT