Comparing version 3.0.5 to 3.1.0
{ | ||
"name": "mrz", | ||
"version": "3.0.5", | ||
"version": "3.1.0", | ||
"description": "Parse MRZ (Machine Readable Zone) from identity documents", | ||
@@ -43,3 +43,3 @@ "main": "./src/index.js", | ||
"eslint": "^4.16.0", | ||
"eslint-config-cheminfo": "^1.14.0", | ||
"eslint-config-cheminfo": "^1.15.1", | ||
"eslint-plugin-jest": "^21.7.0", | ||
@@ -46,0 +46,0 @@ "jest": "^22.1.4" |
@@ -48,2 +48,3 @@ # mrz | ||
* SWISS_DRIVING_LICENSE | ||
* FRENCH_NATIONAL_ID | ||
@@ -92,2 +93,6 @@ #### result.valid | ||
### French national id | ||
https://fr.wikipedia.org/wiki/Carte_nationale_d%27identit%C3%A9_en_France#Codage_Bande_MRZ_(lecture_optique) | ||
## License | ||
@@ -94,0 +99,0 @@ |
@@ -7,3 +7,4 @@ 'use strict'; | ||
TD3: 'TD3', | ||
SWISS_DRIVING_LICENSE: 'SWISS_DRIVING_LICENSE' | ||
SWISS_DRIVING_LICENSE: 'SWISS_DRIVING_LICENSE', | ||
FRENCH_NATIONAL_ID: 'FRENCH_NATIONAL_ID' | ||
}; | ||
@@ -10,0 +11,0 @@ Object.freeze(formats); |
@@ -62,2 +62,8 @@ 'use strict'; | ||
const issueDateTemplate = { | ||
label: 'Issue date', | ||
field: 'issueDate', | ||
parser: require('../parsers/parseDate') | ||
}; | ||
const firstNameTemplate = { | ||
@@ -91,2 +97,3 @@ label: 'First name', | ||
birthDateCheckDigitTemplate, | ||
issueDateTemplate, | ||
compositeCheckDigitTemplate, | ||
@@ -93,0 +100,0 @@ firstNameTemplate, |
@@ -15,4 +15,10 @@ 'use strict'; | ||
return parsers.TD1(lines); | ||
case 36: | ||
return parsers.TD2(lines); | ||
case 36: { | ||
const endLine1 = lines[0].substr(30, 36); | ||
if (endLine1.match(/[0-9]/)) { | ||
return parsers.FRENCH_NATIONAL_ID(lines); | ||
} else { | ||
return parsers.TD2(lines); | ||
} | ||
} | ||
case 44: | ||
@@ -24,3 +30,3 @@ return parsers.TD3(lines); | ||
throw new Error( | ||
'unrecognized document format. First line of input must have 30 (TD1), 36 (TD2), 44 (TD3) or 9 (Swiss Driving License) characters' | ||
'unrecognized document format. First line of input must have 30 (TD1), 36 (TD2 or French National Id), 44 (TD3) or 9 (Swiss Driving License) characters' | ||
); | ||
@@ -27,0 +33,0 @@ } |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const parseSwissDrivingLicense = require('./swissDrivingLicense'); | ||
const parseFrenchNationalId = require('./frenchNationalId'); | ||
@@ -13,3 +14,4 @@ module.exports = { | ||
TD3: parseTD3, | ||
SWISS_DRIVING_LICENSE: parseSwissDrivingLicense | ||
SWISS_DRIVING_LICENSE: parseSwissDrivingLicense, | ||
FRENCH_NATIONAL_ID: parseFrenchNationalId | ||
}; |
@@ -10,2 +10,9 @@ 'use strict'; | ||
lines = checkLines(lines); | ||
if (lines.length !== 3) { | ||
throw new Error( | ||
`invalid number of lines: ${ | ||
lines.length | ||
}: Must be 3 for ${SWISS_DRIVING_LICENSE}` | ||
); | ||
} | ||
if (lines[0].length !== 9) { | ||
@@ -12,0 +19,0 @@ throw new Error( |
@@ -10,2 +10,7 @@ 'use strict'; | ||
lines = checkLines(lines); | ||
if (lines.length !== 3) { | ||
throw new Error( | ||
`invalid number of lines: ${lines.length}: Must be 3 for ${TD1}` | ||
); | ||
} | ||
lines.forEach((line, index) => { | ||
@@ -16,3 +21,3 @@ if (line.length !== 30) { | ||
line.length | ||
}. Must be 30 for TD1` | ||
}. Must be 30 for ${TD1}` | ||
); | ||
@@ -19,0 +24,0 @@ } |
@@ -10,2 +10,7 @@ 'use strict'; | ||
lines = checkLines(lines); | ||
if (lines.length !== 2) { | ||
throw new Error( | ||
`invalid number of lines: ${lines.length}: Must be 2 for ${TD2}` | ||
); | ||
} | ||
lines.forEach((line, index) => { | ||
@@ -12,0 +17,0 @@ if (line.length !== 36) { |
@@ -10,2 +10,7 @@ 'use strict'; | ||
lines = checkLines(lines); | ||
if (lines.length !== 2) { | ||
throw new Error( | ||
`invalid number of lines: ${lines.length}: Must be 2 for ${TD3}` | ||
); | ||
} | ||
lines.forEach((line, index) => { | ||
@@ -12,0 +17,0 @@ if (line.length !== 44) { |
'use strict'; | ||
module.exports = function parseDate(value) { | ||
if (!value.match(/^[0-9<]{6}$/)) { | ||
if (!value.match(/^[0-9<]{4,6}$/)) { | ||
throw new Error(`invalid date: ${value}`); | ||
} | ||
const month = value.substring(2, 4); | ||
const day = value.substring(4, 6); | ||
if (month !== '<<' && (month < 1 || month > 12)) { | ||
throw new Error(`invalid date month: ${month}`); | ||
} | ||
if (day !== '<<' && (day < 1 || day > 31)) { | ||
throw new Error(`invalid date day: ${day}`); | ||
if (value.length === 6) { | ||
const day = value.substring(4, 6); | ||
if (day !== '<<' && (day < 1 || day > 31)) { | ||
throw new Error(`invalid date day: ${day}`); | ||
} | ||
} | ||
@@ -16,0 +19,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56687
54
2062
110