@passport-mrz/builder
v1.0.0
Published
A library for generating passport MRZ (Machine Readable Zone) strings
Readme
@passport-mrz/builder
Usage
import { buildMrzLines } from '@passport-mrz/builder'
const [line1, line2] = buildMrzLines({
documentType: 'P',
issuingState: 'JPN',
documentNumber: 'XS1234567',
primaryIdentifier: 'GAIMU',
secondaryIdentifier: 'SAKURA',
nationality: 'JPN',
dateOfBirth: '790220',
sex: 'F',
dateOfExpiry: '110101',
// personalNumber: '', (optional)
})
console.log(line1)
// P<JPNGAIMU<<SAKURA<<<<<<<<<<<<<<<<<<<<<<<<<<
console.log(line2)
// XS12345673JPN7902206F1101018<<<<<<<<<<<<<<00Features
✨ TD3 format compliant - Generates 2×44 character lines according to ICAO 9303 standard 🔒 Automatic check digits - Calculates all required check digits for validation 🧹 Input sanitization - Strips non-alphanumeric characters to ensure MRZ compliance 📦 Zero dependencies - Lightweight and fast 🎯 TypeScript ready - Full type definitions included
API
buildMrzLines(input)
Generates MRZ lines for a passport document.
input
Type: object
/**
* Input data for generating passport MRZ (Machine Readable Zone).
* Follows TD3 format specification for passport documents according to ICAO 9303 standard.
*/
export type Input = {
/** Document Type (typically "P" for passport) */
documentType: string;
/** Issuing State (ISO 3166-1 alpha-3 country code) */
issuingState: string;
/** Document Number (passport number) */
documentNumber: string;
/** Primary Identifier (surname/family name) */
primaryIdentifier: string;
/** Secondary Identifier (given names) */
secondaryIdentifier: string;
/** Nationality (ISO 3166-1 alpha-3 country code) */
nationality: string;
/** Date of Birth (YYMMDD format) */
dateOfBirth: string;
/** Personal Number (optional, may be empty) */
personalNumber?: string;
/** Sex (M/F/<) */
sex: string;
/** Date of Expiry (YYMMDD format) */
dateOfExpiry: string;
};Returns
Type: [string, string]
Returns a tuple containing the two MRZ lines, each exactly 44 characters long.
MRZ Format
The generated MRZ follows the TD3 format specification:
Line 1 (44 chars):
P<IIISURNAME<<GIVEN<NAMES<<<<<<<<<<<<<<<<<<<Line 2 (44 chars):
NNNNNNNNNCKAAABBBBBBBCSEEEEEEECPPPPPPPPPPPCCWhere:
P- Document typeIII- Issuing state codeNNNNNNNNN- Document numberAAA- Nationality codeBBBBBB- Date of birth (YYMMDD)S- SexEEEEEE- Expiry date (YYMMDD)PPPPPPPPPPPP- Personal numberC- Check digits
Related
- Passport MRZ Simulator - Interactive web app using this library
- @passport-mrz/renderer - Render MRZ as images
License
MIT
