Skip to content

Commit 214a77b

Browse files
authored
chore: address zipCodeByState fix types (#760)
1 parent 52ad16e commit 214a77b

File tree

11 files changed

+10
-26
lines changed

11 files changed

+10
-26
lines changed

src/address.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export class Address {
8484
}
8585

8686
/**
87-
* Generates random zipcode from specified format. If format is not specified, the
88-
* locale's zip format is used.
87+
* Generates random zip code from specified format. If format is not specified,
88+
* the locale's zip format is used.
8989
*
9090
* @param format The optional format used to generate the the zip code.
9191
* By default, a random format is used from the locale zip formats.
@@ -111,7 +111,7 @@ export class Address {
111111
}
112112

113113
/**
114-
* Generates random zipcode from state abbreviation. If state abbreviation is
114+
* Generates random zip code from state abbreviation. If state abbreviation is
115115
* not specified, a random zip code is generated according to the locale's zip format.
116116
* Only works for locales with postcode_by_state definition. If a locale does not
117117
* have a postcode_by_state definition, a random zip code is generated according
@@ -123,11 +123,10 @@ export class Address {
123123
* fakerUS.address.zipCodeByState("AK") // '99595'
124124
* fakerUS.address.zipCodeByState("??") // '47683-9880'
125125
*/
126-
zipCodeByState(state: string): string | number {
127-
const zipRange = this.faker.definitions.address.postcode_by_state[state];
126+
zipCodeByState(state: string): string {
127+
const zipRange = this.faker.definitions.address.postcode_by_state?.[state];
128128
if (zipRange) {
129-
// TODO ST-DDT 2022-02-10: Fix types
130-
return this.faker.datatype.number(zipRange);
129+
return String(this.faker.datatype.number(zipRange));
131130
}
132131
return this.faker.address.zipCode();
133132
}

src/definitions/address.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ export interface AddressDefinitions {
77
/**
88
* Postcodes patterns by state
99
*/
10-
// TODO ST-DDT 2022-01-31: address.zipCodeByState() expects only { [state: string]: { min: number; max: number } }
11-
postcode_by_state:
12-
| string[]
13-
| { [state: string]: { min: number; max: number } };
10+
postcode_by_state: { [state: string]: { min: number; max: number } };
1411
/**
1512
* Postcodes patterns (Fake-Pattern | Fake-Pattern[]).
1613
*/

src/locales/ar/address/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import city_name from './city_name';
99
import country from './country';
1010
import default_country from './default_country';
1111
import postcode from './postcode';
12-
import postcode_by_state from './postcode_by_state';
1312
import secondary_address from './secondary_address';
1413
import state from './state';
1514
import street_address from './street_address';
@@ -23,7 +22,6 @@ const address = {
2322
country,
2423
default_country,
2524
postcode,
26-
postcode_by_state,
2725
secondary_address,
2826
state,
2927
street_address,

src/locales/ar/address/postcode_by_state.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/locales/en/address/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import default_country from './default_country';
1616
import direction from './direction';
1717
import direction_abbr from './direction_abbr';
1818
import postcode from './postcode';
19-
import postcode_by_state from './postcode_by_state';
2019
import secondary_address from './secondary_address';
2120
import state from './state';
2221
import state_abbr from './state_abbr';
@@ -39,7 +38,6 @@ const address = {
3938
direction,
4039
direction_abbr,
4140
postcode,
42-
postcode_by_state,
4341
secondary_address,
4442
state,
4543
state_abbr,

src/locales/en/address/postcode_by_state.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/locales/he/address/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import default_country from './default_country';
1313
import direction from './direction';
1414
import direction_abbr from './direction_abbr';
1515
import postcode from './postcode';
16-
import postcode_by_state from './postcode_by_state';
1716
import secondary_address from './secondary_address';
1817
import state from './state';
1918
import state_abbr from './state_abbr';
@@ -33,7 +32,6 @@ const address = {
3332
direction,
3433
direction_abbr,
3534
postcode,
36-
postcode_by_state,
3735
secondary_address,
3836
state,
3937
state_abbr,

src/locales/he/address/postcode_by_state.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/locales/ur/address/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import country from './country';
1212
import default_country from './default_country';
1313
import direction from './direction';
1414
import postcode from './postcode';
15-
import postcode_by_state from './postcode_by_state';
1615
import secondary_address from './secondary_address';
1716
import state from './state';
1817
import state_abbr from './state_abbr';
@@ -30,7 +29,6 @@ const address = {
3029
default_country,
3130
direction,
3231
postcode,
33-
postcode_by_state,
3432
secondary_address,
3533
state,
3634
state_abbr,

src/locales/ur/address/postcode_by_state.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/address.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,15 @@ describe('address', () => {
395395
faker.locale = 'en_US';
396396
const states = ['IL', 'GA', 'WA'];
397397

398-
const zipCode1 = faker.address.zipCodeByState(states[0]);
398+
const zipCode1 = +faker.address.zipCodeByState(states[0]);
399399
expect(zipCode1).greaterThanOrEqual(60001);
400400
expect(zipCode1).lessThanOrEqual(62999);
401401

402-
const zipCode2 = faker.address.zipCodeByState(states[1]);
402+
const zipCode2 = +faker.address.zipCodeByState(states[1]);
403403
expect(zipCode2).greaterThanOrEqual(30001);
404404
expect(zipCode2).lessThanOrEqual(31999);
405405

406-
const zipCode3 = faker.address.zipCodeByState(states[2]);
406+
const zipCode3 = +faker.address.zipCodeByState(states[2]);
407407
expect(zipCode3).greaterThanOrEqual(98001);
408408
expect(zipCode3).lessThanOrEqual(99403);
409409
});

0 commit comments

Comments
 (0)