diff options
| author | Michał Cieślar <[email protected]> | 2024-10-10 17:57:27 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-10-10 17:57:27 +0200 |
| commit | 2f93d9da383638b6d232ff8b3cae827ea4c80150 (patch) | |
| tree | 4e966f3ad2382f93baa993af90e1a80b65af9052 /src/modules | |
| parent | 17606589dd58151e43c037a3acfa82046b33e37c (diff) | |
| download | faker-2f93d9da383638b6d232ff8b3cae827ea4c80150.tar.xz faker-2f93d9da383638b6d232ff8b3cae827ea4c80150.zip | |
feat: add book module (#2949)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/book/index.ts | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/modules/book/index.ts b/src/modules/book/index.ts new file mode 100644 index 00000000..86e168d2 --- /dev/null +++ b/src/modules/book/index.ts @@ -0,0 +1,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); + } +} |
