Skip to content

Commit

Permalink
Bugfix | Parser | Short Codes for Intersection Addresses (#14)
Browse files Browse the repository at this point in the history
* Bring back old test cases

* Fix parsing of intersection abbrevs

* Update type

* Bump
  • Loading branch information
PapaStef authored Jul 19, 2021
1 parent 0936d2b commit 16b68b8
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 5 deletions.
184 changes: 183 additions & 1 deletion __tests__/test-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ export const existingTests: AddressTestCaseMap = {
short_street_type: 'HY',
state: 'CA'
},
'115 Broadway San Francisco CA': {
number: '115',
street: 'Broadway',
city: 'San Francisco',
state: 'CA'
},
'7800 Mill Station Rd, Sebastopol, CA 95472': {
number: '7800',
street: 'Mill Station',
Expand All @@ -184,6 +190,13 @@ export const existingTests: AddressTestCaseMap = {
short_street_type: 'RD',
zip: '95472'
},
'1005 State Highway 116 Sebastopol CA 95472': {
number: '1005',
street: 'State Highway 116',
city: 'Sebastopol',
state: 'CA',
zip: '95472'
},
'1600 Pennsylvania Ave. Washington DC': {
number: '1600',
street: 'Pennsylvania',
Expand All @@ -200,6 +213,36 @@ export const existingTests: AddressTestCaseMap = {
short_street_type: 'AV',
state: 'DC'
},
'48S 400E, Salt Lake City UT': {
number: '48',
prefix: 'S',
street: '400',
suffix: 'E',
city: 'Salt Lake City',
state: 'UT'
},
'550 S 400 E #3206, Salt Lake City UT 84111': {
number: '550',
prefix: 'S',
street: '400',
suffix: 'E',
sec_unit_type: '#',
sec_unit_num: '3206',
city: 'Salt Lake City',
state: 'UT',
zip: '84111'
},
'6641 N 2200 W Apt D304 Park City, UT 84098': {
number: '6641',
prefix: 'N',
street: '2200',
suffix: 'W',
sec_unit_type: 'Apt',
sec_unit_num: 'D304',
city: 'Park City',
state: 'UT',
zip: '84098'
},
'100 South St, Philadelphia, PA': {
number: '100',
street: 'South',
Expand All @@ -225,6 +268,98 @@ export const existingTests: AddressTestCaseMap = {
short_street_type: 'RD',
state: 'CA'
},
'Mission & Valencia San Francisco CA': {
street1: 'Mission',
street2: 'Valencia',
city: 'San Francisco',
state: 'CA',
type2: '',
type1: ''
},
'Mission & Valencia, San Francisco CA': {
street1: 'Mission',
street2: 'Valencia',
city: 'San Francisco',
state: 'CA',
type2: '',
type1: ''
},
'Mission St and Valencia St San Francisco CA': {
street1: 'Mission',
type1: 'St',
street2: 'Valencia',
type2: 'St',
city: 'San Francisco',
state: 'CA',
short_street_type1: 'ST',
short_street_type2: 'ST'
},
'Mission St and Valencia St': {
street1: 'Mission',
type1: 'St',
street2: 'Valencia',
type2: 'St',
short_street_type1: 'ST',
short_street_type2: 'ST'
},
'Mission St & Valencia St San Francisco CA': {
street1: 'Mission',
type1: 'St',
street2: 'Valencia',
type2: 'St',
city: 'San Francisco',
state: 'CA',
short_street_type1: 'ST',
short_street_type2: 'ST'
},
'Mission and Valencia Sts San Francisco CA': {
street1: 'Mission',
street2: 'Valencia',
type2: 'St',
city: 'San Francisco',
state: 'CA',
type1: 'St',
short_street_type1: 'ST',
short_street_type2: 'ST'
},
'Mission & Valencia Sts. San Francisco CA': {
street1: 'Mission',
street2: 'Valencia',
type2: 'St',
city: 'San Francisco',
state: 'CA',
type1: 'St',
short_street_type1: 'ST',
short_street_type2: 'ST'
},
'Mission and Valencia Sts.': {
street1: 'Mission',
type1: 'St',
street2: 'Valencia',
type2: 'St',
short_street_type1: 'ST',
short_street_type2: 'ST'
},
'Mission & Valencia Streets San Francisco CA': {
street1: 'Mission',
street2: 'Valencia',
type2: 'St',
city: 'San Francisco',
state: 'CA',
type1: 'St',
short_street_type1: 'ST',
short_street_type2: 'ST'
},
'Mission Avenue and Valencia Street San Francisco CA': {
street1: 'Mission',
type1: 'Ave',
street2: 'Valencia',
type2: 'St',
city: 'San Francisco',
state: 'CA',
short_street_type1: 'AV',
short_street_type2: 'ST'
},
'1 First St, e San Jose CA': {
number: '1',
street: 'First',
Expand All @@ -233,6 +368,12 @@ export const existingTests: AddressTestCaseMap = {
short_street_type: 'ST',
state: 'CA'
},
'123 Maple Rochester, New York': {
number: '123',
street: 'Maple',
city: 'Rochester',
state: 'NY'
},
'233 S Wacker Dr 60606-6306': {
number: '233',
prefix: 'S',
Expand Down Expand Up @@ -306,7 +447,27 @@ export const existingTests: AddressTestCaseMap = {
short_street_type: 'RD',
state: 'LA'
},
"'45 Quaker Ave, Ste 105'": {
'36401 County Road 43, Eaton, CO 80615': {
number: '36401',
street: 'County Road 43',
city: 'Eaton',
state: 'CO',
zip: '80615'
},
'1234 COUNTY HWY 60E, Town, CO 12345': {
number: '1234',
street: 'COUNTY HWY 60',
suffix: 'E',
city: 'Town',
state: 'CO',
zip: '12345'
},
'321 S. Washington': {
number: '321',
prefix: 'S',
street: 'Washington'
},
'\'45 Quaker Ave, Ste 105\'': {
number: '45',
street: 'Quaker',
type: 'Ave',
Expand All @@ -323,6 +484,27 @@ export const existingTests: AddressTestCaseMap = {
short_street_type: 'RO',
zip: '48084'
},
'Post office Box 3094 Collierville TN 38027': {
sec_unit_type: 'Post office Box',
sec_unit_num: '3094',
city: 'Collierville',
state: 'TN',
zip: '38027'
},
'P.O. box 3094 Collierville TN 38027': {
sec_unit_type: 'PO box',
sec_unit_num: '3094',
city: 'Collierville',
state: 'TN',
zip: '38027'
},
'POBox 3094 Collierville TN 38027': {
sec_unit_type: 'POBox',
sec_unit_num: '3094',
city: 'Collierville',
state: 'TN',
zip: '38027'
},
'N95W18855 Jay Dr, Menomonee Falls, WI 53051': {
number: 'N95W18855',
street: 'Jay',
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bankrate/parse-address",
"version": "2.1.1",
"version": "2.2.0",
"description": "US Street Address Parser",
"main": "dist/parser.js",
"scripts": {
Expand Down
6 changes: 4 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ export class AddressParser {

;['type', 'type1', 'type2'].forEach(function (key) {
if (key in parsed) {
parsed[key] = parsed[key].charAt(0).toUpperCase() + parsed[key].slice(1).toLowerCase()

// Map the address short code
const lowerCaseType = parsed[key].toLowerCase()
parsed[`short_street_${key}`] = self.findStreetTypeShortCode(lowerCaseType)

parsed[key] = parsed[key].charAt(0).toUpperCase() + parsed[key].slice(1).toLowerCase()
}
})

Expand Down Expand Up @@ -247,10 +247,12 @@ export class AddressParser {

if (parts.type2 && !parts.type1 || (parts.type1 === parts.type2)) {
let type = parts.type2
const short_street_type = parts.short_street_type2
type = XRegExp.replace(type, /s\W*$/, '')

if (XRegExp('^' + this.addressMatch.type + '$', 'ix').test(type)) {
parts.type1 = parts.type2 = type
parts.short_street_type1 = parts.short_street_type2 = short_street_type
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface ParsedAddress {
zip?: string
plus4?: string
short_street_type?: string
short_street_type1?: string
short_street_type2?: string
}

export interface AddressTestCase extends ParsedAddress {
Expand Down

0 comments on commit 16b68b8

Please sign in to comment.