A library for generating passport MRZ (Machine Readable Zone) strings
npm install @passport-mrz/builder



``js
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
// XS12345673JPN7902206F1101018<<<<<<<<<<<<<<00
`
โจ 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
Generates MRZ lines for a passport document.
#### input
Type: object
`ts [input.ts]`
/**
* 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.
The generated MRZ follows the TD3 format specification:
Line 1 (44 chars):
``
P
Line 2 (44 chars):
``
NNNNNNNNNCKAAABBBBBBBCSEEEEEEECPPPPPPPPPPPCC
Where:
- P - Document typeIII
- - Issuing state codeNNNNNNNNN
- - Document numberAAA
- - Nationality codeBBBBBB
- - Date of birth (YYMMDD)S
- - SexEEEEEE
- - Expiry date (YYMMDD)PPPPPPPPPPPP
- - Personal numberC` - Check digits
-
- Passport MRZ Simulator - Interactive web app using this library
- @passport-mrz/renderer - Render MRZ as images
MIT