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[];
|
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>;
|
type FieldList = Record<string, Field>;
|
||||||
|
|
||||||
const DEFAULT_FIELD = {
|
const DEFAULT_FIELD = {
|
||||||
|
|
@ -15,30 +18,30 @@ const DEFAULT_FIELD = {
|
||||||
documentNoCheck: { field: 'doc_number_check' },
|
documentNoCheck: { field: 'doc_number_check' },
|
||||||
name: {
|
name: {
|
||||||
field: 'full_name',
|
field: 'full_name',
|
||||||
format: (value: string) => value.replace(/0/, 'O'),
|
format: (value, _) => value.replace(/0/, 'O'),
|
||||||
},
|
},
|
||||||
country: {
|
country: {
|
||||||
field: 'country',
|
field: 'country',
|
||||||
format: (value: string) => value.replace(/0/, 'O'),
|
format: (value, _) => value.replace(/0/, 'O'),
|
||||||
},
|
},
|
||||||
nationality: {
|
nationality: {
|
||||||
field: 'country',
|
field: 'country',
|
||||||
format: (value: string) => value.replace(/0/, 'O'),
|
format: (value, _) => value.replace(/0/, 'O'),
|
||||||
},
|
},
|
||||||
gender: { field: 'sex' },
|
gender: { field: 'sex' },
|
||||||
birthDate: {
|
birthDate: {
|
||||||
field: 'birth_date',
|
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' },
|
birthDateCheck: { field: 'birth_date_check' },
|
||||||
expireDate: {
|
expireDate: {
|
||||||
field: 'expire_date',
|
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' },
|
expireDateCheck: { field: 'expire_date_check' },
|
||||||
optionalData: {
|
optionalData: {
|
||||||
field: 'optional_data',
|
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' },
|
optionalDataCheck: { field: 'optional_data_check' },
|
||||||
lineCheck: { field: 'line_check' },
|
lineCheck: { field: 'line_check' },
|
||||||
|
|
@ -132,7 +135,7 @@ function mrzCleanResult(obj: Record<string, string>) {
|
||||||
|
|
||||||
for (const value of Object.values(DEFAULT_FIELD)) {
|
for (const value of Object.values(DEFAULT_FIELD)) {
|
||||||
if (obj[value.field] && 'format' in value) {
|
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