npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

snailmailaddressparser

v0.1.27

Published

A Javascript library to parse snail mail addresses into components

Downloads

49

Readme

SnailMailAddressParser

Build Status

A Javascript library for parsing valid address strings into their constituent elements.

It is hosted on GitHub at brianmhunt/SnailMailAddressParser.

Purpose

This project exists to crowdsource the difficult problem of parsing addresses. It is intended to assist with the verification that addresses are properly formatted, and where they are properly formatted to parse and return their respective constituents.

At the moment this project does not aim to verify that an address is consistent with reality. For example, this library shall not verify that a given address in California has a local zip-code.

Usage

An example in node.js:

> smap = require('SnailMailAddressParser')

> smap.parse("100 Bay Street\nToronto, ON M5H 1T1\nCanada")
{ suite: '',
  addressee: '',
  street_number: '100',
  street_name_2: '',
  municipality: 'Toronto',
  province: 'ON',
  postal: 'M5H 1T1',
  country: 'Canada',
  street_name: 'Bay Street' }

API

smap = require('SnailMailAddressParser')

Return an instance of the Address Parser. Uses the amdefine module for Node.js compatibility.

smap.parse(address_string, defaultCountry)

Parse the address_string, returning an object or throwing an exception where the address cannot be parsed.

If the address_string ends in a valid country name, that country is used, otherwise defaultCountry is used.

The object returned will contain the elements corresponding to the given country.

TODO Where the address_string is ambiguous, return a message indicating that the string is ambiguous, and provide the multiple matching results so that the user can choose which is correct.

Contributing

Drop me a message or send along a pull request on GitHub. I would be delighted to co-ordinate support for addresses that may interest you.

The project is intended to divide-and-conquer. Each country has a strategy for parsing addresses, which strategy may be broken down into a variety of sub-strategies. In this way, I hope edge cases can eventually be shored up.

The built-in tests allow for easy verification that addresses return the expected fields. See for example test/canada.coffee.

Browser Installation

To install on the browser you can simply copy build/SnailMailAddressParser.js or build/SnailMailAddressParser.min.js to your project and include it in your project with eg the RequireJS require('jAddressParser').

Requirements for testing

With Homebrew

  • Node.js: brew install node
  • Coffee-script npm install -g coffee-script

Once 'npm' and coffee-script installed, you can run cake deps to install the remaining npm packages.

Cakefile targets

cake toast

Convert the coffeescript in the lib/ directory into a usable javascript AMD modules build/SnailMailAddressParser.js and build/SnailMailAddressParser.min.js by calling cake toast.

cake test

Run Mocha-based tests on the project.

cake deps

Install dependencies in the node_modules subdirectory of the project.

Future

It is challenging to correctly parse the plethora of possible addresses, so contributions to the parsing and testing are most welcome.

Some ideas for future builds includes:

  • Integration with libraries or services that provide address verification
  • Geocoding integration

License

This project is licensed under the MIT license, which is included as LICENSE in the source.