diff --git a/README.md b/README.md index 0c2a1ed..98769de 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ const parse = require('mrz').parse; const mrz = [ 'I { }); }); + it('Portuguese ID - valid', () => { + // source: https://media.timeout.com/images/106144795/image.jpg + const MRZ = [ + 'I f.field === 'optional1', + ); + + expect(optional1Details).toMatchObject({ + value: 'ZZ92', + line: 0, + start: 15, + end: 19, + }); + }); + + it('Portuguese ID PRT-BO-04001 - valid', () => { + // source: https://www.consilium.europa.eu/prado/en/PRT-BO-04001/index.html + const MRZ = [ + 'I f.field === 'optional1', + ); + + expect(optional1Details).toMatchObject({ + value: 'ZZ00', + line: 0, + start: 15, + end: 19, + }); + }); + + it('Belgium ID BEL-BO-11005 - valid', () => { + // source: https://www.consilium.europa.eu/prado/en/BEL-BO-11005/index.html + // Changed the country code from UTO to BEL to make it pass the country validation, + // but that this part does not affect any check digit checks. + const MRZ = [ + 'IDBEL600001795<0152<<<<<<<<<<<', + '1301014F2311207BEL130101987398', + 'SPECIMEN< f.field === 'optional1', + ); + + expect(optional1Details).toMatchObject({ + value: '0152', + 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 = [ + 'I f.field === 'optional1', + ); + + expect(optional1Details).toMatchObject({ + value: '010195 112X', + line: 0, + start: 15, + end: 26, + }); + }); + it('Utopia example', () => { const MRZ = [ 'I { it('parse document number', () => { const MRZ = [ - 'I { expect(documentNumberDetails).toStrictEqual({ label: 'Document number', field: 'documentNumber', - value: 'D23145890124', + value: 'D23145890123', + valid: true, + ranges: [ + { line: 0, start: 5, end: 14, raw: 'D23145890' }, + { line: 0, start: 14, end: 15, raw: '<' }, + { line: 0, start: 15, end: 30, raw: '1233<<<<<<<<<<<' }, + ], + line: 0, + start: 5, + end: 18, + autocorrect: [], + }); + expect(result.fields.documentNumber).toBe('D23145890123'); + expect(result.fields.documentNumberCheckDigit).toBe('3'); + + const documentNumberCheckDigitDetails = result.details.find( + (d) => d.field === 'documentNumberCheckDigit', + ); + + expect(documentNumberCheckDigitDetails).toMatchObject({ + line: 0, + start: 18, + end: 19, + value: '3', + }); + }); + + it('parse document number ICAO Doc 9303 Sample', () => { + // source: https://www.icao.int/sites/default/files/publications/DocSeries/9303_p11_cons_en.pdf + // page 88, D.2 DERIVATION OF DOCUMENT BASIC ACCESS KEYS + const MRZ = [ + 'I !f.valid)).toHaveLength(2); + + const documentNumberDetails = result.details.find( + (d) => d.field === 'documentNumber', + ); + + expect(documentNumberDetails).toStrictEqual({ + label: 'Document number', + field: 'documentNumber', + value: 'D23145890734', valid: true, ranges: [ { line: 0, start: 5, end: 14, raw: 'D23145890' }, { line: 0, start: 14, end: 15, raw: '<' }, - { line: 0, start: 15, end: 30, raw: '1240 d.field === 'documentNumberCheckDigit', @@ -152,7 +391,7 @@ describe('parse TD1', () => { line: 0, start: 18, end: 19, - value: '0', + value: '9', }); }); diff --git a/src/parsers/__tests__/check.test.ts b/src/parsers/__tests__/check.test.ts index 0d7b821..7736722 100644 --- a/src/parsers/__tests__/check.test.ts +++ b/src/parsers/__tests__/check.test.ts @@ -5,5 +5,9 @@ import { check } from '../check.ts'; test('check digits', () => { expect(() => check('592166117<231', 8)).not.toThrow(); expect(() => check('592166111<773', 5)).not.toThrow(); + expect(() => check('007666667 check('007666667ZZ0', 0)).not.toThrow(); + expect(() => check('007777779ZZ9', 2)).not.toThrow(); + expect(() => check('600001795015', 2)).not.toThrow(); expect(() => check('592166111<773', 4)).toThrow(/invalid check digit/); }); diff --git a/src/parsers/parseDocumentNumberCheckDigit.ts b/src/parsers/parseDocumentNumberCheckDigit.ts index ffb351b..6894e4f 100644 --- a/src/parsers/parseDocumentNumberCheckDigit.ts +++ b/src/parsers/parseDocumentNumberCheckDigit.ts @@ -8,7 +8,7 @@ export default function parseDocumentNumberCheckDigit( if (checkDigit === '<' && optional) { const firstFiller = optional.indexOf('<'); const tail = optional.slice(0, firstFiller - 1); - source = `${source}<${tail}`; + source = `${source}${tail}`; checkDigit = optional.charAt(firstFiller - 1); check(source, checkDigit); return {