diff options
| author | ST-DDT <[email protected]> | 2024-09-15 11:25:45 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-09-15 11:25:45 +0200 |
| commit | 15fd536a18f75a73060512ae095a0a20f5fec6b6 (patch) | |
| tree | 8f534688f00119c22e9d808339a8d583630728bb /src | |
| parent | 79d8f2b850d63e9945c01fd155b10acac480ec78 (diff) | |
| download | faker-15fd536a18f75a73060512ae095a0a20f5fec6b6.tar.xz faker-15fd536a18f75a73060512ae095a0a20f5fec6b6.zip | |
refactor(location): adjust zipCode nullish checks (#3080)
Diffstat (limited to 'src')
| -rw-r--r-- | src/modules/location/index.ts | 12 |
1 files changed, 7 insertions, 5 deletions
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; |
