Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate music #107

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Helpers } from './helpers';
import { Image } from './image';
import { Internet } from './internet';
import { Mersenne } from './mersenne';
import { Music } from './music';
import { Name } from './name';
import { Phone } from './phone_number';
import { Random } from './random';
Expand Down Expand Up @@ -190,7 +191,7 @@ export class Faker {
readonly image: Image = new Image(this);
readonly internet: Internet = new Internet(this);
readonly lorem = new (require('./lorem'))(this);
readonly music = new (require('./music'))(this);
readonly music: Music = new Music(this);
readonly name: Name = new Name(this);
readonly phone: Phone = new Phone(this);
readonly system: System = new System(this);
Expand Down
29 changes: 29 additions & 0 deletions src/music.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Faker } from '.';

export class Music {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Music.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
this[name] = this[name].bind(this);
}

// TODO @Shinigami92 2022-01-12: We should find a better strategy as assigning this property to a function
// @ts-expect-error
this.genre.schema = {
description: 'Generates a genre.',
sampleResults: ['Rock', 'Metal', 'Pop'],
};
}

/**
* genre
*
* @method faker.music.genre
*/
genre(): string {
return this.faker.random.arrayElement(this.faker.definitions.music.genre);
}
}