aboutsummaryrefslogtreecommitdiff
path: root/src/modules/book/index.ts
blob: 86e168d2ad468a9112fc3231bd0394306ae37c50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { ModuleBase } from '../../internal/module-base';

/**
 * Module to generate book related entries.
 *
 * ### Overview
 *
 * - For a random title, use [`title()`](https://fakerjs.dev/api/book.html#title).
 * - For a random existing author name, use [`author()`](https://fakerjs.dev/api/book.html#author).
 * - For a random non-existing author name, use [`faker.person.fullName()`](https://fakerjs.dev/api/person.html#fullname).
 * - For a random genre, use [`genre()`](https://fakerjs.dev/api/book.html#genre).
 * - For a random series, use [`series()`](https://fakerjs.dev/api/book.html#series).
 * - For a random publisher, use [`publisher()`](https://fakerjs.dev/api/book.html#publisher).
 * - For a random book format, use [`format()`](https://fakerjs.dev/api/book.html#format).
 * - For a random isbn, use [`faker.commerce.isbn()`](https://fakerjs.dev/api/commerce.html#isbn)
 *
 * All values may be localized.
 */
export class BookModule extends ModuleBase {
  /**
   * Returns a random author name.
   *
   * @example
   * faker.book.author() // 'William Shakespeare'
   *
   * @since 9.1.0
   */
  author(): string {
    return this.faker.helpers.arrayElement(this.faker.definitions.book.author);
  }

  /**
   * Returns a random book format.
   *
   * @example
   * faker.book.format() // 'Hardcover'
   *
   * @since 9.1.0
   */
  format(): string {
    return this.faker.helpers.arrayElement(this.faker.definitions.book.format);
  }

  /**
   * Returns a random genre.
   *
   * @example
   * faker.book.genre() // 'Fantasy'
   *
   * @since 9.1.0
   */
  genre(): string {
    return this.faker.helpers.arrayElement(this.faker.definitions.book.genre);
  }

  /**
   * Returns a random publisher.
   *
   * @example
   * faker.book.publisher() // 'Addison-Wesley'
   *
   * @since 9.1.0
   */
  publisher(): string {
    return this.faker.helpers.arrayElement(
      this.faker.definitions.book.publisher
    );
  }

  /**
   * Returns a random series.
   *
   * @example
   * faker.book.series() // 'Harry Potter'
   *
   * @since 9.1.0
   */
  series(): string {
    return this.faker.helpers.arrayElement(this.faker.definitions.book.series);
  }

  /**
   * Returns a random title.
   *
   * @example
   * faker.book.title() // 'Romeo and Juliet'
   *
   * @since 9.1.0
   */
  title(): string {
    return this.faker.helpers.arrayElement(this.faker.definitions.book.title);
  }
}