Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/parse/__tests__/td1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,51 @@ describe('parse TD1', () => {
});
});

it('PRADO Portugal ID PRT-BO-04001 - valid', () => {
// source: https://www.consilium.europa.eu/prado/en/PRT-BO-04001/index.html
const MRZ = [
'I<PRT007666667<ZZ00<<<<<<<<<<<',
'8303143M3405293PRT<<<<<<<<<<<4',
'CACADOR<DE<ARAUJO<<ANDRE<ESTEV',
];

const result = parse(MRZ);

expect(result).toMatchObject({
format: 'TD1',
valid: true,
documentNumber: result.fields.documentNumber,
});

expect(result.fields).toStrictEqual({
documentCode: 'I',
issuingState: 'PRT',
documentNumber: '007666667ZZ0',
documentNumberCheckDigit: '0',
birthDate: '830314',
birthDateCheckDigit: '3',
sex: 'male',
expirationDate: '340529',
expirationDateCheckDigit: '3',
nationality: 'PRT',
optional1: 'ZZ00',
optional2: '',
compositeCheckDigit: '4',
lastName: 'CACADOR DE ARAUJO',
firstName: 'ANDRE ESTEV',
});

const optional1Details = result.details.find(
(d) => d.field === 'optional1',
);
expect(optional1Details).toMatchObject({
value: 'ZZ00',
line: 0,
start: 15,
end: 19,
});
});

it('Finland ID FIN-BO-12001 - valid', () => {
// source: https://www.consilium.europa.eu/prado/en/FIN-BO-12001/index.html
const MRZ = [
Expand Down
13 changes: 1 addition & 12 deletions src/parse/td1Fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,7 @@ const fields: FieldOptions[] = [
line: 0,
start: 15,
end: 30,
related: [
{
line: 0,
start: 5,
end: 14,
},
{
line: 0,
start: 14,
end: 15,
},
],
related: [],
parser: parseDocumentNumberOptional,
},
{ ...birthDateTemplate, start: 0, end: 6, line: 1 },
Expand Down
27 changes: 7 additions & 20 deletions src/parsers/parseDocumentNumberOptional.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import { parseText } from './parseText.ts';

export function parseDocumentNumberOptional(
optional: string,
checkDigit: string,
) {
if (checkDigit === '<') {
const firstFiller = optional.indexOf('<');
const value = parseText(optional.slice(firstFiller + 1), firstFiller + 1);
return {
value,
start: firstFiller + 1,
end: firstFiller + 1 + value.length,
};
} else {
const value = parseText(optional, 0);
return {
value,
start: 0,
end: value.length,
};
}
export function parseDocumentNumberOptional(optional: string) {
const value = parseText(optional, 0);
return {
value,
start: 0,
end: value.length,
};
}