Giter VIP home page Giter VIP logo

addresser's Introduction

addresser Build Status Coverage Status npm version

A Node.js library for parsing property addresses. Also includes other address utilities such as a function that returns a random city.

Installation

npm install addresser

Usage

var addresser = require('addresser');

// Isn't confused by duplicate place names
console.log(addresser.parseAddress("400 South Orange Ave, South Orange , NJ 07079"););

{ id: '400-South-Orange-Ave,-South-Orange,-NJ-07079',
  formattedAddress: '400 South Orange Ave, South Orange, NJ 07079',
  zipCode: '07079',
  stateAbbreviation: 'NJ',
  stateName: 'New Jersey',
  placeName: 'South Orange',
  addressLine1: '400 South Orange Ave',
  streetNumber: '400',
  streetSuffix: 'Ave',
  streetName: 'South Orange' }

// Handles extra whitespace
console.log(addresser.parseAddress("123 Double  Space    St, Conway, SC 29526"));

{ id: '123-Double-Space-St,-Conway,-SC-29526',
  formattedAddress: '123 Double Space St, Conway, SC 29526',
  streetNumber: '123',
  streetSuffix: 'St',
  streetName: 'Double Space',
  addressLine1: '123 Double Space St',
  placeName: 'Conway',
  stateAbbreviation: 'SC',
  stateName: 'South Carolina',
  zipCode: '29526' }

// normalizes to Title Case  
console.log(addresser.parseAddress("123 Main St, Conway, south carolina 29526-1234"));

{ id: '123-Main-St,-Conway,-SC-29526',
  formattedAddress: '123 Main St, Conway, SC 29526',
  streetNumber: '123',
  streetSuffix: 'St',
  streetName: 'Main',
  addressLine1: '123 Main St',
  placeName: 'Conway',
  stateAbbreviation: 'SC',
  stateName: 'South Carolina',
  zipCode: '29526',
  zipCodePlusFour: '29526-1234'}

// Handles secondary address lines even without delimiters.
// Normalizes street types to standard abbreviations.
console.log(addresser.parseAddress("1301 Columbia College Drive Unit 101 Columbia, SC 29203"));

{ id: '1301-Columbia-College-Dr,-Unit-101,-Columbia,-SC-29203',
  formattedAddress: '1301 Columbia College Dr, Unit 101, Columbia, SC 29203',
  zipCode: '29203',
  stateAbbreviation: 'SC',
  stateName: 'South Carolina',
  placeName: 'Columbia',
  addressLine1: '1301 Columbia College Dr',
  addressLine2: 'Unit 101',
  streetNumber: '1301',
  streetSuffix: 'Dr',
  streetName: 'Columbia College' }       

// Handles trailing street directionals  
console.log(addresser.parseAddress("300 BOYLSTON AVE E SEATTLE WA 98102"));
{ id: '300-Boylston-Ave-E,-Seattle,-WA-98102',
  formattedAddress: '300 Boylston Ave E, Seattle, WA 98102',
  zipCode: '98102',
  stateAbbreviation: 'WA',
  stateName: 'Washington',
  placeName: 'Seattle',
  addressLine1: '300 Boylston Ave E',
  streetDirection: 'E',
  streetNumber: '300',
  streetSuffix: 'Ave',
  streetName: 'Boylston' }

// Handles post office boxes 
console.log(addresser.parseAddress("PO BOX 333 SEATTLE WA 98102"));
{ id: 'PO-BOX-333,-Seattle,-WA-98102',
  formattedAddress: 'PO BOX 333, Seattle, WA 98102',
  zipCode: '98102',
  stateAbbreviation: 'WA',
  stateName: 'Washington',
  placeName: 'Seattle',
  addressLine1: 'PO BOX 333' }

// Return a random valid city 
console.log(addresser.randomCity());
{ city: 'Irwin',
  state: 'ID' }

// Return an object containing all cities
console.log(addresser.cities());
{ 
  ...
  WI:
    [ 
      'Black River Falls',
      'Heafford Junction',
      'Washington Island',
      ...
    ],
  WY:
    [ 
      'Yellowstone National Park',
      'Saint Stephens',
      'Little America',
      ...
    ]
} 

NOTE: Currently addresser supports only US & Canada addresses.

Functions

parseAddress

parseAddress will accept an address string and convert it into structured address data. Addresser is designed to be flexible and forgiving in terms of the formatting of the address string but it does assume a general order of street data, city data and state data from left to right. parseAddress will normalize state names and abbreviations and can recognize state data regardless of case or format.

parseAddress will try to validate that the city provided is valid for the given state. This allows for more intelligent parsing logic when propert delimiters are not used. parseAddress also normalizes street types to standard abberviations ie. Drive to Dr, Street to St, etc.

parseAddress creates a unique id for all addresses based on the parsed values. Currently there is no easy, universal ID available for property addresses and this package should help bridge that gap for developers who need to cross reference property data across multiple data sources. An id is generated only if all the address components are present including street address, city, state and zipcode.

getRandomCity

The getRandomCity function can be used to generate a random valid city. This can be helpful when testing.

cities

The cities function returns a JSON object that contains a list of all known cities and states. The structure is as follows:

{ 
  ...
  WI:
    [ 
      'Black River Falls',
      'Heafford Junction',
      'Washington Island',
      ...
    ],
  WY:
    [ 
      'Yellowstone National Park',
      'Saint Stephens',
      'Little America',
      ...
    ]
}

Tests

npm test

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

addresser's People

Contributors

arthurg avatar dependabot[bot] avatar moneals avatar nikhilw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

addresser's Issues

Incomplete postal code (canada) leads to 'State not found'

Hello, in some cases where we only have canadian postal code first part, parser is mindfuck and couldn't find state:

1427 Rue de Normandie, Deux-Montagnes, QC J7R, Canada

if at line 121, we add something like:

else if(countrySection === 'Canada' && stateString.match(/\b[A-Z]\d[A-Z]\b/)){
      result.zipCode = stateString.match(/\b[A-Z]\d[A-Z]\b/)[0];
      result.zipCodeIsIncomplete=true;
      stateString = stateString.substring(0, stateString.length - result.zipCode.length).trim();
    }

I think it would "fix" some results... or at least it could break less things? What you think?

Not able to parse valid US addresses

Please see some examples of valid addresses that this library is not able to parse below.

These have been verified as actual physical addresses that do exist, so it's not a formatting error on the input side:

  • 1300 Providence Ridge Turn, North Chesterfield, VA 23236 ("Too many address lines" error)
  • 5210 Castlewood Rd Apt E, North Chesterfield, VA 23234 ("Too many address lines" error)
  • 2505 Pocoshock Pl Ste 103, North Chesterfield, VA 23235 ("Too many address lines" error)
  • 186 N Harrisburg St Apt 3, Oberlin, PA 17113 ("Too many address lines" error)
  • 400 Franklin St Apt 205, West Reading, PA 19611 ("Too many address lines" error)
  • 315 Salem St Apt A, West Pittston, PA 18643 ("Too many address lines" error)
  • 485 State St Apt B, Steelton, PA 17113 ("Too many address lines" error)
  • 67A Alameda De Las Pulgas, Redwood City, CA 94062 ("Invalid street address data" error)

Where is version 1.1.20

The published version is 1.1.20, but there are no tags with that version, and the master branch still says 1.1.19.

Not able to parse US address

1177 Avenue of the Americas, Fl 7, New York City, New York 10036, US

I am not able to parse this US address gives me a error of "Can not parse address. More than two address lines."
and sending the address in lower case doesn't finds the country as US. i think u should have case insensitive check there

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.