diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts index a9fb7508f4a..4aabdd8db4a 100644 --- a/src/modules/location/index.ts +++ b/src/modules/location/index.ts @@ -58,15 +58,17 @@ export class LocationModule extends ModuleBase { const { state } = options; - if (state) { - const zipPattern: string = + if (state != null) { + const zipPattern = this.faker.definitions.location.postcode_by_state[state]; - if (zipPattern) { - return this.faker.helpers.fake(zipPattern); + if (zipPattern == null) { + throw new FakerError( + `No zip code definition found for state "${state}"` + ); } - throw new FakerError(`No zip code definition found for state "${state}"`); + return this.faker.helpers.fake(zipPattern); } let { format = this.faker.definitions.location.postcode } = options;