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

usps-webtools-promise

v6.1.0

Published

API wrapper for the USPS Web-Tools, with Promises!

Downloads

7,242

Readme

Node.js CI CodeQL

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;
// or
import USPS from "usps-webtools-promise";

const usps = new USPS({
  // USPS returns ALL CAPS, this boolean turns on Proper Caps for both Street lines and City. This is an optional item. Defaults to true.
  properCase: boolean,
  // Staging will run all functions on the USPS Staging servers instead of Production. Defaults to false.
  staging: boolean,
  // This can be created by going to https://www.usps.com/business/web-tools-apis/ and registering for an id
  userId: "USPS User id",
});

verifyMultiple(object[])

Verify takes one parameter: object[]

object[]: [{Address1, Address2, City, State, Zip}]

Example

usps
  .verifyMultiple([{
    Address1: "322 3rd st.",
    Address2: "Apt 2",
    City: "San Francisco",
    State: "CA",
    Zip5: "94103",
  }, {
    Address1: "322 3rd st.",
    Address2: "Apt 2",
    City: "San Francisco",
    State: "CA",
    Zip5: "94103",
  }
  ])
  .then((address) => {
    console.log(address);
  });

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",
    Zip5: "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);

Coverage

-------------------------------|---------|----------|---------|---------|------------------------------
File                           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------------|---------|----------|---------|---------|------------------------------
All files                      |   91.64 |    62.65 |   93.75 |   91.64 |
 src                           |   95.85 |    55.55 |     100 |   95.85 |
  address-validate.ts          |      96 |     37.5 |     100 |      96 | 81,84,87,93
  multiple-address-validate.ts |   92.77 |    54.54 |     100 |   92.77 | 62,65,68,80-82
  usps.ts                      |     100 |      100 |     100 |     100 |
 src/lookups                   |   84.81 |    66.66 |   83.33 |   84.81 |
  city-state-lookup.ts         |     100 |    83.33 |     100 |     100 | 45
  pricing-rate-lookup.ts       |   74.49 |      100 |      50 |   74.49 | 112-149
  zip-code-lookup.ts           |   95.83 |    54.54 |     100 |   95.83 | 57,60,63
 src/utils                     |   95.65 |       75 |     100 |   95.65 |
  proper-case.ts               |     100 |      100 |     100 |     100 |
  request.ts                   |   94.23 |    64.28 |     100 |   94.23 | 54-55,61,112,122-123,127-129
-------------------------------|---------|----------|---------|---------|------------------------------