Skip to content

Commit

Permalink
feat: migrate music
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Jan 13, 2022
1 parent 7b02094 commit 4b6524a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Datatype } from './datatype';
import { Mersenne } from './mersenne';
import { Music } from './music';
import { Random } from './random';

export interface FakerOptions {
Expand Down Expand Up @@ -175,7 +176,7 @@ export class Faker {
readonly image = new (require('./image'))(this);
readonly internet = new (require('./internet'))(this);
readonly lorem = new (require('./lorem'))(this);
readonly music = new (require('./music'))(this);
readonly music: Music = new Music(this);
readonly name = new (require('./name'))(this);
readonly phone = new (require('./phone_number'))(this);
readonly system = new (require('./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);
}
}

0 comments on commit 4b6524a

Please sign in to comment.