coord-zip-city
v1.0.13
Published
Get latitude/longitude for cities & ZIP codes, using a population-weighted centroid. Browser + Node.js, small install, zero dependencies.
Maintainers
Readme
coord-zip-city
- Get latitude & longitude for a population-weighted centroid of any five-digit US ZIP code
- Works in browsers & Node.js
- ~800KB install, no dependencies
Removed irrelevant fields, rounded coordinates to two decimal places, used regional deltas to reduce size of coordinates
Installation
npm i coord-zip-cityUsage
import { coordZipCity } from 'coord-zip-city';
coordZipCity.zipInfo('30605') // also accepts Number
// { city: 'ATHENS', state: 'GA', lat: 33.93, lon: -83.34 }
coordZipCity.zipCity('30605');
// 'Athens'
coordZipCity.zipState('30605');
// 'GA'
coordZipCity.zipCoordinates('30605');
// {lat: 33.39, lon: -83.34 }
coordZipCity.zipCityState('30605');
// 'ATHENS, GA'
coordZipCity.cityInfo('Athens', 'Georgia'); // case-insensitive, accepts full state name or abbreviation
// { zip: '30601', lat: 35.96, lon: -78.95 }
// returns lowest ZIP code within the city & centroid for that ZIP code
coordZipCity.cityZip('Athens', 'Georgia');
// '30601'
coordZipCity.cityCoordinates('Athens', 'Georgia');
// {lat: 35.96, lon: -78.95 } Using with Bundlers
In production builds, the package should work without any additional configuration.
However, in development builds using bundlers, you will need to:
- Allow the package in the dev server settings, or disable 'strict' mode (or you will see a 403 Forbidden error in the console)
- Exclude the package from dependency optimization (or you will see undefined value errors in the console)
This ensures the binary containing the coordinate data is authorized to load, and is loaded from the correct relative URL.
An example for Vite (vite.config.js):
export default defineConfig({
server: {
fs: {
allow: [
path.resolve('node_modules/coord-zip-city'),
...
]
// or
strict: false
}
},
optimizeDeps: {
exclude: ['coord-zip-city'],
},
...And for Quasar with Vite (quasar.config.js):
export default defineConfig((ctx) => {
return {
build: {
extendViteConf (viteConf) {
viteConf.optimizeDeps ??= {};
viteConf.optimizeDeps.exclude ??= [];
viteConf.optimizeDeps.exclude.push('coord-zip-city');
viteConf.server = viteConf.server || {};
viteConf.server.fs = viteConf.server.fs || {};
const projectRoot = fileURLToPath(new URL('.', import.meta.url));
viteConf.server.fs.allow = [
projectRoot,
...(viteConf.server.fs.allow || []),
path.resolve('node_modules/coord-zip-city')
];
// or
viteConf.server.fs.strict = false;
},
...
},
...
}
})License
This package is licensed under the Prosperity License. In short:
- Non-commercial usage is free.
- You must redistribute the license with the package and attribute the package's authorship to 'NuCommunity Nonprofit (Jake Ware)'.
- If you release a modified version of the package, it must be open-source and under the same license.
- If you wish to use this package in a commercial project, you must contact Jake Ware via email ([email protected]) to negotiate a different license.
