mirror of
https://github.com/selfxyz/self.git
synced 2026-02-09 05:46:01 -05:00
29 lines
777 B
JavaScript
29 lines
777 B
JavaScript
|
|
import { NativeModules } from 'react-native'
|
|
|
|
const { RNPassportReader } = NativeModules
|
|
const DATE_REGEX = /^\d{6}$/
|
|
|
|
module.exports = {
|
|
...RNPassportReader,
|
|
scan
|
|
}
|
|
|
|
function scan ({ documentNumber, dateOfBirth, dateOfExpiry, quality=1 }) {
|
|
assert(typeof documentNumber === 'string', 'expected string "documentNumber"')
|
|
assert(isDate(dateOfBirth), 'expected string "dateOfBirth" in format "yyMMdd"')
|
|
assert(isDate(dateOfExpiry), 'expected string "dateOfExpiry" in format "yyMMdd"')
|
|
return RNPassportReader.scan({ documentNumber, dateOfBirth, dateOfExpiry, quality })
|
|
}
|
|
|
|
|
|
function assert (statement, err) {
|
|
if (!statement) {
|
|
throw new Error(err || 'Assertion failed')
|
|
}
|
|
}
|
|
|
|
function isDate (str) {
|
|
return typeof str === 'string' && DATE_REGEX.test(str)
|
|
}
|