From 2ad9eaebf7610418d802a8a790ebdec68e14fc5f Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 1 Sep 2024 19:57:08 +0200 Subject: [PATCH] refactor(location): adjust zipCode implementation to match other methods --- src/modules/location/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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;