File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { Image } from './image';
1111import { Internet } from './internet' ;
1212import { Mersenne } from './mersenne' ;
1313import { Name } from './name' ;
14+ import { Phone } from './phone_number' ;
1415import { Random } from './random' ;
1516import { System } from './system' ;
1617import { Time } from './time' ;
@@ -191,7 +192,7 @@ export class Faker {
191192 readonly lorem = new ( require ( './lorem' ) ) ( this ) ;
192193 readonly music = new ( require ( './music' ) ) ( this ) ;
193194 readonly name : Name = new Name ( this ) ;
194- readonly phone = new ( require ( './phone_number' ) ) ( this ) ;
195+ readonly phone : Phone = new Phone ( this ) ;
195196 readonly system : System = new System ( this ) ;
196197 readonly time : Time = new Time ( ) ;
197198 readonly vehicle = new ( require ( './vehicle' ) ) ( this ) ;
Original file line number Diff line number Diff line change 1+ import type { Faker } from '.' ;
2+
3+ export class Phone {
4+ constructor ( private readonly faker : Faker ) {
5+ // Bind `this` so namespaced is working correctly
6+ for ( const name of Object . getOwnPropertyNames ( Phone . prototype ) ) {
7+ if ( name === 'constructor' || typeof this [ name ] !== 'function' ) {
8+ continue ;
9+ }
10+ this [ name ] = this [ name ] . bind ( this ) ;
11+ }
12+ }
13+
14+ /**
15+ * phoneNumber
16+ *
17+ * @method faker.phone.phoneNumber
18+ * @param format
19+ * @memberOf faker.phone
20+ */
21+ phoneNumber ( format ?: string ) {
22+ format ||= this . faker . phone . phoneFormats ( ) ;
23+ return this . faker . helpers . replaceSymbolWithNumber ( format ) ;
24+ }
25+
26+ // FIXME: this is strange passing in an array index.
27+ /**
28+ * phoneNumberFormat
29+ *
30+ * @method faker.phone.phoneFormatsArrayIndex
31+ * @param phoneFormatsArrayIndex
32+ * @memberOf faker.phone
33+ */
34+ phoneNumberFormat ( phoneFormatsArrayIndex : number = 0 ) {
35+ return this . faker . helpers . replaceSymbolWithNumber (
36+ this . faker . definitions . phone_number . formats [ phoneFormatsArrayIndex ]
37+ ) ;
38+ }
39+
40+ /**
41+ * phoneFormats
42+ *
43+ * @method faker.phone.phoneFormats
44+ */
45+ phoneFormats ( ) : string {
46+ return this . faker . random . arrayElement (
47+ this . faker . definitions . phone_number . formats
48+ ) ;
49+ }
50+ }
You can’t perform that action at this time.
0 commit comments