node-usps

Node.JS library to comply with USPS Publication 28 address guidelines.

Node-USPS

This library implements many of the USPS Publication 28 guidelines in the form of an address building class. It accepts multiple fields of address inputs, and then builds a USPS compatible address.

This library is currently maintained by David Allen Ball. Contact information is available at daball.me.

This library is very new and untested. Please use caution until it becomes more stable.

Add node-usps to your packages.json file's dependencies section.

"dependencies": {
  "node-usps": "*"
}

Run: npm install.

In your code, implement using:

var usps = require('node-usps');

Create a new builder object using:

var newAddress = new usps.AddressBuilder();

Fill in the blanks:

newAddress.BusinessName = 'Joyent';
newAddress.StreetNumber = '1';
newAddress.StreetName = 'Embarcadero Center';
newAddress.SecondaryUnitIndicator = 'Floor';
newAddress.SecondaryUnitNumber = '9';
newAddress.City = 'San Francisco';
newAddress.State = 'California';
newAddress.PostalCode = '94111';

Manipulate using the API.

These constants are used inside the library itself, but are also exported because they are useful arrays for autocomplete and drop-down lists.

List of countries. Example:

Pointers from country aliases.

List of US states, possessions, and military states. Example:

'Virginia': { abbreviation: 'VA', type: 'State' }

List of Canada provinces and territories. Example:

'British Columbia': { abbreviation: 'BC', type: 'Province', country: 'Canada' }

Pointers from Canada provinces aliases.

Pointers from old abbreviations to new Canada provinces.

List of geographic directionals. Example:

'North': { abbreviation: 'N', language: 'English' }

List of secondary unit identifiers. Example:

'Apartment': { abbreviation: 'APT', requiresUnitNumber: true, language: 'English' }

List of street name suffixes. Example:

'Avenue': { abbreviation: 'Ave', language: 'English' }

NOT IMPLEMENTED YET. Pointers from commonly misspelled street names and suffixes to the correct street name.

The AddressBuilder stores address data components for manipulation and USPS Publication 28 compliance functions.

Future implementation in research.

Future implementation in research.

Future implementation in research.

Prints a multi-line String that dumps all the fields out in the correct order for USPS guidelines. Calls clone(), removePunctuation(), abbreviate(), capitalize(), and then toString(), chaining the output and returning the final String.

Creates a deep-copy of the AddressBuilder object. Returns a new AddressBuilder object instance with the same fields as the initial object.

Returns a new AddressBuilder with all the fields capitalized. Original object is left intact.

Returns a new AddressBuilder with all the USPS unapproved punctuation removed. Original object is left intact.

Returns a new AddressBuilder with all the USPS abbreviations applied. Original object is left intact.

Returns a String with all the fields dumped out in the correct order for an address label. See toUSPSString() to generate USPS-compliant labels.