aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Mayer <[email protected]>2023-05-01 16:03:00 +0700
committerGitHub <[email protected]>2023-05-01 09:03:00 +0000
commita8dc7e07f6d5ee2ae38724ba5d503d7b88bd7147 (patch)
treefb787d9a30e1305c3c2ffb0364395476caa0b93e /src
parenta94d365a2313a7597065b7468abb2d79b6da026e (diff)
downloadfaker-a8dc7e07f6d5ee2ae38724ba5d503d7b88bd7147.tar.xz
faker-a8dc7e07f6d5ee2ae38724ba5d503d7b88bd7147.zip
fix(location): no leading zero on building number or secondary address (#2032)
Diffstat (limited to 'src')
-rw-r--r--src/definitions/location.ts4
-rw-r--r--src/modules/location/index.ts26
2 files changed, 18 insertions, 12 deletions
diff --git a/src/definitions/location.ts b/src/definitions/location.ts
index 9af95fc2..b8e7ebab 100644
--- a/src/definitions/location.ts
+++ b/src/definitions/location.ts
@@ -72,7 +72,7 @@ export type LocationDefinition = LocaleEntry<{
direction_abbr: string[];
/**
- * The pattern used to generate building numbers.
+ * The pattern used to generate building numbers. Since building numbers rarely start with 0, any consecutive # characters will be replaced by a number without a leading zero.
*/
building_number: string[];
@@ -112,7 +112,7 @@ export type LocationDefinition = LocaleEntry<{
};
/**
- * The address "inside" an address/e.g. an apartment or office.
+ * The address "inside" an address/e.g. an apartment or office. Since these rarely start with 0, any consecutive # characters will be replaced by a number without a leading zero.
*/
secondary_address: string[];
diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts
index e924bd7e..5b5d37a1 100644
--- a/src/modules/location/index.ts
+++ b/src/modules/location/index.ts
@@ -188,11 +188,14 @@ export class LocationModule {
* @since 8.0.0
*/
buildingNumber(): string {
- const format = this.faker.helpers.arrayElement(
- this.faker.definitions.location.building_number
- );
-
- return this.faker.helpers.replaceSymbolWithNumber(format);
+ return this.faker.helpers
+ .arrayElement(this.faker.definitions.location.building_number)
+ .replace(/#+/g, (m) =>
+ this.faker.string.numeric({
+ length: m.length,
+ allowLeadingZeros: false,
+ })
+ );
}
/**
@@ -281,11 +284,14 @@ export class LocationModule {
* @since 8.0.0
*/
secondaryAddress(): string {
- return this.faker.helpers.replaceSymbolWithNumber(
- this.faker.helpers.arrayElement(
- this.faker.definitions.location.secondary_address
- )
- );
+ return this.faker.helpers
+ .arrayElement(this.faker.definitions.location.secondary_address)
+ .replace(/#+/g, (m) =>
+ this.faker.string.numeric({
+ length: m.length,
+ allowLeadingZeros: false,
+ })
+ );
}
/**