-
-
Notifications
You must be signed in to change notification settings - Fork 929
/
index.ts
100 lines (95 loc) · 2.72 KB
/
index.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import type { Faker } from '../..';
import { deprecated } from '../../internal/deprecated';
/**
* Module to generate phone-related data.
*/
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);
}
}
/**
* Generates a random phone number.
*
* @param format Format of the phone number. Defaults to a random phone number format.
*
* @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 =
format ??
this.faker.helpers.arrayElement(
this.faker.definitions.phone_number.formats
);
return this.faker.helpers.replaceSymbolWithNumber(format);
}
/**
* 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`.
*
* @see faker.phone.phoneNumber
* @see faker.helpers.replaceSymbolWithNumber
*
* @example
* faker.phone.phoneNumberFormat() // '943-627-0355'
* faker.phone.phoneNumberFormat(3) // '282.652.3201'
*
* @deprecated
*/
phoneNumberFormat(phoneFormatsArrayIndex = 0): string {
deprecated({
deprecated: 'faker.phone.phoneNumberFormat()',
proposed:
'faker.phone.phoneNumber() or faker.helpers.replaceSymbolWithNumber(format)',
since: 'v7.0',
until: 'v8.0',
});
return this.faker.helpers.replaceSymbolWithNumber(
this.faker.definitions.phone_number.formats[phoneFormatsArrayIndex]
);
}
/**
* Returns a random phone number format.
*
* @see faker.phone.phoneNumber
* @see faker.definitions.phone_number.formats
*
* @example
* faker.phone.phoneFormats() // '!##.!##.####'
*
* @deprecated
*/
phoneFormats(): string {
deprecated({
deprecated: 'faker.phone.phoneFormats()',
proposed: 'faker.phone.phoneNumber()',
since: 'v7.0',
until: 'v8.0',
});
return this.faker.helpers.arrayElement(
this.faker.definitions.phone_number.formats
);
}
/**
* Generates IMEI number.
*
* @example
* faker.phone.imei() // '13-850175-913761-7'
*/
imei(): string {
return this.faker.helpers.replaceCreditCardSymbols(
'##-######-######-L',
'#'
);
}
}