File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { Helpers } from './helpers';
1010import { Image } from './image' ;
1111import { Internet } from './internet' ;
1212import { Mersenne } from './mersenne' ;
13+ import { Music } from './music' ;
1314import { Name } from './name' ;
1415import { Phone } from './phone_number' ;
1516import { Random } from './random' ;
@@ -190,7 +191,7 @@ export class Faker {
190191 readonly image : Image = new Image ( this ) ;
191192 readonly internet : Internet = new Internet ( this ) ;
192193 readonly lorem = new ( require ( './lorem' ) ) ( this ) ;
193- readonly music = new ( require ( './music' ) ) ( this ) ;
194+ readonly music : Music = new Music ( this ) ;
194195 readonly name : Name = new Name ( this ) ;
195196 readonly phone : Phone = new Phone ( this ) ;
196197 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