Skip to content

Commit 46d51ba

Browse files
Shinigami92damienwebdev
authored andcommitted
feat: migrate music (#107)
1 parent 77f4e63 commit 46d51ba

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Helpers } from './helpers';
1010
import { Image } from './image';
1111
import { Internet } from './internet';
1212
import { Mersenne } from './mersenne';
13+
import { Music } from './music';
1314
import { Name } from './name';
1415
import { Phone } from './phone_number';
1516
import { 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);

src/music.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 @Shinigami92 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+
}

0 commit comments

Comments
 (0)