About:
This package was forked from MadisonReed/usps-webtools, but it has been modernized with Typescript and Promises (async/await). Note: Version 2 is a drop-in replacement for MadisonReed/usps-webtools, it produces the same output. Version 3 uses the same output from USPS, with the exception of Address1 and Address2 being switched, per social norms.
Installation:
npm install usps-webtools-promise
Usage:
Initializing the usps model with a user id.
Example:
const USPS = require('usps-webtools-promise').default;
import USPS from "usps-webtools-promise";
const usps = new USPS({
properCase: boolean,
staging: boolean,
userId: 'USPS User id',
});
verify(object)
Verify takes one parameter: object
object: Address1, Address2, City, State, Zip
Example
usps.verify({
Address1: '322 3rd st.',
Address2: 'Apt 2',
City: 'San Francisco',
State: 'CA',
Zip: '94103'
}).then(address => {
console.log(address);
});
zipCodeLookup(object)
zipCodeLookup takes one parameter: object.
object: Address1, Address2, City, State
Example
const address = await usps.zipCodeLookup({
Address1: '322 3rd st.',
Address2: 'Apt 2',
City: 'San Francisco',
State: 'CA'
});
console.log(address);
cityStateLookup(object)
cityStateLookup takes one parameter: zipcode.
zipcode: 5 digit Zip Code as a string
Example
const result = await usps.cityStateLookup('94107');
console.log(result);