-
-
Notifications
You must be signed in to change notification settings - Fork 929
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82ab145
commit 77f4e63
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { Faker } from '.'; | ||
|
||
export class Phone { | ||
constructor(private readonly faker: Faker) { | ||
// Bind `this` so namespaced is working correctly | ||
for (const name of Object.getOwnPropertyNames(Phone.prototype)) { | ||
if (name === 'constructor' || typeof this[name] !== 'function') { | ||
continue; | ||
} | ||
this[name] = this[name].bind(this); | ||
} | ||
} | ||
|
||
/** | ||
* phoneNumber | ||
* | ||
* @method faker.phone.phoneNumber | ||
* @param format | ||
* @memberOf faker.phone | ||
*/ | ||
phoneNumber(format?: string) { | ||
format ||= this.faker.phone.phoneFormats(); | ||
return this.faker.helpers.replaceSymbolWithNumber(format); | ||
} | ||
|
||
// FIXME: this is strange passing in an array index. | ||
/** | ||
* phoneNumberFormat | ||
* | ||
* @method faker.phone.phoneFormatsArrayIndex | ||
* @param phoneFormatsArrayIndex | ||
* @memberOf faker.phone | ||
*/ | ||
phoneNumberFormat(phoneFormatsArrayIndex: number = 0) { | ||
return this.faker.helpers.replaceSymbolWithNumber( | ||
this.faker.definitions.phone_number.formats[phoneFormatsArrayIndex] | ||
); | ||
} | ||
|
||
/** | ||
* phoneFormats | ||
* | ||
* @method faker.phone.phoneFormats | ||
*/ | ||
phoneFormats(): string { | ||
return this.faker.random.arrayElement( | ||
this.faker.definitions.phone_number.formats | ||
); | ||
} | ||
} |