@balancer-team/usps-v3

中文文档
0.0.9发布于 2025/05/30MITTypeScriptCommonJS零依赖近 30 天下载 1969

Library for interfacing with the USPS v3 API.

此软件包已被标记为弃用

This package has moved to @nextform/usps-v3. Please update your dependencies.

原始使用文档
文档目录3 节
  1. Installation
  2. Usage
  3. Title Case Conversion

USPS v3 API JavaScript Library

Library for interfacing with the USPS v3 API. The USPS v3 API replaces the legacy Web Tools API.

Installation

npm i @balancer-team/usps-v3

Usage

Import and configure the library

import { USPS } from '@balancer-team/usps-v3'

const usps = new USPS({
  clientId: USPS_CLIENT_ID,
  clientSecret: USPS_CLIENT_SECRET,
})

Validate an address

const data = await usps.getAddress({
  streetAddress: '302 Riverside Drive',
  city: 'Melbourne Beach',
  state: 'FL',
})

// Response:
//
// {
//   firm: '',
//   address: {
//     streetAddress: '302 RIVERSIDE DR',
//     streetAddressAbbreviation: '302 RIVERSIDE DR',
//     secondaryAddress: '',
//     cityAbbreviation: 'MELBOURNE BCH',
//     city: 'MELBOURNE BCH',
//     state: 'FL',
//     ZIPCode: '32951',
//     ZIPPlus4: '2142',
//     urbanization: ''
//   },
//   additionalInfo: {
//     deliveryPoint: '02',
//     carrierRoute: 'C001',
//     DPVConfirmation: 'Y',
//     DPVCMRA: 'N',
//     business: 'N',
//     centralDeliveryPoint: 'N',
//     vacant: 'N'
//   },
//   corrections: [ { code: '', text: '' } ],
//   matches: [ { code: '31', text: 'Single Response - exact match' } ]
// }

Look up a city/state by ZIP code

const data = await usps.getCityState({
  ZIPCode: '90210',
})

// Response:
//
// {
//    city: 'BEVERLY HILLS',
//    state: 'CA',
//    ZIPCode: '90210'
// }

Title Case Conversion

The USPS v3 API returns all caps for address fields by default. This library can automatically convert the fields to a more human-readable title case if desired. To enable this feature, set the useTitleCase option to true when creating the USPS instance.

const usps = new USPS({
  clientId: USPS_CLIENT_ID,
  clientSecret: USPS_CLIENT_SECRET,
  useTitleCase: true,
})

const data = await usps.getAddress({
  streetAddress: '302 Riverside Drive',
  city: 'Melbourne Beach',
  state: 'FL',
})

// Response:
//
// {
//   firm: '',
//   address: {
//     streetAddress: '302 Riverside Dr',
//     ...

const data = await usps.getCityState({
  ZIPCode: '90210',
})

// Response:
//
// {
//    city: 'Beverly Hills',
//    ...

版本与发布记录

@balancer-team/usps-v3 共发布 9 个版本,首次发布于 2025/05/01;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.9latest2025/05/301.4 年前
0.0.82025/05/181.5 年前
0.0.72025/05/011.5 年前
0.0.62025/05/011.5 年前
0.0.52025/05/011.5 年前
0.0.42025/05/011.5 年前

关于 @balancer-team/usps-v3 的常见问题

@balancer-team/usps-v3 是什么?

Library for interfacing with the USPS v3 API.注意:该包已被作者标记为弃用——This package has moved to @nextform/usps-v3. Please update your dependencies.

如何安装 @balancer-team/usps-v3?

在项目目录运行 npm install @balancer-team/usps-v3,或使用 pnpm add / yarn add / bun add。

@balancer-team/usps-v3 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@balancer-team/usps-v3 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@balancer-team/usps-v3 可以商用吗?

@balancer-team/usps-v3 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@balancer-team/usps-v3 的下载量有多少?

根据 npm 官方下载统计,@balancer-team/usps-v3 在 2026/10/08 – 2026/11/06 这 30 天内被下载 1,969 次,日均约 66 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@balancer-team/usps-v3 还在维护吗?

最新版本 0.0.9 发布于 2025/05/30(1.4 年前);至今共发布 9 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/05/01。作者已将其标记为弃用,新项目建议寻找替代方案。