From 15fd536a18f75a73060512ae095a0a20f5fec6b6 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 15 Sep 2024 11:25:45 +0200 Subject: refactor(location): adjust zipCode nullish checks (#3080) --- src/modules/location/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/modules') diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts index a9fb7508..4aabdd8d 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; -- cgit v1.2.3