@@ -30,22 +30,23 @@ module.exports = {
30
30
}
31
31
32
32
// street address line 1 & 2
33
- const streetAddressLineIndex = rawText . findIndex ( ( line ) => line . match ( / ^ 8 ( .* ) $ / g) ) ;
33
+ let streetAddressLineIndex = rawText . findIndex ( ( line ) => line . match ( / ^ 8 ( .* ) $ / g) ) ;
34
+ const lineWithCityStateZipIndex = rawText . findIndex ( ( line ) => line . match ( / ^ ( [ A - Z a - z \s ] + , ? ) ? [ A - Z ] { 2 } \d + - ? \d + ?$ / g) ) ;
35
+ if ( streetAddressLineIndex < 0 && lineWithCityStateZipIndex >= 0 ) {
36
+ streetAddressLineIndex = lineWithCityStateZipIndex - 1 ;
37
+ }
34
38
let street_address_line_1 = rawText [ streetAddressLineIndex ] ;
35
39
let street_address_line_2 = rawText [ streetAddressLineIndex + 1 ] ;
36
40
37
41
if ( street_address_line_1 && street_address_line_1 . substr ( 0 , 2 ) === '8 ' ) {
38
42
street_address_line_1 = street_address_line_1 . replace ( '8 ' , '' ) ;
39
43
}
40
-
41
44
if ( street_address_line_1 === '8' ) {
42
45
street_address_line_1 = undefined ;
43
46
}
44
47
45
48
// city, state, zip code
46
- const lineWithCityStateZipIndex = rawText . findIndex ( ( line ) => line . match ( / ^ ( [ A - Z a - z \s ] + , ) ? [ A - Z ] { 2 } \d + \- ? \d + ?$ / g) ) ;
47
49
const lineWithCityStateZip = rawText [ lineWithCityStateZipIndex ] ;
48
-
49
50
if ( ! street_address_line_1 && lineWithCityStateZipIndex > 0 ) {
50
51
street_address_line_1 = rawText [ lineWithCityStateZipIndex - 1 ] ;
51
52
}
@@ -55,7 +56,7 @@ module.exports = {
55
56
street_address_line_2 = '' ;
56
57
}
57
58
58
- const matchedCityStateZip = / ^ ( [ A - Z a - z \s ] + , ) ? ( [ A - Z ] { 2 } ) ( \d + \ -? \d + ?) $ / g. exec ( lineWithCityStateZip ) || [ ] ;
59
+ const matchedCityStateZip = / ^ ( [ A - Z a - z \s ] + , ? ) ? ( [ A - Z ] { 2 } ) ( \d + - ? \d + ?) $ / g. exec ( lineWithCityStateZip ) || [ ] ;
59
60
let [ , city ] = matchedCityStateZip ;
60
61
const [ , , state , zip_code ] = matchedCityStateZip ;
61
62
if ( city ) {
0 commit comments