Skip to content

Commit

Permalink
✨ update US zips using 2021 files
Browse files Browse the repository at this point in the history
  • Loading branch information
blakek authored Nov 8, 2021
2 parents 7c2dfcf + 1e5bccf commit 540b46f
Show file tree
Hide file tree
Showing 18 changed files with 59,740 additions and 57,801 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# us-zips
# us-zips :us:

> A list of US ZIP codes and their geolocations
Expand All @@ -9,19 +9,20 @@ I needed a list of ZIP codes, and the [US Census Bureau had one][1].
Example: get the nearest zip to a geolocation

```javascript
const geolib = require('geolib');
const usZips = require('us-zips');
const geolib = require('geolib')
const usZips = require('us-zips')

const somewhere = {
lat: 33.1234,
lng: -88.4321
};
}

geolib.findNearest(somewhere, usZips); // { distance: 12834, key: '39341' }
geolib.findNearest(somewhere, usZips) // { distance: 12834, key: '39341' }
```

If you want to get the nearest ZIP, see if [`geo2zip`][2] fits your needs. It's
much faster than the demo above and uses this package as a source.
:information_source: If you need the nearest ZIPs for a geolocation, see if
[`geo2zip`][2] fits your needs. It is much faster than the demo above and uses
this package as a source.

## Data Formats

Expand Down Expand Up @@ -87,9 +88,9 @@ console.log(usZips.find(([key, value]) => key === '10001'))
### Map

```javascript
const usZips = require('us-zips/map');
const usZips = require('us-zips/map')

console.log(usZips.get('90210'));
console.log(usZips.get('90210'))
// { latitude: 34.100517, longitude: -118.41463 }
```

Expand Down Expand Up @@ -122,7 +123,7 @@ page][4].

MIT

[1]: https://www2.census.gov/geo/docs/maps-data/data/gazetteer/2020_Gazetteer/2020_Gaz_zcta_national.zip
[1]: https://www2.census.gov/geo/docs/maps-data/data/gazetteer/2021_Gazetteer/2021_Gaz_zcta_national.zip
[2]: https://github.com/blakek/geo2zip
[3]: https://github.com/blakek/standardize-geolocation
[4]: https://www.census.gov/geographies/reference-files/time-series/geo/gazetteer-files.html
22 changes: 11 additions & 11 deletions __tests__/array.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const test = require('ava').default;
const zipCount = require('../zipCount');
const zipArray = require('../array');
const test = require('ava').default
const zipCount = require('../zipCount')
const zipArray = require('../array')

test('exports the correct number of zips', t => {
t.is(zipArray.length, zipCount);
});
t.is(zipArray.length, zipCount)
})

test('exports the expected format', t => {
t.true(Array.isArray(zipArray));
t.true(Array.isArray(zipArray))

t.is(typeof zipArray[0], 'object');
t.is(typeof zipArray[0], 'object')

t.truthy(zipArray[0].latitude);
t.truthy(zipArray[0].longitude);
t.truthy(zipArray[0].zipCode);
});
t.truthy(zipArray[0].latitude)
t.truthy(zipArray[0].longitude)
t.truthy(zipArray[0].zipCode)
})
22 changes: 11 additions & 11 deletions __tests__/key-value.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const test = require('ava').default;
const zipCount = require('../zipCount');
const zipKeyValue = require('../key-value');
const test = require('ava').default
const zipCount = require('../zipCount')
const zipKeyValue = require('../key-value')

test('exports the correct number of zips', t => {
t.is(zipKeyValue.length, zipCount);
});
t.is(zipKeyValue.length, zipCount)
})

test('exports the expected format', t => {
t.true(Array.isArray(zipKeyValue));
t.true(Array.isArray(zipKeyValue))

const [zipCode, location] = zipKeyValue[0];
const [zipCode, location] = zipKeyValue[0]

t.truthy(zipCode);
t.truthy(location.latitude);
t.truthy(location.longitude);
});
t.truthy(zipCode)
t.truthy(location.latitude)
t.truthy(location.longitude)
})
20 changes: 10 additions & 10 deletions __tests__/map.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const test = require('ava').default;
const zipCount = require('../zipCount');
const zipMap = require('../map');
const test = require('ava').default
const zipCount = require('../zipCount')
const zipMap = require('../map')

test('exports the correct number of zips', t => {
t.is(zipMap.size, zipCount);
});
t.is(zipMap.size, zipCount)
})

test('exports the expected format', t => {
t.true(zipMap instanceof Map);
t.true(zipMap instanceof Map)

const testZip = zipMap.get('38873');
const testZip = zipMap.get('38873')

t.truthy(testZip.latitude);
t.truthy(testZip.longitude);
});
t.truthy(testZip.latitude)
t.truthy(testZip.longitude)
})
24 changes: 12 additions & 12 deletions __tests__/object.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const test = require('ava').default;
const zipCount = require('../zipCount');
const usZips = require('../object');
const test = require('ava').default
const zipCount = require('../zipCount')
const usZips = require('../object')

test('exports the correct number of zips', t => {
const numberExported = Object.keys(usZips).length;
t.is(numberExported, zipCount);
});
const numberExported = Object.keys(usZips).length
t.is(numberExported, zipCount)
})

test('exports the expected format', t => {
t.is(typeof usZips, 'object');
t.is(typeof usZips, 'object')

const testZip = usZips['37214'];
const testZip = usZips['37214']

t.is(typeof testZip, 'object');
t.truthy(testZip.latitude);
t.truthy(testZip.longitude);
});
t.is(typeof testZip, 'object')
t.truthy(testZip.latitude)
t.truthy(testZip.longitude)
})
Loading

0 comments on commit 540b46f

Please sign in to comment.