From 48a7af4f0470115945ab166b540d0bedc7e5eb20 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 6 Nov 2023 09:40:49 +0100 Subject: refactor: simplify module creation (#2485) --- src/modules/airline/index.ts | 9 ++------- src/modules/animal/index.ts | 9 ++------- src/modules/color/index.ts | 9 ++------- src/modules/commerce/index.ts | 9 ++------- src/modules/company/index.ts | 9 ++------- src/modules/database/index.ts | 9 ++------- src/modules/datatype/index.ts | 9 ++------- src/modules/date/index.ts | 10 +++------- src/modules/finance/index.ts | 9 ++------- src/modules/git/index.ts | 9 ++------- src/modules/hacker/index.ts | 9 ++------- src/modules/helpers/index.ts | 8 ++------ src/modules/image/index.ts | 8 ++++---- src/modules/internet/index.ts | 9 ++------- src/modules/location/index.ts | 9 ++------- src/modules/lorem/index.ts | 9 ++------- src/modules/music/index.ts | 9 ++------- src/modules/number/index.ts | 9 ++------- src/modules/person/index.ts | 8 ++------ src/modules/phone/index.ts | 9 ++------- src/modules/random/index.ts | 9 ++------- src/modules/science/index.ts | 9 ++------- src/modules/string/index.ts | 9 ++------- src/modules/system/index.ts | 9 ++------- src/modules/vehicle/index.ts | 9 ++------- src/modules/word/index.ts | 9 ++------- 26 files changed, 55 insertions(+), 177 deletions(-) (limited to 'src/modules') diff --git a/src/modules/airline/index.ts b/src/modules/airline/index.ts index f6d2fdc7..f0ada30c 100644 --- a/src/modules/airline/index.ts +++ b/src/modules/airline/index.ts @@ -4,8 +4,7 @@ * responsible for setting standards relating to many aspects of airline * operations. */ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; export enum Aircraft { Narrowbody = 'narrowbody', @@ -78,11 +77,7 @@ const aircraftTypeSeats: Record = { * * - To generate sample passenger data, you can use the methods of the [`faker.person`](https://fakerjs.dev/api/person.html) module. */ -export class AirlineModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class AirlineModule extends ModuleBase { /** * Generates a random airport. * diff --git a/src/modules/animal/index.ts b/src/modules/animal/index.ts index 09d7f9e1..7e5a51da 100644 --- a/src/modules/animal/index.ts +++ b/src/modules/animal/index.ts @@ -1,5 +1,4 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; /** * Module to generate animal related entries. @@ -12,11 +11,7 @@ import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-fu * * All values may be localized. */ -export class AnimalModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class AnimalModule extends ModuleBase { /** * Returns a random dog breed. * diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts index 5855cd86..ee626e09 100644 --- a/src/modules/color/index.ts +++ b/src/modules/color/index.ts @@ -1,5 +1,4 @@ -import type { Faker } from '../../faker'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; /** * Color space names supported by CSS. @@ -171,11 +170,7 @@ function toColorFormat( * * For a hex color like `#ff0000` used in HTML/CSS, use [`rgb()`](https://fakerjs.dev/api/color.html#rgb). There are also methods for other color formats such as [`hsl()`](https://fakerjs.dev/api/color.html#hsl), [`cmyk()`](https://fakerjs.dev/api/color.html#cmyk), [`hwb()`](https://fakerjs.dev/api/color.html#hwb), [`lab()`](https://fakerjs.dev/api/color.html#lab), and [`lch()`](https://fakerjs.dev/api/color.html#lch). */ -export class ColorModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class ColorModule extends ModuleBase { /** * Returns a random human-readable color name. * diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index 18147dcb..48f56568 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -1,6 +1,5 @@ -import type { Faker } from '../../faker'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { ModuleBase } from '../../internal/module-base'; // Source for official prefixes: https://www.isbn-international.org/range_file_generation const ISBN_LENGTH_RULES: Record< @@ -86,11 +85,7 @@ const ISBN_LENGTH_RULES: Record< * * You can also create a price using [`price()`](https://fakerjs.dev/api/commerce.html#price). */ -export class CommerceModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class CommerceModule extends ModuleBase { /** * Returns a department inside a shop. * diff --git a/src/modules/company/index.ts b/src/modules/company/index.ts index 36144961..14fe0eba 100644 --- a/src/modules/company/index.ts +++ b/src/modules/company/index.ts @@ -1,6 +1,5 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { ModuleBase } from '../../internal/module-base'; /** * Module to generate company related entries. @@ -16,11 +15,7 @@ import { deprecated } from '../../internal/deprecated'; * - For products and commerce, use [`faker.commerce`](https://fakerjs.dev/api/commerce.html). * - For finance-related entries, use [`faker.finance`](https://fakerjs.dev/api/finance.html). */ -export class CompanyModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class CompanyModule extends ModuleBase { /** * Returns an array with possible company name suffixes. * diff --git a/src/modules/database/index.ts b/src/modules/database/index.ts index 6015cfa2..6c3595cc 100644 --- a/src/modules/database/index.ts +++ b/src/modules/database/index.ts @@ -1,5 +1,4 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; /** * Module to generate database related entries. @@ -10,11 +9,7 @@ import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-fu * * For the NoSQL database MongoDB, [`mongodbObjectId()`](https://fakerjs.dev/api/database.html#mongodbobjectid) provides a random ID. */ -export class DatabaseModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class DatabaseModule extends ModuleBase { /** * Returns a random database column name. * diff --git a/src/modules/datatype/index.ts b/src/modules/datatype/index.ts index 4043d6c5..a8b77a2c 100644 --- a/src/modules/datatype/index.ts +++ b/src/modules/datatype/index.ts @@ -1,6 +1,5 @@ -import type { SimpleFaker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { SimpleModuleBase } from '../../internal/module-base'; /** * Module to generate various primitive values and data types. @@ -11,11 +10,7 @@ import { deprecated } from '../../internal/deprecated'; * * For a simple random true or false value, use [`boolean()`](https://fakerjs.dev/api/datatype.html#boolean). */ -export class DatatypeModule { - constructor(private readonly faker: SimpleFaker) { - bindThisToMemberFunctions(this); - } - +export class DatatypeModule extends SimpleModuleBase { /** * Returns a single random number between zero and the given max value or the given range with the specified precision. * The bounds are inclusive. diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts index 3ad5f438..69854688 100644 --- a/src/modules/date/index.ts +++ b/src/modules/date/index.ts @@ -1,8 +1,8 @@ -import type { Faker, SimpleFaker } from '../..'; +import type { Faker } from '../..'; import type { DateEntryDefinition } from '../../definitions'; import { FakerError } from '../../errors/faker-error'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { SimpleModuleBase } from '../../internal/module-base'; /** * Converts date passed as a string, number or Date to a Date object. @@ -26,11 +26,7 @@ function toDate( /** * Module to generate dates (without methods requiring localized data). */ -export class SimpleDateModule { - constructor(protected readonly faker: SimpleFaker) { - bindThisToMemberFunctions(this); - } - +export class SimpleDateModule extends SimpleModuleBase { /** * Generates a random date that can be either in the past or in the future. * diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index b381e16c..ddf3fffe 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -1,7 +1,6 @@ -import type { Faker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { ModuleBase } from '../../internal/module-base'; import iban from './iban'; /** @@ -37,11 +36,7 @@ export interface Currency { * * For blockchain related methods, use: [`bitcoinAddress()`](https://fakerjs.dev/api/finance.html#bitcoinaddress), [`ethereumAddress()`](https://fakerjs.dev/api/finance.html#ethereumaddress) and [`litecoinAddress()`](https://fakerjs.dev/api/finance.html#litecoinaddress). */ -export class FinanceModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class FinanceModule extends ModuleBase { /** * Generates a random account number. * diff --git a/src/modules/git/index.ts b/src/modules/git/index.ts index cbbeb351..89ab4799 100644 --- a/src/modules/git/index.ts +++ b/src/modules/git/index.ts @@ -1,6 +1,5 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { ModuleBase } from '../../internal/module-base'; const nbsp = '\u00A0'; @@ -11,11 +10,7 @@ const nbsp = '\u00A0'; * * [`commitEntry()`](https://fakerjs.dev/api/git.html#commitentry) generates a random commit entry as printed by `git log`. This includes a commit hash [`commitSha()`](https://fakerjs.dev/api/git.html#commitsha), author, date [`commitDate()`](https://fakerjs.dev/api/git.html#commitdate), and commit message [`commitMessage()`](https://fakerjs.dev/api/git.html#commitmessage). You can also generate a random branch name with [`branch()`](https://fakerjs.dev/api/git.html#branch). */ -export class GitModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class GitModule extends ModuleBase { /** * Generates a random branch name. * diff --git a/src/modules/hacker/index.ts b/src/modules/hacker/index.ts index 7513095a..3a0f9dab 100644 --- a/src/modules/hacker/index.ts +++ b/src/modules/hacker/index.ts @@ -1,5 +1,4 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; /** * Module to generate hacker/IT words and phrases. @@ -16,11 +15,7 @@ import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-fu * - [faker.lorem](https://fakerjs.dev/api/lorem.html) uses faux-Latin "lorem ipsum" text. * - [faker.company](https://fakerjs.dev/api/company.html) includes corporate catchphrases and buzzwords. */ -export class HackerModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class HackerModule extends ModuleBase { /** * Returns a random hacker/IT abbreviation. * diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 4c64be4e..ff93f2ca 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -1,7 +1,7 @@ import type { Faker, SimpleFaker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { SimpleModuleBase } from '../../internal/module-base'; import { luhnCheckValue } from './luhn-check'; import type { RecordKey } from './unique'; import * as uniqueExec from './unique'; @@ -161,7 +161,7 @@ function legacyRegexpStringParse( /** * Module with various helper methods providing basic (seed-dependent) operations useful for implementing faker methods (without methods requiring localized data). */ -export class SimpleHelpersModule { +export class SimpleHelpersModule extends SimpleModuleBase { /** * Global store of unique values. * This means that faker should *never* return duplicate values across all API methods when using `faker.helpers.unique` without passing `options.store`. @@ -170,10 +170,6 @@ export class SimpleHelpersModule { */ private readonly uniqueStore: Record = {}; - constructor(protected readonly faker: SimpleFaker) { - bindThisToMemberFunctions(this); - } - /** * Slugifies the given string. * For that all spaces (` `) are replaced by hyphens (`-`) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index b1c9c692..915014db 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -1,6 +1,6 @@ import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { ModuleBase } from '../../internal/module-base'; import type { MethodsOf } from '../../utils/types'; import { LoremPicsum } from './providers/lorempicsum'; import { Placeholder } from './providers/placeholder'; @@ -19,7 +19,7 @@ import { Unsplash } from './providers/unsplash'; * * This module previously also contained methods for specifically themed images like "fashion" or "food", but these are now deprecated. If you need more control over image type, you can request categorized images using [`urlLoremFlickr()`](https://fakerjs.dev/api/image.html#urlloremflickr), use an image provider directly or provide your own set of placeholder images. */ -export class ImageModule { +export class ImageModule extends ModuleBase { /** * @deprecated Use `faker.image` instead. */ @@ -38,8 +38,8 @@ export class ImageModule { // eslint-disable-next-line deprecation/deprecation readonly placeholder: Placeholder; - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); + constructor(faker: Faker) { + super(faker); // eslint-disable-next-line deprecation/deprecation this.unsplash = new Unsplash(this.faker); diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index aecdb302..4f58615f 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -1,6 +1,5 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { ModuleBase } from '../../internal/module-base'; import { charMapping } from './char-mappings'; import * as random_ua from './user-agent'; @@ -38,11 +37,7 @@ export type HTTPProtocolType = 'http' | 'https'; * * You also have access to a number of the more technical elements of web requests, such as [`httpMethod`](https://fakerjs.dev/api/internet.html#httpmethod), [`httpStatusCode`](https://fakerjs.dev/api/internet.html#httpstatuscode), [`ip`](https://fakerjs.dev/api/internet.html#ip), [`mac`](https://fakerjs.dev/api/internet.html#mac), [`userAgent`](https://fakerjs.dev/api/internet.html#useragent), and [`port`](https://fakerjs.dev/api/internet.html#port). */ -export class InternetModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class InternetModule extends ModuleBase { /** * Returns a random avatar url. * diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts index 19816c8f..baf51c51 100644 --- a/src/modules/location/index.ts +++ b/src/modules/location/index.ts @@ -1,7 +1,6 @@ -import type { Faker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { ModuleBase } from '../../internal/module-base'; /** * Module to generate addresses and locations. Prior to Faker 8.0.0, this module was known as `faker.address`. @@ -14,11 +13,7 @@ import { deprecated } from '../../internal/deprecated'; * * For a random country, you can use [`country()`](https://fakerjs.dev/api/location.html#country) or [`countryCode()`](https://fakerjs.dev/api/location.html#countrycode). */ -export class LocationModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class LocationModule extends ModuleBase { /** * Generates random zip code from specified format. If format is not specified, * the locale's zip format is used. diff --git a/src/modules/lorem/index.ts b/src/modules/lorem/index.ts index 82e557e6..ca71afdf 100644 --- a/src/modules/lorem/index.ts +++ b/src/modules/lorem/index.ts @@ -1,5 +1,4 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; import { filterWordListByLength } from '../word/filter-word-list-by-length'; /** @@ -13,11 +12,7 @@ import { filterWordListByLength } from '../word/filter-word-list-by-length'; * * The generic [`text()`](https://fakerjs.dev/api/lorem.html#text) method can be used to generate some text between one sentence and multiple paragraphs, while [`slug()`](https://fakerjs.dev/api/lorem.html#slug) generates an URL-friendly hyphenated string. */ -export class LoremModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class LoremModule extends ModuleBase { /** * Generates a word of a specified length. * diff --git a/src/modules/music/index.ts b/src/modules/music/index.ts index 86e865ae..332b4530 100644 --- a/src/modules/music/index.ts +++ b/src/modules/music/index.ts @@ -1,5 +1,4 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; /** * Module to generate music related entries. @@ -8,11 +7,7 @@ import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-fu * * Generate a random music genre with [`genre()`](https://fakerjs.dev/api/music.html#genre) or song name with [`songName()`](https://fakerjs.dev/api/music.html#songname). Both may be localized. */ -export class MusicModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class MusicModule extends ModuleBase { /** * Returns a random music genre. * diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts index 87464212..85272aff 100644 --- a/src/modules/number/index.ts +++ b/src/modules/number/index.ts @@ -1,6 +1,5 @@ -import type { SimpleFaker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { SimpleModuleBase } from '../../internal/module-base'; /** * Module to generate numbers of any kind. @@ -16,11 +15,7 @@ import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-fu * - For numeric strings of a given length, use [`faker.string.numeric()`](https://fakerjs.dev/api/string.html#numeric). * - For credit card numbers, use [`faker.finance.creditCardNumber()`](https://fakerjs.dev/api/finance.html#creditcardnumber). */ -export class NumberModule { - constructor(private readonly faker: SimpleFaker) { - bindThisToMemberFunctions(this); - } - +export class NumberModule extends SimpleModuleBase { /** * Returns a single random integer between zero and the given max value or the given range. * The bounds are inclusive. diff --git a/src/modules/person/index.ts b/src/modules/person/index.ts index f07727a2..de408091 100644 --- a/src/modules/person/index.ts +++ b/src/modules/person/index.ts @@ -1,5 +1,5 @@ import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; export enum Sex { Female = 'female', @@ -74,11 +74,7 @@ function selectDefinition( * * For personal contact information like phone numbers and email addresses, see the [`faker.phone`](https://fakerjs.dev/api/phone.html) and [`faker.internet`](https://fakerjs.dev/api/internet.html) modules. */ -export class PersonModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class PersonModule extends ModuleBase { /** * Returns a random first name. * diff --git a/src/modules/phone/index.ts b/src/modules/phone/index.ts index 448cdf78..6747e35d 100644 --- a/src/modules/phone/index.ts +++ b/src/modules/phone/index.ts @@ -1,6 +1,5 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { ModuleBase } from '../../internal/module-base'; /** * Module to generate phone-related data. @@ -9,11 +8,7 @@ import { deprecated } from '../../internal/deprecated'; * * For a phone number, use [`number()`](https://fakerjs.dev/api/phone.html#number). Many locales provide country-specific formats. */ -export class PhoneModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class PhoneModule extends ModuleBase { /** * Generates a random phone number. * diff --git a/src/modules/random/index.ts b/src/modules/random/index.ts index 7fa16f40..98d28bc5 100644 --- a/src/modules/random/index.ts +++ b/src/modules/random/index.ts @@ -1,7 +1,6 @@ -import type { Faker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; import { deprecated } from '../../internal/deprecated'; +import { ModuleBase } from '../../internal/module-base'; import type { LiteralUnion } from '../../utils/types'; import type { AlphaChar, @@ -15,11 +14,7 @@ import type { * * @deprecated Use the modules specific to the type of data you want to generate instead. */ -export class RandomModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class RandomModule extends ModuleBase { /** * Returns a random word. * diff --git a/src/modules/science/index.ts b/src/modules/science/index.ts index 95fc1290..26c78014 100644 --- a/src/modules/science/index.ts +++ b/src/modules/science/index.ts @@ -1,5 +1,4 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; /** * The possible definitions related to elements. @@ -37,11 +36,7 @@ export interface Unit { * * Both methods in this module return objects rather than strings. For example, you can use `faker.science.chemicalElement().name` to pick out the specific property you need. */ -export class ScienceModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class ScienceModule extends ModuleBase { /** * Returns a random periodic table element. * diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts index a370c386..7c159a21 100644 --- a/src/modules/string/index.ts +++ b/src/modules/string/index.ts @@ -1,6 +1,5 @@ -import type { SimpleFaker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { SimpleModuleBase } from '../../internal/module-base'; import type { LiteralUnion } from '../../utils/types'; export type Casing = 'upper' | 'lower' | 'mixed'; @@ -98,11 +97,7 @@ const SAMPLE_MAX_LENGTH = 2 ** 20; * - Emoji can be found at [`faker.internet.emoji()`](https://fakerjs.dev/api/internet.html#emoji). * - The [`faker.helpers`](https://fakerjs.dev/api/helpers.html) module includes a number of string related methods. */ -export class StringModule { - constructor(private readonly faker: SimpleFaker) { - bindThisToMemberFunctions(this); - } - +export class StringModule extends SimpleModuleBase { /** * Generates a string from the given characters. * diff --git a/src/modules/system/index.ts b/src/modules/system/index.ts index 8a21a39b..fa38d6ce 100644 --- a/src/modules/system/index.ts +++ b/src/modules/system/index.ts @@ -1,5 +1,4 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; const commonFileTypes = ['video', 'audio', 'image', 'text', 'application']; @@ -36,11 +35,7 @@ const CRON_DAY_OF_WEEK = [ /** * Generates fake data for many computer systems properties. */ -export class SystemModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class SystemModule extends ModuleBase { /** * Returns a random file name with extension. * diff --git a/src/modules/vehicle/index.ts b/src/modules/vehicle/index.ts index f5f4f1af..e47b7b05 100644 --- a/src/modules/vehicle/index.ts +++ b/src/modules/vehicle/index.ts @@ -1,5 +1,4 @@ -import type { Faker } from '../..'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; /** * Module to generate vehicle related entries. @@ -10,11 +9,7 @@ import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-fu * * If you prefer two wheels, you can generate a [`bicycle()`](https://fakerjs.dev/api/vehicle.html#bicycle) type instead. */ -export class VehicleModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class VehicleModule extends ModuleBase { /** * Returns a random vehicle. * diff --git a/src/modules/word/index.ts b/src/modules/word/index.ts index 93c56829..0408f3cf 100644 --- a/src/modules/word/index.ts +++ b/src/modules/word/index.ts @@ -1,16 +1,11 @@ -import type { Faker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { bindThisToMemberFunctions } from '../../internal/bind-this-to-member-functions'; +import { ModuleBase } from '../../internal/module-base'; import { filterWordListByLength } from './filter-word-list-by-length'; /** * Module to return various types of words. */ -export class WordModule { - constructor(private readonly faker: Faker) { - bindThisToMemberFunctions(this); - } - +export class WordModule extends ModuleBase { /** * Returns an adjective of random or optionally specified length. * -- cgit v1.2.3