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.
This commit is contained in:
Simon Larsen 2024-06-02 21:38:26 +01:00
parent 737c785e73
commit fca2c74817
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA

View File

@ -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);
}
}