aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinigami <[email protected]>2022-01-14 17:46:18 +0100
committerDamien Retzinger <[email protected]>2022-01-14 18:37:49 -0500
commit46d51bac072e1efee0b7c6ddfa4b6aac2a9aa0ee (patch)
treec0cafcc021ebb5bb65963c82101f046bddb0da22
parent77f4e63c4bfac731b813f7577a6e257548e20dd9 (diff)
downloadfaker-46d51bac072e1efee0b7c6ddfa4b6aac2a9aa0ee.tar.xz
faker-46d51bac072e1efee0b7c6ddfa4b6aac2a9aa0ee.zip
feat: migrate music (#107)
-rw-r--r--src/index.ts3
-rw-r--r--src/music.ts29
2 files changed, 31 insertions, 1 deletions
diff --git a/src/index.ts b/src/index.ts
index 965b38e9..98b5f51e 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -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';
@@ -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);
diff --git a/src/music.ts b/src/music.ts
new file mode 100644
index 00000000..5c773693
--- /dev/null
+++ b/src/music.ts
@@ -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);
+ }
+}