File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-disable camelcase */
2
2
const moment = require ( 'moment' ) ;
3
+ const stringSimilarity = require ( 'string-similarity' ) ;
3
4
4
5
module . exports = {
5
6
@@ -30,6 +31,7 @@ module.exports = {
30
31
} ,
31
32
32
33
extractor : ( keyValues , rawText ) => {
34
+ const keys = Object . keys ( keyValues ) ;
33
35
const [ , fullNameLine ] = rawText ;
34
36
let first_name ;
35
37
let last_name ;
@@ -61,10 +63,29 @@ module.exports = {
61
63
}
62
64
63
65
// bill amount
64
- const bill_amount = keyValues [ 'Total Amount Due' ] ;
66
+ let bill_amount = keyValues [ keys [ stringSimilarity . findBestMatch (
67
+ 'Total Amount Due' ,
68
+ keys ,
69
+ ) . bestMatchIndex ] ] ;
70
+ if ( ! bill_amount || ! bill_amount . length ) {
71
+ bill_amount = keyValues [ keys [ stringSimilarity . findBestMatch (
72
+ 'Total amount due:' ,
73
+ keys ,
74
+ ) . bestMatchIndex ] ] ;
75
+ }
65
76
66
77
// bill date
67
- const bill_date = keyValues [ 'Bill Date:' ] ;
78
+ let bill_date = keyValues [ keys [ stringSimilarity . findBestMatch (
79
+ 'Due Date' ,
80
+ keys ,
81
+ ) . bestMatchIndex ] ] ;
82
+ if ( ! bill_date || ! bill_date . length || ! bill_date . match ( / ^ ( \d { 1 , 2 } ) \/ ( \d { 1 , 2 } ) \/ ( \d { 4 } ) $ / g) ) {
83
+ const lineWithDueDate = rawText . findIndex ( ( line ) => line . match ( / ^ D u e D a t e $ / g) ) ;
84
+ bill_date = rawText . slice ( lineWithDueDate - 5 , lineWithDueDate + 5 ) . filter ( ( line ) => (
85
+ line . match ( / ^ ( \d { 1 , 2 } ) \/ ( \d { 1 , 2 } ) \/ ( \d { 4 } ) $ / g)
86
+ ) ) ;
87
+ bill_date = bill_date . length ? bill_date [ 0 ] : '' ;
88
+ }
68
89
69
90
// account number
70
91
const account_number = keyValues [ 'Account Number:' ] ;
You can’t perform that action at this time.
0 commit comments