Skip to content

Commit

Permalink
fix: add support for French national id with no administrative code (#61
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fominv authored Nov 21, 2024
1 parent d6f291a commit 506be15
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
33 changes: 33 additions & 0 deletions src/parse/__tests__/frenchNationalId.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,39 @@ describe('parse French National Id', () => {
expect(result.details.filter((a) => !a.valid)).toHaveLength(0);
});

it('valid MRZ with no administrative code', () => {
const MRZ = [
'IDFRABERTHIER<<<<<<<<<<<<<<<<<<<<<<<',
'9409923102854CORINNE<<<<<<<6512068F4',
];

const result = parse(MRZ);

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

expect(result.fields).toStrictEqual({
documentCode: 'ID',
issuingState: 'FRA',
lastName: 'BERTHIER',
administrativeCode: '',
issueDate: '9409',
administrativeCode2: '923',
documentNumber: '10285',
documentNumberCheckDigit: '4',
firstName: 'CORINNE',
birthDate: '651206',
birthDateCheckDigit: '8',
sex: 'female',
compositeCheckDigit: '4',
});

expect(result.details.filter((a) => !a.valid)).toHaveLength(0);
});

it('invalid MRZ', () => {
const MRZ = [
'IDFRATEST<NAME<<<<<<<<<<<<<<<<0CHE02',
Expand Down
6 changes: 4 additions & 2 deletions src/parse/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ function parseMRZ(
case 30:
return parsers.td1(lines, options);
case 36: {
const endLine1 = lines[0].substring(30, 66);
if (endLine1.match(/[0-9]/)) {
if (
lines[0].substring(30, 35).match(/[0-9]/) ||
lines[0].match(/^IDFRA/)
) {
return parsers.frenchNationalId(lines, options);
} else {
return parsers.td2(lines, options);
Expand Down

0 comments on commit 506be15

Please sign in to comment.