feat: also send original object into format function
This commit is contained in:
parent
c59d163a54
commit
3ae0a05b6e
1 changed files with 11 additions and 8 deletions
|
|
@ -5,7 +5,10 @@ type MRZ = {
|
|||
zone: string[];
|
||||
};
|
||||
|
||||
type Field = { field: string; format?: (value: string) => string };
|
||||
type Field = {
|
||||
field: string;
|
||||
format?: (value: string, obj?: Record<string, string>) => string;
|
||||
};
|
||||
type FieldList = Record<string, Field>;
|
||||
|
||||
const DEFAULT_FIELD = {
|
||||
|
|
@ -15,30 +18,30 @@ const DEFAULT_FIELD = {
|
|||
documentNoCheck: { field: 'doc_number_check' },
|
||||
name: {
|
||||
field: 'full_name',
|
||||
format: (value: string) => value.replace(/0/, 'O'),
|
||||
format: (value, _) => value.replace(/0/, 'O'),
|
||||
},
|
||||
country: {
|
||||
field: 'country',
|
||||
format: (value: string) => value.replace(/0/, 'O'),
|
||||
format: (value, _) => value.replace(/0/, 'O'),
|
||||
},
|
||||
nationality: {
|
||||
field: 'country',
|
||||
format: (value: string) => value.replace(/0/, 'O'),
|
||||
format: (value, _) => value.replace(/0/, 'O'),
|
||||
},
|
||||
gender: { field: 'sex' },
|
||||
birthDate: {
|
||||
field: 'birth_date',
|
||||
format: (value: string) => moment(value, 'YYMMDD').format('YYYY-MM-DD'),
|
||||
format: (value, _) => moment(value, 'YYMMDD').format('YYYY-MM-DD'),
|
||||
},
|
||||
birthDateCheck: { field: 'birth_date_check' },
|
||||
expireDate: {
|
||||
field: 'expire_date',
|
||||
format: (value: string) => moment(value, 'YYMMDD').format('YYYY-MM-DD'),
|
||||
format: (value, _) => moment(value, 'YYMMDD').format('YYYY-MM-DD'),
|
||||
},
|
||||
expireDateCheck: { field: 'expire_date_check' },
|
||||
optionalData: {
|
||||
field: 'optional_data',
|
||||
format: (value: string) => moment(value, 'YYMMDD').format('YYYY-MM-DD'),
|
||||
format: (value, _) => moment(value, 'YYMMDD').format('YYYY-MM-DD'),
|
||||
},
|
||||
optionalDataCheck: { field: 'optional_data_check' },
|
||||
lineCheck: { field: 'line_check' },
|
||||
|
|
@ -132,7 +135,7 @@ function mrzCleanResult(obj: Record<string, string>) {
|
|||
|
||||
for (const value of Object.values(DEFAULT_FIELD)) {
|
||||
if (obj[value.field] && 'format' in value) {
|
||||
obj[value.field] = value.format(obj[value.field]);
|
||||
obj[value.field] = value.format(obj[value.field], obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue