diff --git a/lib/documentTypes/srpBill.js b/lib/documentTypes/srpBill.js index a197e37..17a6a16 100644 --- a/lib/documentTypes/srpBill.js +++ b/lib/documentTypes/srpBill.js @@ -39,25 +39,31 @@ module.exports = { last_name = fullNameLine.split(' ').slice(-1).join(' '); } + let last10Lines = rawText.slice(-10); + if (last10Lines.filter((line) => line === 'PRESCOTT AZ 86304-8062').length === 1) { + // remove SRP address + last10Lines = last10Lines.filter((line) => ( + line !== 'PO BOX 80062' + && line !== 'PRESCOTT AZ 86304-8062' + )); + } // street address line 1 & 2 - const last5Lines = rawText.slice(-5); - let street_address_line_1; let street_address_line_2; let cityStateZipCodeLine = []; // city, state, zip code - const lineWithCityStateZipCodeIndex = last5Lines.findIndex((line) => line.match(/^([A-Za-z\s]+) ([A-Z]{2}) (\d+-\d+)$/g)); + const lineWithCityStateZipCodeIndex = last10Lines.findIndex((line) => line.match(/^([A-Za-z\s]+) ([A-Z]{2}) (\d+-\d+)$/g)); if (lineWithCityStateZipCodeIndex) { - street_address_line_1 = last5Lines[lineWithCityStateZipCodeIndex - 1]; + street_address_line_1 = last10Lines[lineWithCityStateZipCodeIndex - 1]; street_address_line_2 = ''; - cityStateZipCodeLine = last5Lines[lineWithCityStateZipCodeIndex].split(' '); + cityStateZipCodeLine = last10Lines[lineWithCityStateZipCodeIndex].split(' '); } const [city, state, zip_code] = cityStateZipCodeLine; // bill amount let bill_amount = keyValues['PLEASE PAY']; - if(!bill_amount || !bill_amount.length) { + if (!bill_amount || !bill_amount.length) { bill_amount = keyValues['This Month\'s Charges']; }