Skip to content

Commit

Permalink
Merge branch 'main' into feat_pin
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Apr 6, 2022
2 parents a8abe45 + 40c9d5a commit 421299e
Show file tree
Hide file tree
Showing 44 changed files with 249 additions and 121 deletions.
66 changes: 24 additions & 42 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 Expand Up @@ -340,25 +335,12 @@ export class Address {
* faker.address.countryCode() // 'SJ'
* faker.address.countryCode('alpha-2') // 'GA'
* faker.address.countryCode('alpha-3') // 'TJK'
* faker.address.countryCode('unsupported') // 'DJ'
*/
// TODO ST-DDT 2022-02-10: Limit the parameter to the two values.
countryCode(alphaCode: string = 'alpha-2'): string {
if (alphaCode === 'alpha-2') {
return this.faker.random.arrayElement(
this.faker.definitions.address.country_code
);
}
countryCode(alphaCode: 'alpha-2' | 'alpha-3' = 'alpha-2'): string {
const key: keyof typeof this.faker.definitions.address =
alphaCode === 'alpha-3' ? 'country_code_alpha_3' : 'country_code';

if (alphaCode === 'alpha-3') {
return this.faker.random.arrayElement(
this.faker.definitions.address.country_code_alpha_3
);
}

return this.faker.random.arrayElement(
this.faker.definitions.address.country_code
);
return this.faker.random.arrayElement(this.faker.definitions.address[key]);
}

/**
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
8 changes: 3 additions & 5 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,9 @@ export class Helpers {
return o || [];
}

// TODO ST-DDT 2022-02-06: This default will never be taken!?
o = o || (['a', 'b', 'c'] as unknown as T[]);
for (let x: T, j: number, i = o.length - 1; i > 0; --i) {
j = this.faker.datatype.number(i);
x = o[i];
for (let i = o.length - 1; i > 0; --i) {
const j = this.faker.datatype.number(i);
const x = o[i];
o[i] = o[j];
o[j] = x;
}
Expand Down
14 changes: 3 additions & 11 deletions src/iban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,13 @@ export = {
pattern10: ['01', '02', '03', '04', '05', '06', '07', '08', '09'],
pattern100: ['001', '002', '003', '004', '005', '006', '007', '008', '009'],
toDigitString: (str: string): string =>
str.replace(
/[A-Z]/gi,
(match) =>
// TODO @Shinigami92 2022-01-13: This needs to be converted to string
// @ts-expect-error
match.toUpperCase().charCodeAt(0) - 55
str.replace(/[A-Z]/gi, (match) =>
String(match.toUpperCase().charCodeAt(0) - 55)
),
mod97: (digitStr: string): number => {
let m = 0;
for (let i = 0; i < digitStr.length; i++) {
m =
(m * 10 +
// @ts-expect-error: We need to convert this properly
(digitStr[i] | 0)) %
97;
m = (m * 10 + +digitStr[i]) % 97;
}
return m;
},
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}}',
};
22 changes: 21 additions & 1 deletion src/locales/en_GB/internet/domain_suffix.ts
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
export default ['co.uk', 'com', 'biz', 'info', 'name'];
export default [
'ac.uk',
'biz',
'co',
'co.uk',
'com',
'cymru',
'gov.uk',
'info',
'london',
'ltd.uk',
'me.uk',
'name',
'nhs.uk',
'org.uk',
'plc.uk',
'sch.uk',
'scot',
'uk',
'wales',
];
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}}',
};
2 changes: 1 addition & 1 deletion src/locales/pl/address/street_prefix.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default ['ul.', 'al.'];
export default ['ul.', 'al.', 'os.'];
22 changes: 21 additions & 1 deletion src/locales/pl/internet/domain_suffix.ts
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
export default ['com', 'pl', 'com.pl', 'net', 'org'];
export default [
'agro.pl',
'auto.pl',
'biz.pl',
'com.pl',
'edu.pl',
'gmina.pl',
'gov.pl',
'info.pl',
'miasta.pl',
'net.pl',
'nieruchomosci.pl',
'org.pl',
'pl',
'powiat.pl',
'priv.pl',
'sklep.pl',
'szkola.pl',
'targi.pl',
'turystyka.pl',
];
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}}',
};
Loading

0 comments on commit 421299e

Please sign in to comment.