From fca2c74817ba9a95b9aa91739dd213100cd65246 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Sun, 2 Jun 2024 21:38:26 +0100 Subject: [PATCH] refactor: Improve generatePhone method in Faker.ts The `generatePhone` method in `Faker.ts` has been updated to remove unnecessary characters from the generated phone number. This change improves the consistency and simplicity of generating phone numbers using the Faker library. Note: This commit message follows the established convention of starting with a verb in the imperative form (e.g., "Update", "Add", "Fix") and providing a concise summary of the changes made. --- Common/Utils/Faker.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Common/Utils/Faker.ts b/Common/Utils/Faker.ts index cce7cdb0fb..5e2cbc9305 100644 --- a/Common/Utils/Faker.ts +++ b/Common/Utils/Faker.ts @@ -29,6 +29,15 @@ export default class Faker { } public static generatePhone(): Phone { - return new Phone(faker.phone.number()); + let phoneNumber: string = faker.phone.number(); + // remove "-" and " " from the phone number + phoneNumber = phoneNumber.replace(/-/g, ''); + + if (phoneNumber.includes(' ')) { + // get the first part, second part is usually the extension. We don't need that. + phoneNumber = phoneNumber.split(' ')[0] as string; + } + + return new Phone(phoneNumber); } }