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

mrz4nodejs

v2.0.1

Published

Node.js MRZ (passport, ID card, visa) scanner built on Dynamsoft Capture Vision - pure JavaScript, no native build step.

Readme

Node.js MRZ Scanner SDK

Node.js MRZ (Machine Readable Zone) scanner for passports, ID cards and visas. It exposes the familiar mrz4nodejs API on top of dynamsoft-capture-vision-for-node, which means:

  • No native build step. No node-gyp, no C++ compiler, no prebuilt .node binaries.
  • Always the latest Dynamsoft MRZ engine. The engine ships as a regular npm dependency.
  • Unchanged JavaScript API. Existing mrz4nodejs code keeps working without modification.
const MrzScanner = require('mrz4nodejs');

MrzScanner.initLicense('LICENSE-KEY');

const scanner = new MrzScanner();
const lines = await scanner.decodeFileAsync('passport.png');
console.log(scanner.parseTwoLines(lines[0].text, lines[1].text));

License Key

Get a 30-day FREE trial license to activate the SDK.

MrzScanner.initLicense('DLS2eyJoYW5kc2hha2VDb2RlIjoi...');

Installation

npm install mrz4nodejs

Requirements:

  • Node.js >= 16
  • Windows (x64 / x86), Linux (x64 / arm64) or macOS (x64 / arm64). The platform specific native library is pulled in automatically as an optional dependency of dynamsoft-capture-vision-for-node.

Supported Documents

| Document | MRZ format | Lines | |---|---|---| | Passport | TD-3 | 2 | | ID card | TD-1 | 3 | | ID card | TD-2 | 2 | | Visa | MRV-A / MRV-B | 2 |

API

  • MrzScanner.initLicense(license: string): number
  • MrzScanner.getVersionNumber(): string
  • scanner.loadModel(modelDir: string): number
  • scanner.setTemplate(templateName: string): void
  • scanner.decodeFileAsync(filePath: string): Promise<MrzLineResult[]>
  • scanner.decodeBufferAsync(buffer, width, height, stride): Promise<MrzLineResult[]>
  • scanner.parseTwoLines(line1, line2): MrzInfo | false
  • scanner.parseThreeLines(line1, line2, line3): MrzInfo | false

MrzLineResult

{
  confidence: number,  // recognition confidence of the MRZ block
  text: string,        // one MRZ line, e.g. "P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<"
  x1, y1, x2, y2, x3, y3, x4, y4: number  // bounding quad of that line
}

decodeFileAsync() and decodeBufferAsync() return one item per MRZ line, so parseTwoLines(result[0].text, result[1].text) keeps working exactly as before.

Usage

Basic steps:

  1. Set the license key.

    MrzScanner.initLicense('LICENSE-KEY');
  2. Create an MRZ scanner object.

    const scanner = new MrzScanner();
  3. (Optional) Point the scanner at a custom template directory. The MRZ models ship with the npm package, so this step is only needed when modelDir contains a Capture Vision template (MRZ.json with a CaptureVisionTemplates array). It is kept so existing code keeps working.

    scanner.loadModel(path.dirname(require.resolve('mrz4nodejs')));
  4. Recognize MRZ lines from an image file.

    const result = await scanner.decodeFileAsync('passport.png');
    console.log(result);
  5. Parse the MRZ information.

    const info = result.length === 3
        ? scanner.parseThreeLines(result[0].text, result[1].text, result[2].text)
        : scanner.parseTwoLines(result[0].text, result[1].text);
    
    console.log(info);
    // {
    //   type: 'PASSPORT (TD-3)',
    //   nationality: 'UTO',
    //   surname: 'ERIKSSON',
    //   givenname: 'ANNA MARIA',
    //   passportnumber: 'L898902C3',
    //   issuecountry: 'UTO',
    //   birth: '1974-08-12',
    //   gender: 'F',
    //   expiry: '2012-04-15'
    // }
  6. Or recognize raw pixels (for example a camera frame).

    // Buffer holding RGB pixels
    const result = await scanner.decodeBufferAsync(rgbBuffer, width, height, width * 3);

Templates

setTemplate() switches the preset used by the decode calls:

| Template | Purpose | |---|---| | ReadPassportAndId (default) | Passports, ID cards and visas | | ReadPassport | Passports (TD-3) | | ReadId | ID cards (TD-1 / TD-2) | | ReadVisa | Visas (MRV-A / MRV-B) | | ReadMRZ | Any MRZ |

Behaviour Notes

  • One result per MRZ line. The engine returns one block per document; the block text is split on \n and a quad is interpolated per line, so the historical result[0..2].text shape is preserved.
  • Errors are reported. Failures (invalid license, unreadable file) reject the promise. Older versions resolved with an empty array.
  • getVersionNumber() returns the version string reported by the SDK itself, e.g. js:3.6.4002.20261019;cpp:3.6.40.9167 (Dynamsoft did not bump the JS prefix in 3.6.4003).
  • Decoding runs in worker threads managed by the SDK, so it never blocks the event loop. The worker pool is shut down shortly after the last decode, which lets short-lived scripts exit on their own.

Examples

Testing

npm test
DCV_LICENSE=YOUR-LICENSE-KEY npm test

License

MIT