File tree 2 files changed +31
-1
lines changed 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { Helpers } from './helpers';
10
10
import { Image } from './image' ;
11
11
import { Internet } from './internet' ;
12
12
import { Mersenne } from './mersenne' ;
13
+ import { Music } from './music' ;
13
14
import { Name } from './name' ;
14
15
import { Phone } from './phone_number' ;
15
16
import { Random } from './random' ;
@@ -190,7 +191,7 @@ export class Faker {
190
191
readonly image : Image = new Image ( this ) ;
191
192
readonly internet : Internet = new Internet ( this ) ;
192
193
readonly lorem = new ( require ( './lorem' ) ) ( this ) ;
193
- readonly music = new ( require ( './music' ) ) ( this ) ;
194
+ readonly music : Music = new Music ( this ) ;
194
195
readonly name : Name = new Name ( this ) ;
195
196
readonly phone : Phone = new Phone ( this ) ;
196
197
readonly system : System = new System ( this ) ;
Original file line number Diff line number Diff line change
1
+ import type { Faker } from '.' ;
2
+
3
+ export class Music {
4
+ constructor ( private readonly faker : Faker ) {
5
+ // Bind `this` so namespaced is working correctly
6
+ for ( const name of Object . getOwnPropertyNames ( Music . prototype ) ) {
7
+ if ( name === 'constructor' || typeof this [ name ] !== 'function' ) {
8
+ continue ;
9
+ }
10
+ this [ name ] = this [ name ] . bind ( this ) ;
11
+ }
12
+
13
+ // TODO @Shinigami 92 2022-01-12: We should find a better strategy as assigning this property to a function
14
+ // @ts -expect-error
15
+ this . genre . schema = {
16
+ description : 'Generates a genre.' ,
17
+ sampleResults : [ 'Rock' , 'Metal' , 'Pop' ] ,
18
+ } ;
19
+ }
20
+
21
+ /**
22
+ * genre
23
+ *
24
+ * @method faker.music.genre
25
+ */
26
+ genre ( ) : string {
27
+ return this . faker . random . arrayElement ( this . faker . definitions . music . genre ) ;
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments