@@ -12,36 +12,46 @@ export class Phone {
12
12
}
13
13
14
14
/**
15
- * phoneNumber
15
+ * Generates a random phone number.
16
16
*
17
- * @method faker.phone.phoneNumber
18
- * @param format
19
- * @memberOf faker.phone
17
+ * @param format Format of the phone number. Defaults to `faker.phone.phoneFormats()`
18
+ *
19
+ * @example
20
+ * faker.phone.phoneNumber() // '961-770-7727'
21
+ * faker.phone.phoneNumber('501-###-###') // '501-039-841'
22
+ * faker.phone.phoneNumber('+48 91 ### ## ##') // '+48 91 463 61 70'
20
23
*/
24
+ // TODO @pkuczynski 2022-02-01: simplify name to `number()`
21
25
phoneNumber ( format ?: string ) : string {
22
- format ||= this . faker . phone . phoneFormats ( ) ;
23
- return this . faker . helpers . replaceSymbolWithNumber ( format ) ;
26
+ return this . faker . helpers . replaceSymbolWithNumber (
27
+ format || this . phoneFormats ( )
28
+ ) ;
24
29
}
25
30
26
- // FIXME: this is strange passing in an array index.
27
31
/**
28
- * phoneNumberFormat
32
+ * Returns phone number in a format of the given index from `faker.definitions.phone_number.formats`.
33
+ *
34
+ * @param phoneFormatsArrayIndex Index in the `faker.definitions.phone_number.formats` array. Defaults to `0`.
29
35
*
30
- * @method faker.phone.phoneFormatsArrayIndex
31
- * @param phoneFormatsArrayIndex
32
- * @memberOf faker.phone
36
+ * @example
37
+ * faker.phone.phoneNumberFormat() // '943-627-0355'
38
+ * faker.phone.phoneNumberFormat(3) // '282.652.3201'
33
39
*/
34
- phoneNumberFormat ( phoneFormatsArrayIndex : number = 0 ) : string {
40
+ // FIXME @Shinigami 2022-01-14: this is strange passing in an array index
41
+ // TODO @pkuczynski 2022-02-01: discuss removing this method as it tightly couples with localisation
42
+ phoneNumberFormat ( phoneFormatsArrayIndex = 0 ) : string {
35
43
return this . faker . helpers . replaceSymbolWithNumber (
36
44
this . faker . definitions . phone_number . formats [ phoneFormatsArrayIndex ]
37
45
) ;
38
46
}
39
47
40
48
/**
41
- * phoneFormats
49
+ * Returns a random phone number format.
42
50
*
43
- * @method faker.phone.phoneFormats
51
+ * @example
52
+ * faker.phone.phoneFormats() // '!##.!##.####'
44
53
*/
54
+ // TODO @pkuczynski 2022-02-01: simplify name to `format()`
45
55
phoneFormats ( ) : string {
46
56
return this . faker . random . arrayElement (
47
57
this . faker . definitions . phone_number . formats
0 commit comments