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

@llein/anpr-plate-cleaner

v1.0.0

Published

Production-grade OCR/ANPR license plate text cleaner, character confusion disambiguation (0/O, 1/I, 8/B), 2-line combiner, and fuzzy matcher.

Readme

@llein/anpr-plate-cleaner

Production-grade OCR / ANPR license plate text cleaner, character confusion disambiguation (0 vs O, 1 vs I, 8 vs B), 2-line combiner, and whitelist fuzzy matcher.

npm version npm downloads bundle size license


⚡ Why This Package?

In real-world parking barrier systems and traffic cameras (ANPR / ALPR), raw OCR output from models like YOLO, PaddleOCR, or EasyOCR is often corrupted by:

  • Night infrared reflections, dirt, scratches, and screw heads on the license plate.
  • OCR character confusions:
    • Letters read where digits are required (e.g., S instead of 5, I / L instead of 1, B instead of 8, O / D instead of 0).
    • Digits read where letters are required (e.g., 8 instead of B, 0 instead of D/O, 1 instead of I).
  • Two-line plates (top line: province & series, bottom line: sequence numbers).

@llein/anpr-plate-cleaner solves this using position-aware syntactic disambiguation, 2-line merging, and confusion-discounted fuzzy matching for resident whitelists.


🚀 Features

  • Position-Aware Error Correction:
    • Automatically fixes province digits, series letters, and serial numbers according to vehicle registration standards (Circular 24/2023/TT-BCA).
  • Two-Line Plate Stitching:
    • Combines multi-line OCR detections (e.g. 59-P1 on line 1 and 123.45 on line 2 -> 59P112345).
  • Vehicle Type Classification:
    • Classifies into car, motorbike, electric_motorbike, military, and diplomatic.
  • Confusion-Weighted Fuzzy Matching:
    • Levenshtein distance with fractional penalties for known OCR confusions (e.g. mistaking 8 for B is penalized with only 0.25 instead of 1.0).
    • Perfect for matching parking gate scans against database whitelist records.
  • Zero External Dependencies: Pure TypeScript, minimal footprint (< 4KB).

📦 Installation

# Using npm
npm install @llein/anpr-plate-cleaner

# Using pnpm
pnpm add @llein/anpr-plate-cleaner

# Using yarn
yarn add @llein/anpr-plate-cleaner

🛠️ Usage Examples

1. Clean Corrupted OCR Output

import { cleanVietnamPlate, cleanANPRText } from '@llein/anpr-plate-cleaner';

// OCR misread 'S' as 5, 'I' as 1, 'B' as 8
const result = cleanVietnamPlate('SIK-999.9B');

console.log(result.compact);   // "51K99998"
console.log(result.formatted); // "51K-999.98"
console.log(result.vehicleType); // "car"
console.log(result.isValid);   // true

2. Multi-line Motorbike Plate

// Bounding boxes read top & bottom lines
const rawOCR = "59-P1\n123.45";

const result = cleanVietnamPlate(rawOCR);
console.log(result.compact);   // "59P112345"
console.log(result.formatted); // "59-P1 123.45"
console.log(result.vehicleType); // "motorbike"

3. Match Plate Against Parking Whitelist (Fuzzy Search)

import { findBestPlateMatch } from '@llein/anpr-plate-cleaner';

const whitelist = [
  '51K99999',
  '29A12345',
  '59P167890'
];

// OCR reading has a glitch: 'O' instead of '0'
const scanned = '59P16789O';

const match = findBestPlateMatch(scanned, whitelist, 0.85);

if (match) {
  console.log(`Open Barrier! Matched: ${match.match} (Confidence: ${match.score * 100}%)`);
}

📖 API Reference

cleanVietnamPlate(raw: string): PlateCleanResult

Full syntactic analysis returning { raw, compact, formatted, vehicleType, isValid, score }.

cleanANPRText(raw: string, options?: CleanOptions): string

Returns cleaned string directly (compact or formatted).

combinePlateLines(topLine: string, bottomLine: string): string

Joins 2-line OCR boxes into a unified text string.

calculatePlateSimilarity(plateA: string, plateB: string): number

Returns a similarity score between 0.0 and 1.0 utilizing OCR confusion matrices.

findBestPlateMatch(query: string, candidates: string[], threshold?: number)

Searches a candidate array for the closest matching registered plate.


🧪 Testing

npm test

📄 License

MIT © Llein-Dev