us-zip-to-long-lat
v1.0.0
Published
Zero-dependency US zip code to latitude/longitude lookup, backed by a compact binary dataset
Maintainers
Readme
us-zip-to-long-lat
Zero-dependency US zip code → latitude/longitude lookup.
The full 41k-row source dataset is compacted at build time into a ~490KB binary file (sorted zip codes + float32 coordinates) and looked up with binary search — no JSON parsing, no runtime dependencies.
Install
npm install us-zip-to-long-latUsage
const { lookup } = require('us-zip-to-long-lat');
lookup('90210'); // { lat: 34.0901, lng: -118.4065 }
lookup(90210); // same, number input also accepted
lookup('00000'); // null — not foundAPI
lookup(zip: string | number): { lat: number, lng: number } | null
Pass the zip as a 5-digit string (preserves leading zeros, e.g. "00501")
or a number. Returns null if the zip code isn't in the dataset.
Development
npm run build # compiles src/ and regenerates dist/data.bin from US.txt
npm testData
Source: US.txt (US zip code centroid dataset, tab-separated). Only the
zip code, latitude, and longitude are retained in the published package;
city/state/county fields are dropped to keep the package small.
