diff --git a/src/definitions/address.ts b/src/definitions/address.ts index c5d5409f926..6552f39a7c4 100644 --- a/src/definitions/address.ts +++ b/src/definitions/address.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to addresses. */ @@ -99,36 +97,3 @@ export interface AddressDefinitions { // A list of timezones names. time_zone: string[]; } - -/** - * Internal: A list of all keys for the AddressDefinitions. - */ -export const ADDRESS = allOf()( - 'postcode_by_state', - 'postcode', - - 'city_name', - 'city_prefix', - 'city_suffix', - - 'country', - 'state', - 'state_abbr', - 'county', - - 'direction_abbr', - 'direction', - - 'building_number', - - 'street_prefix', - 'street_suffix', - - 'street_address', - 'secondary_address', - - 'country_code', - 'country_code_alpha_3', - - 'time_zone' -); diff --git a/src/definitions/animal.ts b/src/definitions/animal.ts index 68fe0db24ae..d056e4021f0 100644 --- a/src/definitions/animal.ts +++ b/src/definitions/animal.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to animals. */ @@ -19,23 +17,3 @@ export interface AnimalDefinitions { snake: string[]; type: string[]; } - -/** - * Internal: A list of all keys for the AnimalDefinitions. - */ -export const ANIMAL = allOf()( - 'dog', - 'cat', - 'snake', - 'bear', - 'lion', - 'cetacean', - 'insect', - 'crocodilia', - 'cow', - 'bird', - 'fish', - 'rabbit', - 'horse', - 'type' -); diff --git a/src/definitions/commerce.ts b/src/definitions/commerce.ts index dbe22f69949..eb1064638a7 100644 --- a/src/definitions/commerce.ts +++ b/src/definitions/commerce.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to commerce. */ @@ -39,13 +37,3 @@ export interface CommerceProductNameDefinitions { */ product: string[]; } - -/** - * Internal: A list of all keys for the CommerceDefinitions. - */ -export const COMMERCE = allOf()( - 'color', - 'department', - 'product_name', - 'product_description' -); diff --git a/src/definitions/company.ts b/src/definitions/company.ts index 35947bde9f7..89999ced4ca 100644 --- a/src/definitions/company.ts +++ b/src/definitions/company.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to companies. */ @@ -33,18 +31,3 @@ export interface CompanyDefinitions { */ suffix: string[]; } - -/** - * Internal: A list of all keys for the CompanyDefinitions. - */ -export const COMPANY = allOf()( - 'bs_adjective', - 'bs_noun', - 'bs_verb', - - 'adjective', - 'descriptor', - 'noun', - - 'suffix' -); diff --git a/src/definitions/database.ts b/src/definitions/database.ts index 935f35fcd98..47ab603d52c 100644 --- a/src/definitions/database.ts +++ b/src/definitions/database.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to databases. */ @@ -21,13 +19,3 @@ export interface DatabaseDefinitions { */ type: string[]; } - -/** - * Internal: A list of all keys for the DatabaseDefinitions. - */ -export const DATABASE = allOf()( - 'collation', - 'column', - 'engine', - 'type' -); diff --git a/src/definitions/date.ts b/src/definitions/date.ts index 2738bdb5e84..a6d74722e8a 100644 --- a/src/definitions/date.ts +++ b/src/definitions/date.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to dates. */ @@ -37,8 +35,3 @@ export interface DateEntryDefinition { */ abbr_context?: string[]; } - -/** - * Internal: A list of all keys for the DateDefinitions. - */ -export const DATE = allOf()('month', 'weekday'); diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index b696d47a2ff..69a6c5cb24f 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -1,35 +1,19 @@ import type { AddressDefinitions } from './address'; -import { ADDRESS } from './address'; import type { AnimalDefinitions } from './animal'; -import { ANIMAL } from './animal'; import type { CommerceDefinitions } from './commerce'; -import { COMMERCE } from './commerce'; import type { CompanyDefinitions } from './company'; -import { COMPANY } from './company'; import type { DatabaseDefinitions } from './database'; -import { DATABASE } from './database'; import type { DateDefinitions } from './date'; -import { DATE } from './date'; import type { FinanceDefinitions } from './finance'; -import { FINANCE } from './finance'; import type { HackerDefinitions } from './hacker'; -import { HACKER } from './hacker'; import type { InternetDefinitions } from './internet'; -import { INTERNET } from './internet'; import type { LoremDefinitions } from './lorem'; -import { LOREM } from './lorem'; import type { MusicDefinitions } from './music'; -import { MUSIC } from './music'; import type { NameDefinitions } from './name'; -import { NAME } from './name'; import type { PhoneNumberDefinitions } from './phone_number'; -import { PHONE_NUMBER } from './phone_number'; import type { SystemDefinitions } from './system'; -import { SYSTEM } from './system'; import type { VehicleDefinitions } from './vehicle'; -import { VEHICLE } from './vehicle'; import type { WordDefinitions } from './word'; -import { WORD } from './word'; /** * The definitions as used by the Faker modules. @@ -84,29 +68,3 @@ export type DefinitionTypes = { } & { readonly [module in keyof Definitions]: Array; }; - -/** - * Internal: List off all modules and their properties, - * that needs to have a fallback generated in Faker.loadDefinitions(). - */ -export const DEFINITIONS: DefinitionTypes = { - title: 'metadata', - separator: 'metadata', - - address: ADDRESS, - animal: ANIMAL, - company: COMPANY, - commerce: COMMERCE, - database: DATABASE, - date: DATE, - finance: FINANCE, - hacker: HACKER, - internet: INTERNET, - lorem: LOREM, - music: MUSIC, - name: NAME, - phone_number: PHONE_NUMBER, - system: SYSTEM, - vehicle: VEHICLE, - word: WORD, -}; diff --git a/src/definitions/finance.ts b/src/definitions/finance.ts index 633d087f8f2..e5f4553bbfe 100644 --- a/src/definitions/finance.ts +++ b/src/definitions/finance.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to finances. */ @@ -38,13 +36,3 @@ export interface FinanceCurrencyEntryDefinitions { */ symbol: string; } - -/** - * Internal: A list of all keys for the FinanceDefinitions. - */ -export const FINANCE = allOf()( - 'account_type', - 'credit_card', - 'currency', - 'transaction_type' -); diff --git a/src/definitions/hacker.ts b/src/definitions/hacker.ts index 00aa3a40875..8a23c88a744 100644 --- a/src/definitions/hacker.ts +++ b/src/definitions/hacker.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to computers. */ @@ -33,15 +31,3 @@ export interface HackerDefinitions { */ verb: string[]; } - -/** - * Internal: A list of all keys for the HackerDefinitions. - */ -export const HACKER = allOf()( - 'abbreviation', - 'adjective', - 'ingverb', - 'noun', - 'phrase', - 'verb' -); diff --git a/src/definitions/index.ts b/src/definitions/index.ts index 9eb4c3f3ea1..da01ed15489 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -7,7 +7,6 @@ export type { export type { CompanyDefinitions } from './company'; export type { DatabaseDefinitions } from './database'; export type { DateDefinitions, DateEntryDefinition } from './date'; -export { DEFINITIONS } from './definitions'; export type { DefinitionTypes, LocaleDefinition } from './definitions'; export type { FinanceCurrencyEntryDefinitions, diff --git a/src/definitions/internet.ts b/src/definitions/internet.ts index 562f77e9e8c..3687229f3d7 100644 --- a/src/definitions/internet.ts +++ b/src/definitions/internet.ts @@ -1,5 +1,4 @@ import type { EmojiType } from '../internet'; -import { allOf } from './utils'; /** * The possible definitions related to internet stuff. @@ -22,13 +21,3 @@ export interface InternetDefinitions { */ emoji: Record; } - -/** - * Internal: A list of all keys for the InternetDefinitions. - */ -export const INTERNET = allOf()( - 'domain_suffix', - 'example_email', - 'free_email', - 'emoji' -); diff --git a/src/definitions/lorem.ts b/src/definitions/lorem.ts index eb548e46fd4..202a527f067 100644 --- a/src/definitions/lorem.ts +++ b/src/definitions/lorem.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to lorem texts. */ @@ -9,8 +7,3 @@ export interface LoremDefinitions { */ words: string[]; } - -/** - * Internal: A list of all keys for the LoremDefinitions. - */ -export const LOREM = allOf()('words'); diff --git a/src/definitions/music.ts b/src/definitions/music.ts index 1f2ffdd80bd..eaa340aed8a 100644 --- a/src/definitions/music.ts +++ b/src/definitions/music.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to music. */ @@ -9,8 +7,3 @@ export interface MusicDefinitions { */ genre: string[]; } - -/** - * Internal: A list of all keys for the MusicDefinitions. - */ -export const MUSIC = allOf()('genre'); diff --git a/src/definitions/name.ts b/src/definitions/name.ts index 57926649b09..a5156410cc5 100644 --- a/src/definitions/name.ts +++ b/src/definitions/name.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to people's names. */ @@ -41,33 +39,3 @@ export interface NameTitleDefinitions { job: string[]; level?: string[]; } - -/** - * Internal: A list of all keys for the NameDefinitions. - */ -export const NAME = allOf()( - 'gender', - 'binary_gender', - - 'prefix', - 'female_prefix', - 'male_prefix', - - 'first_name', - 'female_first_name', - 'male_first_name', - - 'middle_name', - 'female_middle_name', - 'male_middle_name', - - 'last_name', - 'female_last_name', - 'male_last_name', - - 'suffix', - - 'name', - - 'title' -); diff --git a/src/definitions/phone_number.ts b/src/definitions/phone_number.ts index ed7353b552d..1fb69ad2146 100644 --- a/src/definitions/phone_number.ts +++ b/src/definitions/phone_number.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to phone numbers. */ @@ -14,8 +12,3 @@ export interface PhoneNumberDefinitions { */ formats: string[]; } - -/** - * Internal: A list of all keys for the PhoneNumberDefinitions. - */ -export const PHONE_NUMBER = allOf()('formats'); diff --git a/src/definitions/system.ts b/src/definitions/system.ts index 5c9039b43d1..c3e252329bd 100644 --- a/src/definitions/system.ts +++ b/src/definitions/system.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to files and the system. */ @@ -23,11 +21,3 @@ export interface SystemMimeTypeEntryDefinitions { compressible?: boolean; charset?: string; } - -/** - * Internal: A list of all keys for the SystemDefinitions. - */ -export const SYSTEM = allOf()( - 'directoryPaths', - 'mimeTypes' -); diff --git a/src/definitions/utils.ts b/src/definitions/utils.ts deleted file mode 100644 index 03764c1dfeb..00000000000 --- a/src/definitions/utils.ts +++ /dev/null @@ -1,12 +0,0 @@ -// https://stackoverflow.com/a/53395649/4573065 -export type AllOf = ['Needs to be all of', T]; - -/** - * Creates a function that requires all keys of the generic type to be used as parameters. - * The function itself will return the given parameters. - */ -export function allOf(): ( - ...array: U & ([T] extends [U[number]] ? unknown : AllOf[]) -) => U & ([T] extends [U[number]] ? unknown : AllOf[]) { - return (...array) => array; -} diff --git a/src/definitions/vehicle.ts b/src/definitions/vehicle.ts index 7fdc11f1de1..71c35851516 100644 --- a/src/definitions/vehicle.ts +++ b/src/definitions/vehicle.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to vehicles. */ @@ -25,14 +23,3 @@ export interface VehicleDefinitions { */ type: string[]; } - -/** - * Internal: A list of all keys for the VehicleDefinitions. - */ -export const VEHICLE = allOf()( - 'bicycle_type', - 'fuel', - 'manufacturer', - 'model', - 'type' -); diff --git a/src/definitions/word.ts b/src/definitions/word.ts index dcbe47dd508..3e502215037 100644 --- a/src/definitions/word.ts +++ b/src/definitions/word.ts @@ -1,5 +1,3 @@ -import { allOf } from './utils'; - /** * The possible definitions related to words. */ @@ -12,16 +10,3 @@ export interface WordDefinitions { preposition: string[]; verb: string[]; } - -/** - * Internal: A list of all keys for the WordDefinitions. - */ -export const WORD = allOf()( - 'adjective', - 'adverb', - 'conjunction', - 'interjection', - 'noun', - 'preposition', - 'verb' -); diff --git a/src/faker.ts b/src/faker.ts index 5ae0bd9c4a3..58209d34330 100644 --- a/src/faker.ts +++ b/src/faker.ts @@ -6,7 +6,6 @@ import { Database } from './database'; import { Datatype } from './datatype'; import { _Date } from './date'; import type { LocaleDefinition } from './definitions'; -import { DEFINITIONS } from './definitions'; import { FakerError } from './errors/faker-error'; import { Fake } from './fake'; import { Finance } from './finance'; @@ -43,6 +42,11 @@ export interface FakerOptions { localeFallback?: UsableLocale; } +const metadataKeys: ReadonlyArray = [ + 'title', + 'separator', +]; + export class Faker { locales: UsedLocales; locale: UsableLocale; @@ -157,7 +161,7 @@ export class Faker { let result = target[module]; if (result) { return result; - } else if (DEFINITIONS[module] === 'metadata') { + } else if (metadataKeys.includes(module)) { return resolveBaseData(module); } else { result = moduleLoader(module);