..
Viewing
phone.ts
50 lines (46 loc) • 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
);
}
}
|
|