@bluehive/zipcodes

中文文档
8.0.4发布于 2024/04/11BSDCommonJS零依赖近 30 天下载 2.2万

Useful zipcode database with helper methods (updated)

原始使用文档
文档目录8 节
  1. Usage
  2. Zipcode Lookup
  3. Distance
  4. Lookup By Name
  5. Lookup by Radius
  6. Zipcode Random
  7. TODO
  8. Development

USA Zip Code Lookups (Data Last Updated April 10th, 2024)

A localized (flatfile) zipcode lookup (USA Only)

USA zip codes from: https://postalpro.usps.com/ZIP_Locale_Detail

Transformed into a JSON object and then wrapped with some helper methods.

Usage

const zipcodes = require('zipcodes');

Zipcode Lookup

const hills = zipcodes.lookup(90210);

{
  zip: '90210',
  latitude: 34.088808,
  longitude: -118.406125,
  city: 'Beverly Hills',
  state: 'CA',
  country: 'US'
}

Distance

This is not driving distance, it's line of sight distance

var dist = zipcodes.distance(62959, 90210); //In Miles
// dist = 1662

var kilo = zipcodes.toKilometers(dist); //Convert to Kilometers
// kilo = 2675

var miles = zipcodes.toMiles(zipcodes.toKilometers(dist)); //Convert to Kilometers, then to miles
// miles = 1662

Lookup By Name

This does not work on the Canada data, the data file doesn't include this much detail.

var l = zipcodes.lookupByName('Cupertino', 'CA');

//Always returns an array, since cities can have multiple zip codes
[
  {
    zip: '95015',
    latitude: 37.323,
    longitude: -122.0527,
    city: 'Cupertino',
    state: 'CA',
    country: 'US'
  }
]

Lookup by Radius

Get all zipcodes within the milage radius of this zipcode

var rad = zipcodes.radius(95014, 50);
// rad.length == 385

[ '93901',
  '93902',
  '93905',
  '93906',
  '93907',
  '93912',
  '93933',
  '93942',
  '93944',
  '93950',
  ...
  '95377',
  '95378',
  '95385',
  '95387',
  '95391' 
]

Zipcode Random

var zipObj = zipcodes.random();

{ 
  zip: '90210',
  latitude: 34.088808,
  longitude: -118.406125,
  city: 'Beverly Hills',
  state: 'CA',
  country: 'US'
}

TODO

Add support for importing into MongoDB or CouchDB to speed up searchs.

Development

The original CSV file that I am using for this data is not included in this repo, but I did wrap up the best way to get the data and how to convert it into the format that this module uses.

To develop with this module, just make it and it will fetch the latest zipcodes and reprocess them.

make

To just fetch and process the zipcodes:

make codes

To run the very simple test suite:

make tests

版本与发布记录

@bluehive/zipcodes 共发布 1 个版本,首次发布于 2024/04/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
8.0.4latest2024/04/112 年前

关于 @bluehive/zipcodes 的常见问题

@bluehive/zipcodes 是什么?

Useful zipcode database with helper methods (updated)

如何安装 @bluehive/zipcodes?

在项目目录运行 npm install @bluehive/zipcodes,或使用 pnpm add / yarn add / bun add。

@bluehive/zipcodes 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bluehive__zipcodes 是否存在。

@bluehive/zipcodes 支持 ESM 还是 CommonJS?

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

@bluehive/zipcodes 可以商用吗?

@bluehive/zipcodes 使用 BSD 许可。声明的许可为 BSD,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@bluehive/zipcodes 的下载量有多少?

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

@bluehive/zipcodes 还在维护吗?

最新版本 8.0.4 发布于 2024/04/11(2 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/04/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。