Faker.js: Zipcode and state don't match

Created on 17 Aug 2016  路  8Comments  路  Source: Marak/faker.js

Is there a way to make faker.address.zipCode match a state, eg.
faker.address.zipCode('NY') and it will generate ny zip codes?

Most helpful comment

I ended up not using @davglass's repo as I didn't want to introduce a new dependency and it doesn't account for localization in the same way as we would need. The PR I just made (#600) implements a zipCodeByState method that uses a new descriptor file to find min and max zip codes based on the two-letter state abbreviation.

All 8 comments

I'm curious about this too. Anyone know if we can generate state specific zip codes?

@nikmash from the looks of it, it seems just to be random method specific data.

@si-mikey got it. Not ideal for testing with systems that do geocode resolution.

@si-mikey @nikmash

This seems like a useful feature to have.

I don't know exactly how, but it seems like there is a known algorithm for determining zipcode min max ranges by state?

Check this out: http://www.structnet.com/instructions/zip_min_max_by_state.html

If anyone could turn this into code, or find an existing JavaScript solution which does, I'd be glad to add this feature to faker.

Good suggestion, thanks!

This needs to be added, for one project we wanted to generate sandbox Stripe accounts for our test server but Stripe even in sandbox mode requires valid zip codes. Generating a set of address fields that are valid at least by city, state, zip would be really great.

I am going to start working on this. My current thought is to use davglass/zipcodes to support something like this:

// Lookup zip code by state
faker.address.zipCodeByState('CA');

// Lookup zip code by city and state
faker.address.zipCodeByCityAndState('Cupertino', 'CA');

Welcome to feedback on this strategy though!

I ended up not using @davglass's repo as I didn't want to introduce a new dependency and it doesn't account for localization in the same way as we would need. The PR I just made (#600) implements a zipCodeByState method that uses a new descriptor file to find min and max zip codes based on the two-letter state abbreviation.

Some of the min max numbers are incorrect as they left off the leading 0. For example: CT, MA, ME, NH, NJ, NY, RI, and VT.

I looked at the tests and none of the selected states zip codes would have this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clarmso picture clarmso  路  3Comments

chenweiyj picture chenweiyj  路  4Comments

AlexMiroshnikov picture AlexMiroshnikov  路  4Comments

HoustonBass picture HoustonBass  路  6Comments

kevinburke picture kevinburke  路  5Comments