Skip to content

chore: fix JSDoc comments in phone.ts #397

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

Merged
merged 4 commits into from
Feb 3, 2022
Merged
Changes from 3 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
38 changes: 24 additions & 14 deletions src/phone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,46 @@ export class Phone {
}

/**
* phoneNumber
* Generates a random phone number.
*
* @method faker.phone.phoneNumber
* @param format
* @memberOf faker.phone
* @param format Format of the phone number. Defaults to `faker.phone.phoneFormats()`
*
* @example
* faker.phone.phoneNumber() // '961-770-7727'
* faker.phone.phoneNumber('501-###-###') // '501-039-841'
* faker.phone.phoneNumber('+48 91 ### ## ##') // '+48 91 463 61 70'
*/
// TODO @pkuczynski 2022-02-01: simplify name to `number()`
phoneNumber(format?: string): string {
format ||= this.faker.phone.phoneFormats();
return this.faker.helpers.replaceSymbolWithNumber(format);
return this.faker.helpers.replaceSymbolWithNumber(
format || this.phoneFormats()
);
}

// FIXME: this is strange passing in an array index.
/**
* phoneNumberFormat
* Returns phone number in a format of the given index from `faker.definitions.phone_number.formats`.
*
* @param phoneFormatsArrayIndex Index in the `faker.definitions.phone_number.formats` array. Defaults to `0`.
*
* @method faker.phone.phoneFormatsArrayIndex
* @param phoneFormatsArrayIndex
* @memberOf faker.phone
* @example
* faker.phone.phoneNumberFormat() // '943-627-0355'
* faker.phone.phoneNumberFormat(3) // '282.652.3201'
*/
phoneNumberFormat(phoneFormatsArrayIndex: number = 0): string {
// FIXME @Shinigami 2022-01-14: this is strange passing in an array index
// TODO @pkuczynski 2022-02-01: discuss removing this method as it tightly couples with localisation
phoneNumberFormat(phoneFormatsArrayIndex = 0): string {
return this.faker.helpers.replaceSymbolWithNumber(
this.faker.definitions.phone_number.formats[phoneFormatsArrayIndex]
);
}

/**
* phoneFormats
* Returns a random phone number format.
*
* @method faker.phone.phoneFormats
* @example
* faker.phone.phoneFormats() // '!##.!##.####'
*/
// TODO @pkuczynski 2022-02-01: simplify name to `format()`
phoneFormats(): string {
return this.faker.random.arrayElement(
this.faker.definitions.phone_number.formats
Expand Down