Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use street address templates from locales #754

Merged
merged 7 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 20 additions & 25 deletions src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ export class Address {
);
}

/**
* Generates a random building number.
*
* @example
* faker.address.buildingNumber() // '379'
*/
buildingNumber(): string {
const format = this.faker.random.arrayElement(
this.faker.definitions.address.building_number
);

return this.faker.helpers.replaceSymbolWithNumber(format);
}

/**
* Generates a random localized street name.
*
Expand Down Expand Up @@ -242,30 +256,10 @@ export class Address {
* faker.address.streetAddress(false) // '34830 Erdman Hollow'
*/
streetAddress(useFullAddress: boolean = false): string {
let address = '';
switch (this.faker.datatype.number(2)) {
case 0:
address =
this.faker.helpers.replaceSymbolWithNumber('#####') +
' ' +
this.faker.address.streetName();
break;
case 1:
address =
this.faker.helpers.replaceSymbolWithNumber('####') +
' ' +
this.faker.address.streetName();
break;
case 2:
address =
this.faker.helpers.replaceSymbolWithNumber('###') +
' ' +
this.faker.address.streetName();
break;
}
return useFullAddress
? address + ' ' + this.faker.address.secondaryAddress()
: address;
const formats = this.faker.definitions.address.street_address;
const format = formats[useFullAddress ? 'full' : 'normal'];

return this.faker.fake(format);
}

/**
Expand Down Expand Up @@ -293,7 +287,8 @@ export class Address {
}

/**
* Generates a random localized secondary address.
* Generates a random localized secondary address. This refers to a specific location at a given address
* such as an apartment or room number.
*
* @example
* faker.address.secondaryAddress() // 'Apt. 861'
Expand Down
22 changes: 22 additions & 0 deletions src/definitions/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export interface AddressDefinitions {
*/
direction_abbr: string[];

/**
* The pattern used to generate building numbers.
*/
building_number: string[];

/**
* Common street prefixes
*/
Expand All @@ -63,6 +68,20 @@ export interface AddressDefinitions {
*/
street_suffix: string[];

/**
* The pattern used to generate street addresses.
*/
street_address: {
/**
* The fake pattern to generate only the street address.
*/
normal: string;
/**
* The fake pattern to generate the full street address including the secondary address.
*/
full: string;
};

/**
* The address "inside" an address/e.g. an apartment or office.
*/
Expand Down Expand Up @@ -100,9 +119,12 @@ export const ADDRESS = allOf<keyof AddressDefinitions>()(
'direction_abbr',
'direction',

'building_number',

'street_prefix',
'street_suffix',

'street_address',
'secondary_address',

'country_code',
Expand Down
5 changes: 4 additions & 1 deletion src/locales/ar/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{building_number} #{street_name}'];
export default {
normal: '{{address.buildingNumber}} {{address.streetName}}',
full: '{{address.buildingNumber}} {{address.streetName}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/az/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name}, #{building_number}'];
export default {
normal: '{{address.streetName}}, {{address.buildingNumber}}',
full: '{{address.streetName}}, {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/cz/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/de/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/de_AT/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/en/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{building_number} #{street_name}'];
export default {
normal: '{{address.buildingNumber}} {{address.streetName}}',
full: '{{address.buildingNumber}} {{address.streetName}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/en_GH/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{building_number} #{street_name}'];
export default {
normal: '{{address.buildingNumber}} {{address.streetName}}',
full: '{{address.buildingNumber}} {{address.streetName}} {{address.secondaryAddress}}',
};
8 changes: 4 additions & 4 deletions src/locales/es/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default [
'#{street_name}#{building_number}',
'#{street_name}#{building_number} #{secondary_address}',
];
export default {
normal: '{{address.streetName}}{{address.buildingNumber}}',
full: '{{address.streetName}}{{address.buildingNumber}} {{address.secondaryAddress}}',
};
8 changes: 4 additions & 4 deletions src/locales/es_MX/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default [
'#{street_name}#{building_number}',
'#{street_name}#{building_number} #{secondary_address}',
];
export default {
normal: '{{address.streetName}}{{address.buildingNumber}}',
full: '{{address.streetName}}{{address.buildingNumber}} {{address.secondaryAddress}}',
};
8 changes: 4 additions & 4 deletions src/locales/fa/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default [
'#{street_name}, پلاک #{building_number}',
'#{street_name}, #{street_name}, پلاک #{building_number}',
];
export default {
normal: '{{address.streetName}}, پلاک {{address.buildingNumber}}',
full: '{{address.streetName}}, پلاک {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/fr/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{building_number} #{street_name}'];
export default {
normal: '{{address.buildingNumber}} {{address.streetName}}',
full: '{{address.buildingNumber}} {{address.streetName}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/fr_BE/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/ge/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/he/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{building_number} #{street_name}'];
export default {
normal: '{{address.buildingNumber}} {{address.streetName}}',
full: '{{address.buildingNumber}} {{address.streetName}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/hr/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/hy/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{address.street_name} #{address.building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/id_ID/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} no #{building_number}'];
export default {
normal: '{{address.streetName}} no {{address.buildingNumber}}',
full: '{{address.streetName}} no {{address.buildingNumber}} {{address.secondaryAddress}}',
};
8 changes: 4 additions & 4 deletions src/locales/it/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default [
'#{street_name} #{building_number}',
'#{street_name} #{building_number}, #{secondary_address}',
];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}}, {{address.secondaryAddress}}',
};
8 changes: 4 additions & 4 deletions src/locales/lv/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default [
'#{street_name} #{building_number}',
'#{street_name} #{building_number} #{secondary_address}',
];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/mk/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/nb_NO/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/nl/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/nl_BE/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/pl/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/pt_PT/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/ro/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name}, #{building_number}, #{secondary_address}'];
export default {
normal: '{{address.streetName}}, {{address.buildingNumber}}',
full: '{{address.streetName}}, {{address.buildingNumber}}, {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/ru/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name}, #{building_number}'];
export default {
normal: '{{address.streetName}}, {{address.buildingNumber}}',
full: '{{address.streetName}}, {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/sk/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/sv/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/tr/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name} #{building_number}'];
export default {
normal: '{{address.streetName}} {{address.buildingNumber}}',
full: '{{address.streetName}} {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/uk/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name}, #{building_number}'];
export default {
normal: '{{address.streetName}}, {{address.buildingNumber}}',
full: '{{address.streetName}}, {{address.buildingNumber}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/ur/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{building_number} #{street_name}'];
export default {
normal: '{{address.buildingNumber}} {{address.streetName}}',
full: '{{address.buildingNumber}} {{address.streetName}} {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/zh_CN/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name}#{building_number}号'];
export default {
normal: '{{address.streetName}}{{address.buildingNumber}}号',
full: '{{address.streetName}}{{address.buildingNumber}}号 {{address.secondaryAddress}}',
};
5 changes: 4 additions & 1 deletion src/locales/zh_TW/address/street_address.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default ['#{street_name}#{building_number}號'];
export default {
normal: '{{address.streetName}}{{address.buildingNumber}}號',
full: '{{address.streetName}}{{address.buildingNumber}}號 {{address.secondaryAddress}}',
};