-
Notifications
You must be signed in to change notification settings - Fork 28
Fix french ID parser #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a85f867
e3ebb0a
747aded
35a06aa
e7802e5
3499a4a
916e5cb
94f88e1
e3efd15
4866d80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| testURL: 'http://localhost', | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||||||
| { | ||||||||||
| "name": "mrz", | ||||||||||
| "version": "3.1.1", | ||||||||||
| "name": "@lukesolo/mrz", | ||||||||||
| "version": "3.1.3", | ||||||||||
|
Comment on lines
+2
to
+3
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| "description": "Parse MRZ (Machine Readable Zone) from identity documents", | ||||||||||
| "main": "./src/index.js", | ||||||||||
| "files": [ | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,8 @@ const formats = { | |
| TD2: 'TD2', | ||
| TD3: 'TD3', | ||
| SWISS_DRIVING_LICENSE: 'SWISS_DRIVING_LICENSE', | ||
| FRENCH_NATIONAL_ID: 'FRENCH_NATIONAL_ID' | ||
| FRENCH_NATIONAL_ID: 'FRENCH_NATIONAL_ID', | ||
| FRENCH_DRIVING_LICENSE: 'FRENCH_DRIVING_LICENSE' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we call it EU_DRIVING_LICENSE or the french one has non-standard parts?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no standard in EU driving license. As I know, French, Swiss and Netherlands driving licenses are all has unique format. |
||
| }; | ||
| Object.freeze(formats); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| 'use strict'; | ||
|
|
||
| const parse = require('../parse'); | ||
|
|
||
| describe('parse French Driving License', () => { | ||
| it('valid MRZ', function () { | ||
| const MRZ = [ 'D1FRA13BB148959280920BETTOLO<7' ]; | ||
| var result = parse(MRZ); | ||
| expect(result.format).toBe('FRENCH_DRIVING_LICENSE'); | ||
| expect(result.details.filter((a) => !a.valid)).toHaveLength(0); | ||
| expect(result.fields).toEqual({ | ||
| documentCode: 'D', | ||
| bapConfiguration: '1', | ||
| issuingState: 'FRA', | ||
| documentNumber: '13BB14895', | ||
| documentNumberCheckDigit: '9', | ||
| expirationDate: '280920', | ||
| lastName: 'BETTOLO', | ||
| compositeCheckDigit: '7' | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| 'use strict'; | ||
|
|
||
| const checkLines = require('./checkLines'); | ||
| const getResult = require('./getResult'); | ||
| const { FRENCH_DRIVING_LICENSE } = require('../formats'); | ||
| const frenchDrivingLicenseFields = require('./frenchDrivingLicenseFields'); | ||
|
|
||
| module.exports = function parseFrenchDrivingLicense(lines) { | ||
| lines = checkLines(lines); | ||
| if (lines.length !== 1) { | ||
| throw new Error( | ||
| `invalid number of lines: ${ | ||
| lines.length | ||
| }: Must be 1 for ${FRENCH_DRIVING_LICENSE}` | ||
| ); | ||
| } | ||
| if (lines[0].length !== 30) { | ||
| throw new Error( | ||
| `invalid number of characters for line: ${ | ||
| lines[0].length | ||
| }. Must be 30 for ${FRENCH_DRIVING_LICENSE}` | ||
| ); | ||
| } | ||
| return getResult(FRENCH_DRIVING_LICENSE, lines, frenchDrivingLicenseFields); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| 'use strict'; | ||
|
|
||
| const parseDocumentCode = require('../parsers/euDrivingLicense/parseDocumentCode'); | ||
| const parseBapConfiguration = require('../parsers/euDrivingLicense/parseBapConfiguration'); | ||
| const parseState = require('../parsers/parseState'); | ||
| const parseDocumentNumber = require('../parsers/euDrivingLicense/france/parseDocumentNumber'); | ||
| const parseLastName = require('../parsers/euDrivingLicense/france/parseLastName'); | ||
|
|
||
| const { | ||
| documentCodeTemplate, | ||
| bapConfigurationTemplate, | ||
| issuingStateTemplate, | ||
| documentNumberTemplate, | ||
| documentNumberCheckDigitTemplate, | ||
| expirationDateTemplate, | ||
| lastNameTemplate, | ||
| compositeCheckDigitTemplate | ||
| } = require('./fieldTemplates'); | ||
| const createFieldParser = require('./createFieldParser'); | ||
|
|
||
| module.exports = [ | ||
| Object.assign({}, documentCodeTemplate, { | ||
| line: 0, | ||
| start: 0, | ||
| end: 1, | ||
| parser: parseDocumentCode | ||
| }), | ||
| Object.assign({}, bapConfigurationTemplate, { | ||
| line: 0, | ||
| start: 1, | ||
| end: 2, | ||
| parser: parseBapConfiguration | ||
| }), | ||
| Object.assign({}, issuingStateTemplate, { | ||
| line: 0, | ||
| start: 2, | ||
| end: 5, | ||
| parser: parseState | ||
| }), | ||
| Object.assign({}, documentNumberTemplate, { | ||
| line: 0, | ||
| start: 5, | ||
| end: 14, | ||
| parser: parseDocumentNumber | ||
| }), | ||
| Object.assign({}, documentNumberCheckDigitTemplate, { | ||
| line: 0, | ||
| start: 14, | ||
| end: 15, | ||
| related: [ | ||
| { | ||
| line: 0, | ||
| start: 5, | ||
| end: 14 | ||
| } | ||
| ] | ||
| }), | ||
| Object.assign({}, expirationDateTemplate, { | ||
| line: 0, | ||
| start: 15, | ||
| end: 21 | ||
| }), | ||
| Object.assign({}, lastNameTemplate, { | ||
| line: 0, | ||
| start: 21, | ||
| end: 29, | ||
| parser: parseLastName | ||
| }), | ||
| Object.assign({}, compositeCheckDigitTemplate, { | ||
| line: 0, | ||
| start: 29, | ||
| end: 30, | ||
| related: [ | ||
| { | ||
| line: 0, | ||
| start: 0, | ||
| end: 29 | ||
| } | ||
| ] | ||
| }) | ||
| ].map(createFieldParser); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,7 @@ module.exports = [ | |
| }, | ||
| Object.assign({}, documentNumberTemplate, { | ||
| line: 1, | ||
| start: 7, | ||
| start: 0, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this change? The 3 fields are separated in the description of wikipedia. They can always be reconcatenated later
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://www.consilium.europa.eu/prado/en/FRA-BO-02002/image-7890.html I can make a pull request without this change if you don't want to break the backward compatibility.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation. This LGTM then. No problem, we'll make a major release with all the changes. |
||
| end: 12 | ||
| }), | ||
| Object.assign({}, documentNumberCheckDigitTemplate, { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = function parseDocumentCode(source) { | ||
| // french driving license number | ||
| if (!source.match(/^[0-9]{2}[A-Z]{2}[0-9]{5}$/)) { | ||
| throw new Error( | ||
| `invalid document number: ${source}.` | ||
| ); | ||
| } | ||
| return source; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| 'use strict'; | ||
|
|
||
| var parseText = require('../../parseText'); | ||
|
|
||
| module.exports = function parseLastName(source) { | ||
| const parsed = parseText(source, /^[A-Z<]+$/); | ||
| return { | ||
| value: parsed, | ||
| start: 0, | ||
| end: parsed.length | ||
| }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = function parseBapConfiguration(bapConfig) { | ||
| switch (bapConfig) { | ||
| case '1': | ||
| case 'P': | ||
| case 'N': | ||
| case '<': | ||
| return bapConfig; | ||
| default: | ||
| throw new Error( | ||
| `invalid BAP configuration code: ${bapConfig}. Must be 1, P, N or <` | ||
| ); | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = function parseDocumentCode(source) { | ||
| if (source !== 'D') { | ||
| throw new Error(`invalid document code: ${source}. Must be D`); | ||
| } | ||
| return source; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, as I remember I had some problems with Jest and after googling this helped me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it I get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you try with
testEnvironment: "node"instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it helps.
Thanks!