From 3e0ffb20540ef6b496c3de34f7b8e8f9401d2a63 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 01:49:12 +0100 Subject: [PATCH 01/37] feat(types): provide strong typing for locales --- src/address.ts | 2 + src/definitions.ts | 276 +++++++++++++++++++++++------ src/index.ts | 148 ++-------------- src/locales/en/address/index.ts | 35 ++-- src/locales/en/address/postcode.ts | 4 +- src/locales/en/animal/index.ts | 3 +- src/locales/en/name/index.ts | 19 +- src/locales/en/name/title.ts | 6 +- src/name.ts | 4 +- 9 files changed, 284 insertions(+), 213 deletions(-) diff --git a/src/address.ts b/src/address.ts index 7e6b0fdcc4e..d813a85f8dd 100644 --- a/src/address.ts +++ b/src/address.ts @@ -1,4 +1,5 @@ import type { Faker } from '.'; +import { Format, Formats } from './definitions'; import type { Fake } from './fake'; import type { Helpers } from './helpers'; @@ -235,6 +236,7 @@ export class Address { */ secondaryAddress(): string { return this.Helpers.replaceSymbolWithNumber( + // TODO ST-DDT 2022-01-30: this.faker.definitions.address.secondary_address this.faker.random.arrayElement(['Apt. ###', 'Suite ###']) ); } diff --git a/src/definitions.ts b/src/definitions.ts index db142429ba3..566c985dd7e 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -1,38 +1,196 @@ +import { Address } from './address'; + +type AllOf = ['Needs to be all of', T]; +const allOf = + () => + ( + ...array: U & ([T] extends [U[number]] ? unknown : AllOf[]) + ) => + array; + +// A list of values that can be used as is. +export type Values = readonly T[]; +export type Texts = Values; +// A strings that might contain a placeholder for fake(). +export type Format = string; +export type Formats = readonly Format[]; + +export type Range = { + min: number; + max: number; +}; + +// ----------------------------------------------------------------------------- + +export interface AddressDefinitions { + // zipCodeByState expects only { [state: string]: Range } + postcode_by_state: Formats | { [state: string]: Range }; + postcode: Format | Formats; + + // Names of actual cities + city_name?: Texts; + // Common city prefixes + city_prefix: Texts; + // Common city suffixes + city_suffix: Texts; + + // The names of all countries + country: Texts; + // The names of this country's states + state: Texts; + state_abbr: Texts; + // The names of counties inside the country or state + county: Texts; + + // The names of the compass directions. + // First the 4 cardinal directions, then the 4 ordinal directions + direction: Texts; + direction_abbr: Texts; + + // Common street prefixes + street_prefix: Texts; + // Common street suffixes + street_suffix: Texts; + + // The address "inside" an address/e.g. an apartment or office. + secondary_address: Texts; + + // The iso country codes + country_code: Texts; // Alpha 2 + country_code_alpha_3: Texts; + + // The ISO? names of the timezones + time_zone: Texts; +} + +export const addresses = allOf()( + 'postcode_by_state', + 'postcode', + + 'city_name', + 'city_prefix', + 'city_suffix', + + 'country', + 'state', + 'state_abbr', + 'county', + + 'direction_abbr', + 'direction', + + 'street_prefix', + 'street_suffix', + + 'secondary_address', + + 'country_code', + 'country_code_alpha_3', + + 'time_zone' +); + +// ----------------------------------------------------------------------------- + +export interface AnimalDefinitions { + bear: Texts; + bird: Texts; + cat: Texts; + cetacean: Texts; + cow: Texts; + crocodilia: Texts; + dog: Texts; + fish: Texts; + horse: Texts; + insect: Texts; + lion: Texts; + rabbit: Texts; + snake: Texts; + type: Texts; +} + +export const animals = allOf()( + 'dog', + 'cat', + 'snake', + 'bear', + 'lion', + 'cetacean', + 'insect', + 'crocodilia', + 'cow', + 'bird', + 'fish', + 'rabbit', + 'horse', + 'type' +); + +// ------------------------- + +export interface NameDefinitions { + gender: Texts; + binary_gender: Texts; + + prefix?: Texts; + female_prefix?: Texts; + male_prefix?: Texts; + + first_name?: Texts; + female_first_name?: Texts; + male_first_name?: Texts; + + middle_name?: Texts; + female_middle_name?: Texts; + male_middle_name?: Texts; + + last_name?: Texts; + female_last_name?: Texts; + male_last_name?: Texts; + + suffix: Texts; + + name: Formats; + + title: NameTitleDefinitions; +} + +export interface NameTitleDefinitions { + descriptor?: Texts; + job: Texts; + level?: Texts; +} + +export const names = 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' +); + export interface Definitions { - address: { - city_name; - city_prefix; - city_suffix; - country_code_alpha_3; - country_code; - country; - county; - direction_abbr; - direction; - postcode_by_state; - postcode: string | string[]; - state_abbr; - state; - street_prefix; - street_suffix; - time_zone; - }; - animal: { - bear; - bird; - cat; - cetacean; - cow; - crocodilia; - dog; - fish; - horse; - insect; - lion; - rabbit; - snake; - type; - }; + address: AddressDefinitions; + animal: AnimalDefinitions; commerce: { color; department; @@ -83,28 +241,7 @@ export interface Definitions { music: { genre; }; - name: { - binary_gender; - female_first_name; - female_last_name; - female_middle_name; - female_prefix; - first_name; - gender; - last_name; - male_first_name; - male_last_name; - male_middle_name; - male_prefix; - middle_name; - prefix; - suffix; - title: { - descriptor; - level; - job; - }; - }; + name: NameDefinitions; phone_number: { formats; }; @@ -129,3 +266,30 @@ export interface Definitions { verb: string[]; }; } + +export interface DefinitionTypes { + readonly title: string; + readonly separator: string; + + readonly address: typeof addresses; + readonly animal: typeof animals; + readonly name: typeof names; + + readonly company: string[]; + readonly lorem: string[]; + readonly hacker: string[]; + readonly phone_number: string[]; + readonly finance: string[]; + readonly internet: string[]; + readonly commerce: string[]; + readonly database: string[]; + readonly system: string[]; + readonly date: string[]; + readonly vehicle: string[]; + readonly music: string[]; + readonly word: string[]; +} + +export const definitions: Partial = { + animal: animals, +}; diff --git a/src/index.ts b/src/index.ts index d740faea929..2007c1f9e26 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,14 @@ import { Company } from './company'; import { Database } from './database'; import { Datatype } from './datatype'; import { _Date } from './date'; -import type { Definitions } from './definitions'; +import { addresses, animals, names } from './definitions'; +import type { + AddressDefinitions, + AnimalDefinitions, + Definitions, + DefinitionTypes, + NameDefinitions, +} from './definitions'; import { Fake } from './fake'; import { Finance } from './finance'; import { Git } from './git'; @@ -34,45 +41,8 @@ export interface LocaleDefinition { title: string; separator?: string; - address?: Partial<{ - building_number: any[]; - city_name: any[]; - city_prefix: any[]; - city_suffix: any[]; - city: any[]; - country_code_alpha_3: any[]; - country_code: any[]; - country: any[]; - county: any[]; - default_country: any[]; - direction_abbr: any[]; - direction: any[]; - postcode_by_state: any[]; - postcode: any[]; - secondary_address: any[]; - state_abbr: any[]; - state: any[]; - street_address: any[]; - street_name: any[]; - street_suffix: any[]; - time_zone: any[]; - }>; - animal?: Partial<{ - bear: any[]; - bird: any[]; - cat: any[]; - cetacean: any[]; - cow: any[]; - crocodilia: any[]; - dog: any[]; - fish: any[]; - horse: any[]; - insect: any[]; - lion: any[]; - rabbit: any[]; - snake: any[]; - type: any[]; - }>; + address?: Partial; + animal?: Partial; app?: Partial<{ author: any[]; name: any[]; @@ -139,28 +109,7 @@ export interface LocaleDefinition { music?: Partial<{ genre: any[]; }>; - name?: Partial<{ - binary_gender: string[]; - female_first_name: string[]; - female_last_name: string[]; - female_middle_name: string[]; - female_prefix: string[]; - first_name: string[]; - gender: string[]; - last_name: string[]; - male_first_name: string[]; - male_last_name: string[]; - male_middle_name: string[]; - male_prefix: string[]; - name: string[]; - prefix: string[]; - suffix: string[]; - title: { - descriptor?: string[]; - job: string[]; - level?: string[]; - }; - }>; + name?: Partial; phone_number?: Partial<{ formats: any[]; }>; @@ -202,27 +151,6 @@ export interface FakerOptions { localeFallback?: UsableLocale; } -export interface DefinitionTypes { - readonly name: string[]; - readonly address: string[]; - readonly animal: string[]; - readonly company: string[]; - readonly lorem: string[]; - readonly hacker: string[]; - readonly phone_number: string[]; - readonly finance: string[]; - readonly internet: string[]; - readonly commerce: string[]; - readonly database: string[]; - readonly system: string[]; - readonly date: string[]; - readonly vehicle: string[]; - readonly music: string[]; - readonly word: string[]; - readonly title: string | string[]; - readonly separator: string | string[]; -} - export class Faker { locales: UsedLocales; locale: UsableLocale; @@ -231,57 +159,9 @@ export class Faker { // @ts-expect-error: will be lazy filled by constructor readonly definitions: Definitions = {}; private readonly definitionTypes: DefinitionTypes = { - name: [ - 'first_name', - 'last_name', - 'prefix', - 'suffix', - 'binary_gender', - 'gender', - 'title', - 'male_prefix', - 'female_prefix', - 'male_first_name', - 'female_first_name', - 'male_middle_name', - 'female_middle_name', - 'male_last_name', - 'female_last_name', - ], - address: [ - 'city_name', - 'city_prefix', - 'city_suffix', - 'street_suffix', - 'county', - 'country', - 'country_code', - 'country_code_alpha_3', - 'state', - 'state_abbr', - 'street_prefix', - 'postcode', - 'postcode_by_state', - 'direction', - 'direction_abbr', - 'time_zone', - ], - animal: [ - 'dog', - 'cat', - 'snake', - 'bear', - 'lion', - 'cetacean', - 'insect', - 'crocodilia', - 'cow', - 'bird', - 'fish', - 'rabbit', - 'horse', - 'type', - ], + address: addresses, + animal: animals, + name: names, company: [ 'adjective', 'noun', diff --git a/src/locales/en/address/index.ts b/src/locales/en/address/index.ts index d0677de66cc..27c071aa886 100644 --- a/src/locales/en/address/index.ts +++ b/src/locales/en/address/index.ts @@ -1,3 +1,4 @@ +import type { AddressDefinitions } from '../../../definitions'; import building_number from './building_number'; import city from './city'; import city_name from './city_name'; @@ -20,28 +21,38 @@ import street_name from './street_name'; import street_suffix from './street_suffix'; import time_zone from './time_zone'; -const address: any = { - building_number, +const address = { + postcode, + postcode_by_state, + city, city_name, city_prefix, city_suffix, + country, - country_code, - country_code_alpha_3, + state, + state_abbr, county, - default_country, + direction, direction_abbr, - postcode, - postcode_by_state, + + // street_prefix + street_suffix, + secondary_address, - state, - state_abbr, + + country_code, + country_code_alpha_3, + + time_zone, + + // Extra street_address, street_name, - street_suffix, - time_zone, -}; + default_country, + building_number, +} as Partial; export default address; diff --git a/src/locales/en/address/postcode.ts b/src/locales/en/address/postcode.ts index 4433f068b5e..24b2d2af457 100644 --- a/src/locales/en/address/postcode.ts +++ b/src/locales/en/address/postcode.ts @@ -1 +1,3 @@ -export default ['#####', '#####-####']; +import type { Formats } from '../../../definitions'; + +export default ['#####', '#####-####'] as Formats; diff --git a/src/locales/en/animal/index.ts b/src/locales/en/animal/index.ts index f576b998579..33625a81f44 100644 --- a/src/locales/en/animal/index.ts +++ b/src/locales/en/animal/index.ts @@ -1,3 +1,4 @@ +import type { AnimalDefinitions } from '../../../definitions'; import bear from './bear'; import bird from './bird'; import cat from './cat'; @@ -13,7 +14,7 @@ import rabbit from './rabbit'; import snake from './snake'; import type from './type'; -const animal: any = { +const animal: AnimalDefinitions = { bear, bird, cat, diff --git a/src/locales/en/name/index.ts b/src/locales/en/name/index.ts index 6e21934a33d..8241b4ad716 100644 --- a/src/locales/en/name/index.ts +++ b/src/locales/en/name/index.ts @@ -1,3 +1,4 @@ +import type { NameDefinitions } from '../../../definitions'; import binary_gender from './binary_gender'; import female_first_name from './female_first_name'; import first_name from './first_name'; @@ -9,16 +10,22 @@ import prefix from './prefix'; import suffix from './suffix'; import title from './title'; -const name: any = { +const name: NameDefinitions = { binary_gender, - female_first_name, - first_name, gender, - last_name, - male_first_name, - name: name_, + prefix, + + first_name, + female_first_name, + male_first_name, + + last_name, + suffix, + + name: name_, + title, }; diff --git a/src/locales/en/name/title.ts b/src/locales/en/name/title.ts index b18b6004c1b..ec599841aa0 100644 --- a/src/locales/en/name/title.ts +++ b/src/locales/en/name/title.ts @@ -1,4 +1,6 @@ -export default { +import type { NameTitleDefinitions } from '../../../definitions'; + +const title: NameTitleDefinitions = { descriptor: [ 'Lead', 'Senior', @@ -90,3 +92,5 @@ export default { 'Strategist', ], }; + +export default title; diff --git a/src/name.ts b/src/name.ts index 84f1623d60a..278cb17c4cc 100644 --- a/src/name.ts +++ b/src/name.ts @@ -110,11 +110,11 @@ export class Name { } if (gender === 0) { return this.faker.random.arrayElement( - this.faker.locales[this.faker.locale].name.male_middle_name + this.faker.definitions.name.male_middle_name ); } else { return this.faker.random.arrayElement( - this.faker.locales[this.faker.locale].name.female_middle_name + this.faker.definitions.name.female_middle_name ); } } From 41419d719c555ccf5bc11911e6b8b73d46b0b7e3 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 02:14:24 +0100 Subject: [PATCH 02/37] fix: use only a single definitions instance --- src/definitions.ts | 56 +++++++++++++++++++++++++++++++++++++- src/index.ts | 67 +++------------------------------------------- 2 files changed, 58 insertions(+), 65 deletions(-) diff --git a/src/definitions.ts b/src/definitions.ts index 566c985dd7e..5ec53dcfd18 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -290,6 +290,60 @@ export interface DefinitionTypes { readonly word: string[]; } -export const definitions: Partial = { +export const definitions: DefinitionTypes = { + title: '', + separator: '', + + address: addresses, animal: animals, + name: names, + + company: [ + 'adjective', + 'noun', + 'descriptor', + 'bs_adjective', + 'bs_noun', + 'bs_verb', + 'suffix', + ], + lorem: ['words'], + hacker: ['abbreviation', 'adjective', 'noun', 'verb', 'ingverb', 'phrase'], + phone_number: ['formats'], + finance: [ + 'account_type', + 'transaction_type', + 'currency', + 'iban', + 'credit_card', + ], + internet: [ + 'avatar_uri', + 'domain_suffix', + 'free_email', + 'example_email', + 'password', + ], + commerce: [ + 'color', + 'department', + 'product_name', + 'price', + 'categories', + 'product_description', + ], + database: ['collation', 'column', 'engine', 'type'], + system: ['mimeTypes', 'directoryPaths'], + date: ['month', 'weekday'], + vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], + music: ['genre'], + word: [ + 'adjective', + 'adverb', + 'conjunction', + 'interjection', + 'noun', + 'preposition', + 'verb', + ], }; diff --git a/src/index.ts b/src/index.ts index 2007c1f9e26..73c994937b0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,6 @@ import { Company } from './company'; import { Database } from './database'; import { Datatype } from './datatype'; import { _Date } from './date'; -import { addresses, animals, names } from './definitions'; import type { AddressDefinitions, AnimalDefinitions, @@ -13,6 +12,7 @@ import type { DefinitionTypes, NameDefinitions, } from './definitions'; +import { definitions } from './definitions'; import { Fake } from './fake'; import { Finance } from './finance'; import { Git } from './git'; @@ -158,69 +158,8 @@ export class Faker { // @ts-expect-error: will be lazy filled by constructor readonly definitions: Definitions = {}; - private readonly definitionTypes: DefinitionTypes = { - address: addresses, - animal: animals, - name: names, - company: [ - 'adjective', - 'noun', - 'descriptor', - 'bs_adjective', - 'bs_noun', - 'bs_verb', - 'suffix', - ], - lorem: ['words'], - hacker: ['abbreviation', 'adjective', 'noun', 'verb', 'ingverb', 'phrase'], - phone_number: ['formats'], - finance: [ - 'account_type', - 'transaction_type', - 'currency', - 'iban', - 'credit_card', - ], - internet: [ - 'avatar_uri', - 'domain_suffix', - 'free_email', - 'example_email', - 'password', - ], - commerce: [ - 'color', - 'department', - 'product_name', - 'price', - 'categories', - 'product_description', - ], - database: ['collation', 'column', 'engine', 'type'], - system: ['mimeTypes', 'directoryPaths'], - date: ['month', 'weekday'], - vehicle: [ - 'vehicle', - 'manufacturer', - 'model', - 'type', - 'fuel', - 'vin', - 'color', - ], - music: ['genre'], - word: [ - 'adjective', - 'adverb', - 'conjunction', - 'interjection', - 'noun', - 'preposition', - 'verb', - ], - title: '', - separator: '', - }; + // This will eventually be replaced by just the imported definitions + private readonly definitionTypes: DefinitionTypes = definitions; seedValue?: any[] | any; From f5dc95a1909e9d88db461d616096999beebe0037 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 02:20:06 +0100 Subject: [PATCH 03/37] chore: cleanup --- src/definitions.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/definitions.ts b/src/definitions.ts index 5ec53dcfd18..a39550b83e7 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -1,5 +1,4 @@ -import { Address } from './address'; - +// https://stackoverflow.com/a/53395649/4573065 type AllOf = ['Needs to be all of', T]; const allOf = () => From 72c7da247a6df6b3fcc187b1705eebcd6cfe7415 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 11:47:48 +0100 Subject: [PATCH 04/37] chore: improve comment --- src/definitions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/definitions.ts b/src/definitions.ts index a39550b83e7..c9ae2a28a9a 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -22,7 +22,7 @@ export type Range = { // ----------------------------------------------------------------------------- export interface AddressDefinitions { - // zipCodeByState expects only { [state: string]: Range } + // address.zipCodeByState() expects only { [state: string]: Range } postcode_by_state: Formats | { [state: string]: Range }; postcode: Format | Formats; From 798e4fedbc17354ef8d5cffaacf31b867b12f19b Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 12:16:47 +0100 Subject: [PATCH 05/37] chore: move definitions to separate files --- src/address.ts | 1 - src/definitions.ts | 348 --------------------------------- src/definitions/address.ts | 70 +++++++ src/definitions/animal.ts | 36 ++++ src/definitions/definitions.ts | 166 ++++++++++++++++ src/definitions/index.ts | 20 ++ src/definitions/name.ts | 62 ++++++ src/definitions/utils.ts | 20 ++ 8 files changed, 374 insertions(+), 349 deletions(-) delete mode 100644 src/definitions.ts create mode 100644 src/definitions/address.ts create mode 100644 src/definitions/animal.ts create mode 100644 src/definitions/definitions.ts create mode 100644 src/definitions/index.ts create mode 100644 src/definitions/name.ts create mode 100644 src/definitions/utils.ts diff --git a/src/address.ts b/src/address.ts index d813a85f8dd..c510b46c040 100644 --- a/src/address.ts +++ b/src/address.ts @@ -1,5 +1,4 @@ import type { Faker } from '.'; -import { Format, Formats } from './definitions'; import type { Fake } from './fake'; import type { Helpers } from './helpers'; diff --git a/src/definitions.ts b/src/definitions.ts deleted file mode 100644 index c9ae2a28a9a..00000000000 --- a/src/definitions.ts +++ /dev/null @@ -1,348 +0,0 @@ -// https://stackoverflow.com/a/53395649/4573065 -type AllOf = ['Needs to be all of', T]; -const allOf = - () => - ( - ...array: U & ([T] extends [U[number]] ? unknown : AllOf[]) - ) => - array; - -// A list of values that can be used as is. -export type Values = readonly T[]; -export type Texts = Values; -// A strings that might contain a placeholder for fake(). -export type Format = string; -export type Formats = readonly Format[]; - -export type Range = { - min: number; - max: number; -}; - -// ----------------------------------------------------------------------------- - -export interface AddressDefinitions { - // address.zipCodeByState() expects only { [state: string]: Range } - postcode_by_state: Formats | { [state: string]: Range }; - postcode: Format | Formats; - - // Names of actual cities - city_name?: Texts; - // Common city prefixes - city_prefix: Texts; - // Common city suffixes - city_suffix: Texts; - - // The names of all countries - country: Texts; - // The names of this country's states - state: Texts; - state_abbr: Texts; - // The names of counties inside the country or state - county: Texts; - - // The names of the compass directions. - // First the 4 cardinal directions, then the 4 ordinal directions - direction: Texts; - direction_abbr: Texts; - - // Common street prefixes - street_prefix: Texts; - // Common street suffixes - street_suffix: Texts; - - // The address "inside" an address/e.g. an apartment or office. - secondary_address: Texts; - - // The iso country codes - country_code: Texts; // Alpha 2 - country_code_alpha_3: Texts; - - // The ISO? names of the timezones - time_zone: Texts; -} - -export const addresses = allOf()( - 'postcode_by_state', - 'postcode', - - 'city_name', - 'city_prefix', - 'city_suffix', - - 'country', - 'state', - 'state_abbr', - 'county', - - 'direction_abbr', - 'direction', - - 'street_prefix', - 'street_suffix', - - 'secondary_address', - - 'country_code', - 'country_code_alpha_3', - - 'time_zone' -); - -// ----------------------------------------------------------------------------- - -export interface AnimalDefinitions { - bear: Texts; - bird: Texts; - cat: Texts; - cetacean: Texts; - cow: Texts; - crocodilia: Texts; - dog: Texts; - fish: Texts; - horse: Texts; - insect: Texts; - lion: Texts; - rabbit: Texts; - snake: Texts; - type: Texts; -} - -export const animals = allOf()( - 'dog', - 'cat', - 'snake', - 'bear', - 'lion', - 'cetacean', - 'insect', - 'crocodilia', - 'cow', - 'bird', - 'fish', - 'rabbit', - 'horse', - 'type' -); - -// ------------------------- - -export interface NameDefinitions { - gender: Texts; - binary_gender: Texts; - - prefix?: Texts; - female_prefix?: Texts; - male_prefix?: Texts; - - first_name?: Texts; - female_first_name?: Texts; - male_first_name?: Texts; - - middle_name?: Texts; - female_middle_name?: Texts; - male_middle_name?: Texts; - - last_name?: Texts; - female_last_name?: Texts; - male_last_name?: Texts; - - suffix: Texts; - - name: Formats; - - title: NameTitleDefinitions; -} - -export interface NameTitleDefinitions { - descriptor?: Texts; - job: Texts; - level?: Texts; -} - -export const names = 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' -); - -export interface Definitions { - address: AddressDefinitions; - animal: AnimalDefinitions; - commerce: { - color; - department; - product_description; - product_name; - }; - company: { - adjective; - bs_adjective; - bs_noun; - bs_verb; - descriptor; - noun; - suffix; - }; - database: { - collation; - column; - engine; - type; - }; - date: { - month; - weekday; - }; - finance: { - account_type; - credit_card; - currency: Record; - transaction_type; - }; - hacker: { - abbreviation; - adjective; - ingverb; - noun; - phrase; - verb; - }; - internet: { - domain_suffix; - example_email; - free_email; - }; - lorem: { - words; - }; - music: { - genre; - }; - name: NameDefinitions; - phone_number: { - formats; - }; - system: { - directoryPaths; - mimeTypes; - }; - vehicle: { - bicycle_type; - fuel; - manufacturer; - model; - type; - }; - word: { - adjective: string[]; - adverb: string[]; - conjunction: string[]; - interjection: string[]; - noun: string[]; - preposition: string[]; - verb: string[]; - }; -} - -export interface DefinitionTypes { - readonly title: string; - readonly separator: string; - - readonly address: typeof addresses; - readonly animal: typeof animals; - readonly name: typeof names; - - readonly company: string[]; - readonly lorem: string[]; - readonly hacker: string[]; - readonly phone_number: string[]; - readonly finance: string[]; - readonly internet: string[]; - readonly commerce: string[]; - readonly database: string[]; - readonly system: string[]; - readonly date: string[]; - readonly vehicle: string[]; - readonly music: string[]; - readonly word: string[]; -} - -export const definitions: DefinitionTypes = { - title: '', - separator: '', - - address: addresses, - animal: animals, - name: names, - - company: [ - 'adjective', - 'noun', - 'descriptor', - 'bs_adjective', - 'bs_noun', - 'bs_verb', - 'suffix', - ], - lorem: ['words'], - hacker: ['abbreviation', 'adjective', 'noun', 'verb', 'ingverb', 'phrase'], - phone_number: ['formats'], - finance: [ - 'account_type', - 'transaction_type', - 'currency', - 'iban', - 'credit_card', - ], - internet: [ - 'avatar_uri', - 'domain_suffix', - 'free_email', - 'example_email', - 'password', - ], - commerce: [ - 'color', - 'department', - 'product_name', - 'price', - 'categories', - 'product_description', - ], - database: ['collation', 'column', 'engine', 'type'], - system: ['mimeTypes', 'directoryPaths'], - date: ['month', 'weekday'], - vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], - music: ['genre'], - word: [ - 'adjective', - 'adverb', - 'conjunction', - 'interjection', - 'noun', - 'preposition', - 'verb', - ], -}; diff --git a/src/definitions/address.ts b/src/definitions/address.ts new file mode 100644 index 00000000000..da28b4afd8c --- /dev/null +++ b/src/definitions/address.ts @@ -0,0 +1,70 @@ +import type { Format, Formats, Texts } from './utils'; +import { allOf } from './utils'; + +export interface AddressDefinitions { + // address.zipCodeByState() expects only { [state: string]: Range } + postcode_by_state: Formats | { [state: string]: Range }; + postcode: Format | Formats; + + // Names of actual cities + city_name?: Texts; + // Common city prefixes + city_prefix: Texts; + // Common city suffixes + city_suffix: Texts; + + // The names of all countries + country: Texts; + // The names of this country's states + state: Texts; + state_abbr: Texts; + // The names of counties inside the country or state + county: Texts; + + // The names of the compass directions. + // First the 4 cardinal directions, then the 4 ordinal directions + direction: Texts; + direction_abbr: Texts; + + // Common street prefixes + street_prefix: Texts; + // Common street suffixes + street_suffix: Texts; + + // The address "inside" an address/e.g. an apartment or office. + secondary_address: Texts; + + // The iso country codes + country_code: Texts; // Alpha 2 + country_code_alpha_3: Texts; + + // The ISO? names of the timezones + time_zone: Texts; +} + +export const addresses = allOf()( + 'postcode_by_state', + 'postcode', + + 'city_name', + 'city_prefix', + 'city_suffix', + + 'country', + 'state', + 'state_abbr', + 'county', + + 'direction_abbr', + 'direction', + + 'street_prefix', + 'street_suffix', + + 'secondary_address', + + 'country_code', + 'country_code_alpha_3', + + 'time_zone' +); diff --git a/src/definitions/animal.ts b/src/definitions/animal.ts new file mode 100644 index 00000000000..951344368cf --- /dev/null +++ b/src/definitions/animal.ts @@ -0,0 +1,36 @@ +import type { Texts } from './utils'; +import { allOf } from './utils'; + +export interface AnimalDefinitions { + bear: Texts; + bird: Texts; + cat: Texts; + cetacean: Texts; + cow: Texts; + crocodilia: Texts; + dog: Texts; + fish: Texts; + horse: Texts; + insect: Texts; + lion: Texts; + rabbit: Texts; + snake: Texts; + type: Texts; +} + +export const animals = allOf()( + 'dog', + 'cat', + 'snake', + 'bear', + 'lion', + 'cetacean', + 'insect', + 'crocodilia', + 'cow', + 'bird', + 'fish', + 'rabbit', + 'horse', + 'type' +); diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts new file mode 100644 index 00000000000..60271e19f5d --- /dev/null +++ b/src/definitions/definitions.ts @@ -0,0 +1,166 @@ +import type { AddressDefinitions } from './address'; +import { addresses } from './address'; +import type { AnimalDefinitions } from './animal'; +import { animals } from './animal'; +import type { NameDefinitions } from './name'; +import { names } from './name'; + +export interface Definitions { + address: AddressDefinitions; + animal: AnimalDefinitions; + commerce: { + color; + department; + product_description; + product_name; + }; + company: { + adjective; + bs_adjective; + bs_noun; + bs_verb; + descriptor; + noun; + suffix; + }; + database: { + collation; + column; + engine; + type; + }; + date: { + month; + weekday; + }; + finance: { + account_type; + credit_card; + currency: Record; + transaction_type; + }; + hacker: { + abbreviation; + adjective; + ingverb; + noun; + phrase; + verb; + }; + internet: { + domain_suffix; + example_email; + free_email; + }; + lorem: { + words; + }; + music: { + genre; + }; + name: NameDefinitions; + phone_number: { + formats; + }; + system: { + directoryPaths; + mimeTypes; + }; + vehicle: { + bicycle_type; + fuel; + manufacturer; + model; + type; + }; + word: { + adjective: string[]; + adverb: string[]; + conjunction: string[]; + interjection: string[]; + noun: string[]; + preposition: string[]; + verb: string[]; + }; +} + +export interface DefinitionTypes { + readonly title: string; + readonly separator: string; + + readonly address: typeof addresses; + readonly animal: typeof animals; + readonly name: typeof names; + + readonly company: string[]; + readonly lorem: string[]; + readonly hacker: string[]; + readonly phone_number: string[]; + readonly finance: string[]; + readonly internet: string[]; + readonly commerce: string[]; + readonly database: string[]; + readonly system: string[]; + readonly date: string[]; + readonly vehicle: string[]; + readonly music: string[]; + readonly word: string[]; +} + +export const definitions: DefinitionTypes = { + title: '', + separator: '', + + address: addresses, + animal: animals, + name: names, + + company: [ + 'adjective', + 'noun', + 'descriptor', + 'bs_adjective', + 'bs_noun', + 'bs_verb', + 'suffix', + ], + lorem: ['words'], + hacker: ['abbreviation', 'adjective', 'noun', 'verb', 'ingverb', 'phrase'], + phone_number: ['formats'], + finance: [ + 'account_type', + 'transaction_type', + 'currency', + 'iban', + 'credit_card', + ], + internet: [ + 'avatar_uri', + 'domain_suffix', + 'free_email', + 'example_email', + 'password', + ], + commerce: [ + 'color', + 'department', + 'product_name', + 'price', + 'categories', + 'product_description', + ], + database: ['collation', 'column', 'engine', 'type'], + system: ['mimeTypes', 'directoryPaths'], + date: ['month', 'weekday'], + vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], + music: ['genre'], + word: [ + 'adjective', + 'adverb', + 'conjunction', + 'interjection', + 'noun', + 'preposition', + 'verb', + ], +}; diff --git a/src/definitions/index.ts b/src/definitions/index.ts new file mode 100644 index 00000000000..5fb6a43b0ba --- /dev/null +++ b/src/definitions/index.ts @@ -0,0 +1,20 @@ +import type { AddressDefinitions } from './address'; +import type { AnimalDefinitions } from './animal'; +import type { Definitions, DefinitionTypes } from './definitions'; +import { definitions } from './definitions'; +import type { NameDefinitions, NameTitleDefinitions } from './name'; +import type { Format, Formats, Texts, Values } from './utils'; + +export { definitions }; +export type { + Definitions, + DefinitionTypes, + Values, + Texts, + Format, + Formats, + AnimalDefinitions, + AddressDefinitions, + NameDefinitions, + NameTitleDefinitions, +}; diff --git a/src/definitions/name.ts b/src/definitions/name.ts new file mode 100644 index 00000000000..31c180f7a89 --- /dev/null +++ b/src/definitions/name.ts @@ -0,0 +1,62 @@ +import type { Formats, Texts } from './utils'; +import { allOf } from './utils'; + +export interface NameDefinitions { + gender: Texts; + binary_gender: Texts; + + prefix?: Texts; + female_prefix?: Texts; + male_prefix?: Texts; + + first_name?: Texts; + female_first_name?: Texts; + male_first_name?: Texts; + + middle_name?: Texts; + female_middle_name?: Texts; + male_middle_name?: Texts; + + last_name?: Texts; + female_last_name?: Texts; + male_last_name?: Texts; + + suffix: Texts; + + name: Formats; + + title: NameTitleDefinitions; +} + +export interface NameTitleDefinitions { + descriptor?: Texts; + job: Texts; + level?: Texts; +} + +export const names = 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/utils.ts b/src/definitions/utils.ts new file mode 100644 index 00000000000..13e1b6b61fc --- /dev/null +++ b/src/definitions/utils.ts @@ -0,0 +1,20 @@ +// https://stackoverflow.com/a/53395649/4573065 +type AllOf = ['Needs to be all of', T]; +export const allOf = + () => + ( + ...array: U & ([T] extends [U[number]] ? unknown : AllOf[]) + ) => + array; + +// A list of values that can be used as is. +export type Values = readonly T[]; +export type Texts = Values; +// A strings that might contain a placeholder for fake(). +export type Format = string; +export type Formats = readonly Format[]; + +export type Range = { + min: number; + max: number; +}; From d389048fe47f818f0c9247f7d74f20ca78c18943 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 12:45:09 +0100 Subject: [PATCH 06/37] feat: migrate company definitions --- src/definitions/company.ts | 27 +++++++++++++++++++++++++++ src/definitions/definitions.ts | 25 +++++-------------------- src/definitions/index.ts | 4 ++++ src/index.ts | 12 ++---------- src/locales/en/company/index.ts | 12 ++++++++---- 5 files changed, 46 insertions(+), 34 deletions(-) create mode 100644 src/definitions/company.ts diff --git a/src/definitions/company.ts b/src/definitions/company.ts new file mode 100644 index 00000000000..8df5fab1a25 --- /dev/null +++ b/src/definitions/company.ts @@ -0,0 +1,27 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +export interface CompanyDefinition { + // Business/products related words + bs_adjective: Texts; + bs_noun; + bs_verb; + // Catch phrases + adjective: Texts; + descriptor: Texts; + noun: Texts; + // Company suffixes + suffix: Texts; +} + +export const companies = allOf()( + 'bs_adjective', + 'bs_noun', + 'bs_verb', + + 'adjective', + 'descriptor', + 'noun', + + 'suffix' +); diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 60271e19f5d..e349d99cfc9 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -2,6 +2,8 @@ import type { AddressDefinitions } from './address'; import { addresses } from './address'; import type { AnimalDefinitions } from './animal'; import { animals } from './animal'; +import { companies } from './company'; +import type { CompanyDefinition } from './company'; import type { NameDefinitions } from './name'; import { names } from './name'; @@ -14,15 +16,7 @@ export interface Definitions { product_description; product_name; }; - company: { - adjective; - bs_adjective; - bs_noun; - bs_verb; - descriptor; - noun; - suffix; - }; + company: CompanyDefinition; database: { collation; column; @@ -92,7 +86,7 @@ export interface DefinitionTypes { readonly animal: typeof animals; readonly name: typeof names; - readonly company: string[]; + readonly company: typeof companies; readonly lorem: string[]; readonly hacker: string[]; readonly phone_number: string[]; @@ -114,16 +108,7 @@ export const definitions: DefinitionTypes = { address: addresses, animal: animals, name: names, - - company: [ - 'adjective', - 'noun', - 'descriptor', - 'bs_adjective', - 'bs_noun', - 'bs_verb', - 'suffix', - ], + company: companies, lorem: ['words'], hacker: ['abbreviation', 'adjective', 'noun', 'verb', 'ingverb', 'phrase'], phone_number: ['formats'], diff --git a/src/definitions/index.ts b/src/definitions/index.ts index 5fb6a43b0ba..ced4335a506 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -1,10 +1,13 @@ import type { AddressDefinitions } from './address'; import type { AnimalDefinitions } from './animal'; +import type { CompanyDefinition } from './company'; import type { Definitions, DefinitionTypes } from './definitions'; import { definitions } from './definitions'; import type { NameDefinitions, NameTitleDefinitions } from './name'; import type { Format, Formats, Texts, Values } from './utils'; +let a: CompanyDefinition; + export { definitions }; export type { Definitions, @@ -15,6 +18,7 @@ export type { Formats, AnimalDefinitions, AddressDefinitions, + CompanyDefinition, NameDefinitions, NameTitleDefinitions, }; diff --git a/src/index.ts b/src/index.ts index 73c994937b0..b96ec6eeb71 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ import { _Date } from './date'; import type { AddressDefinitions, AnimalDefinitions, + CompanyDefinition, Definitions, DefinitionTypes, NameDefinitions, @@ -62,16 +63,7 @@ export interface LocaleDefinition { product_description: any[]; product_name: any[]; }>; - company?: Partial<{ - adjective: any[]; - bs_adjective: any[]; - bs_noun: any[]; - bs_verb: any[]; - descriptor: any[]; - name: any[]; - noun: any[]; - suffix: any[]; - }>; + company?: Partial; database?: Partial<{ collation: any[]; column: any[]; diff --git a/src/locales/en/company/index.ts b/src/locales/en/company/index.ts index 9c2343931ad..9c7ab51f91b 100644 --- a/src/locales/en/company/index.ts +++ b/src/locales/en/company/index.ts @@ -1,3 +1,4 @@ +import type { CompanyDefinition } from '../../../definitions'; import adjective from './adjective'; import bs_adjective from './bs_adjective'; import bs_noun from './bs_noun'; @@ -7,15 +8,18 @@ import name from './name'; import noun from './noun'; import suffix from './suffix'; -const company: any = { - adjective, +const company = { bs_adjective, bs_noun, bs_verb, + + adjective, descriptor, - name, noun, + suffix, -}; + + name, +} as CompanyDefinition; export default company; From 80efc204707f6ed009fc6fef1c489c815efb35ee Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 13:01:44 +0100 Subject: [PATCH 07/37] chore: move LocaleDefinition to definitions --- src/definitions/definitions.ts | 94 ++++++++++++++++++++++++++++++ src/definitions/index.ts | 9 ++- src/index.ts | 101 +-------------------------------- 3 files changed, 102 insertions(+), 102 deletions(-) diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index e349d99cfc9..7406eceb0c5 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -78,6 +78,100 @@ export interface Definitions { }; } +export interface LocaleDefinition { + title: string; + separator?: string; + + address?: Partial; + animal?: Partial; + app?: Partial<{ + author: any[]; + name: any[]; + version: any[]; + }>; + business?: Partial<{ + credit_card_expiry_dates: any[]; + credit_card_numbers: any[]; + credit_card_types: any[]; + }>; + cell_phone?: Partial<{ + formats: any[]; + }>; + commerce?: Partial<{ + color: any[]; + department: any[]; + product_description: any[]; + product_name: any[]; + }>; + company?: Partial; + database?: Partial<{ + collation: any[]; + column: any[]; + engine: any[]; + type: any[]; + }>; + date?: Partial<{ + month: any[]; + weekday: any[]; + }>; + finance?: Partial<{ + account_type: any[]; + credit_card: any[]; + currency: any[]; + transaction_type: any[]; + }>; + hacker?: Partial<{ + abbreviation: any[]; + adjective: any[]; + ingverb: any[]; + noun: any[]; + phrase: any[]; + verb: any[]; + }>; + internet?: Partial<{ + avatar_uri: any[]; + domain_suffix: any[]; + example_email: any[]; + free_email: any[]; + }>; + lorem?: Partial<{ + supplemental: any[]; + words: any[]; + }>; + music?: Partial<{ + genre: any[]; + }>; + name?: Partial; + phone_number?: Partial<{ + formats: any[]; + }>; + system?: Partial<{ + directoryPaths: any[]; + mimeTypes: any[]; + }>; + team?: Partial<{ + creature: any[]; + name: any[]; + }>; + vehicle?: Partial<{ + bicycle: any[]; + fuel: any[]; + manufacturer: any[]; + model: any[]; + type: any[]; + }>; + word?: Partial<{ + adjective: any[]; + adverb: any[]; + conjunction: any[]; + interjection: any[]; + noun: any[]; + preposition: any[]; + verb: any[]; + }>; + [group: string]: any; +} + export interface DefinitionTypes { readonly title: string; readonly separator: string; diff --git a/src/definitions/index.ts b/src/definitions/index.ts index ced4335a506..66c0d6bcd72 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -1,16 +1,19 @@ import type { AddressDefinitions } from './address'; import type { AnimalDefinitions } from './animal'; import type { CompanyDefinition } from './company'; -import type { Definitions, DefinitionTypes } from './definitions'; +import type { + Definitions, + DefinitionTypes, + LocaleDefinition, +} from './definitions'; import { definitions } from './definitions'; import type { NameDefinitions, NameTitleDefinitions } from './name'; import type { Format, Formats, Texts, Values } from './utils'; -let a: CompanyDefinition; - export { definitions }; export type { Definitions, + LocaleDefinition, DefinitionTypes, Values, Texts, diff --git a/src/index.ts b/src/index.ts index b96ec6eeb71..d7de3c03ce3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,12 +6,9 @@ import { Database } from './database'; import { Datatype } from './datatype'; import { _Date } from './date'; import type { - AddressDefinitions, - AnimalDefinitions, - CompanyDefinition, Definitions, DefinitionTypes, - NameDefinitions, + LocaleDefinition, } from './definitions'; import { definitions } from './definitions'; import { Fake } from './fake'; @@ -38,104 +35,10 @@ import { Word } from './word'; // https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609 type LiteralUnion = T | (U & { zz_IGNORE_ME?: never }); -export interface LocaleDefinition { - title: string; - separator?: string; - - address?: Partial; - animal?: Partial; - app?: Partial<{ - author: any[]; - name: any[]; - version: any[]; - }>; - business?: Partial<{ - credit_card_expiry_dates: any[]; - credit_card_numbers: any[]; - credit_card_types: any[]; - }>; - cell_phone?: Partial<{ - formats: any[]; - }>; - commerce?: Partial<{ - color: any[]; - department: any[]; - product_description: any[]; - product_name: any[]; - }>; - company?: Partial; - database?: Partial<{ - collation: any[]; - column: any[]; - engine: any[]; - type: any[]; - }>; - date?: Partial<{ - month: any[]; - weekday: any[]; - }>; - finance?: Partial<{ - account_type: any[]; - credit_card: any[]; - currency: any[]; - transaction_type: any[]; - }>; - hacker?: Partial<{ - abbreviation: any[]; - adjective: any[]; - ingverb: any[]; - noun: any[]; - phrase: any[]; - verb: any[]; - }>; - internet?: Partial<{ - avatar_uri: any[]; - domain_suffix: any[]; - example_email: any[]; - free_email: any[]; - }>; - lorem?: Partial<{ - supplemental: any[]; - words: any[]; - }>; - music?: Partial<{ - genre: any[]; - }>; - name?: Partial; - phone_number?: Partial<{ - formats: any[]; - }>; - system?: Partial<{ - directoryPaths: any[]; - mimeTypes: any[]; - }>; - team?: Partial<{ - creature: any[]; - name: any[]; - }>; - vehicle?: Partial<{ - bicycle: any[]; - fuel: any[]; - manufacturer: any[]; - model: any[]; - type: any[]; - }>; - word?: Partial<{ - adjective: any[]; - adverb: any[]; - conjunction: any[]; - interjection: any[]; - noun: any[]; - preposition: any[]; - verb: any[]; - }>; - [group: string]: any; -} - export type UsableLocale = LiteralUnion; export type UsedLocales = Partial>; -export type { Definitions }; +export type { Definitions, LocaleDefinition }; export interface FakerOptions { locales?: UsedLocales; From fcbb75445650efa19c0a1967dc2ad50bbbea2a93 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 13:38:19 +0100 Subject: [PATCH 08/37] docs: add some jsdocs --- src/definitions/address.ts | 6 ++++++ src/definitions/animal.ts | 6 ++++++ src/definitions/company.ts | 6 ++++++ src/definitions/definitions.ts | 20 ++++++++++++++++++++ src/definitions/name.ts | 9 +++++++++ 5 files changed, 47 insertions(+) diff --git a/src/definitions/address.ts b/src/definitions/address.ts index da28b4afd8c..9487720b5cf 100644 --- a/src/definitions/address.ts +++ b/src/definitions/address.ts @@ -1,6 +1,9 @@ import type { Format, Formats, Texts } from './utils'; import { allOf } from './utils'; +/** + * The possible definitions related to addresses. + */ export interface AddressDefinitions { // address.zipCodeByState() expects only { [state: string]: Range } postcode_by_state: Formats | { [state: string]: Range }; @@ -42,6 +45,9 @@ export interface AddressDefinitions { time_zone: Texts; } +/** + * Internal: A list of all keys for the AddressDefinitions. + */ export const addresses = allOf()( 'postcode_by_state', 'postcode', diff --git a/src/definitions/animal.ts b/src/definitions/animal.ts index 951344368cf..e3fbf6b8cb2 100644 --- a/src/definitions/animal.ts +++ b/src/definitions/animal.ts @@ -1,6 +1,9 @@ import type { Texts } from './utils'; import { allOf } from './utils'; +/** + * The possible definitions related to animals. + */ export interface AnimalDefinitions { bear: Texts; bird: Texts; @@ -18,6 +21,9 @@ export interface AnimalDefinitions { type: Texts; } +/** + * Internal: A list of all keys for the AnimalDefinitions. + */ export const animals = allOf()( 'dog', 'cat', diff --git a/src/definitions/company.ts b/src/definitions/company.ts index 8df5fab1a25..1e709abddc7 100644 --- a/src/definitions/company.ts +++ b/src/definitions/company.ts @@ -1,6 +1,9 @@ import type { Texts } from '.'; import { allOf } from './utils'; +/** + * The possible definitions related to companies. + */ export interface CompanyDefinition { // Business/products related words bs_adjective: Texts; @@ -14,6 +17,9 @@ export interface CompanyDefinition { suffix: Texts; } +/** + * Internal: A list of all keys for the CompanyDefinition. + */ export const companies = allOf()( 'bs_adjective', 'bs_noun', diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 7406eceb0c5..7fe9a30dc43 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -7,6 +7,9 @@ import type { CompanyDefinition } from './company'; import type { NameDefinitions } from './name'; import { names } from './name'; +/** + * The definitions as used by the Faker modules. + */ export interface Definitions { address: AddressDefinitions; animal: AnimalDefinitions; @@ -78,7 +81,15 @@ export interface Definitions { }; } +/** + * The definitions as used by the translations/locales. + * This is basically the same as Definitions with the exception, + * that most properties are optional and extra properties are allowed. + */ export interface LocaleDefinition { + /** + * The name of the language. + */ title: string; separator?: string; @@ -172,6 +183,11 @@ export interface LocaleDefinition { [group: string]: any; } +/** + * Internal: Compatibility type to ensure all modules have access to fallback locales. + * This should be replaced with a Proxy based property access + * that don't require prior getter generation in the future. + */ export interface DefinitionTypes { readonly title: string; readonly separator: string; @@ -195,6 +211,10 @@ export interface DefinitionTypes { readonly word: string[]; } +/** + * Internal: List off all modules and their properties, + * that needs to have a fallback generated in Faker.loadDefinitions(). + */ export const definitions: DefinitionTypes = { title: '', separator: '', diff --git a/src/definitions/name.ts b/src/definitions/name.ts index 31c180f7a89..3f28716523d 100644 --- a/src/definitions/name.ts +++ b/src/definitions/name.ts @@ -1,6 +1,9 @@ import type { Formats, Texts } from './utils'; import { allOf } from './utils'; +/** + * The possible definitions related to people's names. + */ export interface NameDefinitions { gender: Texts; binary_gender: Texts; @@ -28,12 +31,18 @@ export interface NameDefinitions { title: NameTitleDefinitions; } +/** + * The possible definitions related to people's titles. + */ export interface NameTitleDefinitions { descriptor?: Texts; job: Texts; level?: Texts; } +/** + * Internal: A list of all keys for the NameDefinitions. + */ export const names = allOf()( 'gender', 'binary_gender', From fd6da924307676462854e7d415fa33e02e5bc0cb Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 14:21:42 +0100 Subject: [PATCH 09/37] feat: split commerce to its own file --- src/definitions/commerce.ts | 52 ++++++++++++++++++++++++++++++++++ src/definitions/definitions.ts | 33 ++++++--------------- src/definitions/index.ts | 2 ++ 3 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 src/definitions/commerce.ts diff --git a/src/definitions/commerce.ts b/src/definitions/commerce.ts new file mode 100644 index 00000000000..c063a236957 --- /dev/null +++ b/src/definitions/commerce.ts @@ -0,0 +1,52 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +/** + * The possible definitions related to commerce. + */ +export interface CommerceDefinitions { + /** + * Human readable color names + */ + color: Texts; + /** + * Department names inside a shop. + */ + department: Texts; + /** + * Product name generation definitions. + */ + product_name: CommerceProductNameDefinitions; + /** + * Descriptions for products. + */ + product_description: Texts; +} + +/** + * The possible definitions related to product name generation. + */ +export interface CommerceProductNameDefinitions { + /** + * Adjectives describing a product (e.g. tasty). + */ + adjective: Texts; + /** + * Materials describing a product (e.g. wood). + */ + material: Texts; + /** + * Types of products (e.g. chair). + */ + product: Texts; +} + +/** + * Internal: A list of all keys for the CommerceDefinitions. + */ +export const commerce = allOf()( + 'color', + 'department', + 'product_name', + 'product_description' +); diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 7fe9a30dc43..9898cedfb8b 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -2,8 +2,10 @@ import type { AddressDefinitions } from './address'; import { addresses } from './address'; import type { AnimalDefinitions } from './animal'; import { animals } from './animal'; -import { companies } from './company'; +import type { CommerceDefinitions } from './commerce'; +import { commerce } from './commerce'; import type { CompanyDefinition } from './company'; +import { companies } from './company'; import type { NameDefinitions } from './name'; import { names } from './name'; @@ -13,12 +15,7 @@ import { names } from './name'; export interface Definitions { address: AddressDefinitions; animal: AnimalDefinitions; - commerce: { - color; - department; - product_description; - product_name; - }; + commerce: CommerceDefinitions; company: CompanyDefinition; database: { collation; @@ -108,12 +105,7 @@ export interface LocaleDefinition { cell_phone?: Partial<{ formats: any[]; }>; - commerce?: Partial<{ - color: any[]; - department: any[]; - product_description: any[]; - product_name: any[]; - }>; + commerce?: Partial; company?: Partial; database?: Partial<{ collation: any[]; @@ -194,15 +186,15 @@ export interface DefinitionTypes { readonly address: typeof addresses; readonly animal: typeof animals; + readonly commerce: typeof commerce; + readonly company: typeof companies; readonly name: typeof names; - readonly company: typeof companies; readonly lorem: string[]; readonly hacker: string[]; readonly phone_number: string[]; readonly finance: string[]; readonly internet: string[]; - readonly commerce: string[]; readonly database: string[]; readonly system: string[]; readonly date: string[]; @@ -221,8 +213,9 @@ export const definitions: DefinitionTypes = { address: addresses, animal: animals, - name: names, company: companies, + commerce, + name: names, lorem: ['words'], hacker: ['abbreviation', 'adjective', 'noun', 'verb', 'ingverb', 'phrase'], phone_number: ['formats'], @@ -240,14 +233,6 @@ export const definitions: DefinitionTypes = { 'example_email', 'password', ], - commerce: [ - 'color', - 'department', - 'product_name', - 'price', - 'categories', - 'product_description', - ], database: ['collation', 'column', 'engine', 'type'], system: ['mimeTypes', 'directoryPaths'], date: ['month', 'weekday'], diff --git a/src/definitions/index.ts b/src/definitions/index.ts index 66c0d6bcd72..5e7a29437c2 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -1,5 +1,6 @@ import type { AddressDefinitions } from './address'; import type { AnimalDefinitions } from './animal'; +import type { CommerceDefinitions } from './commerce'; import type { CompanyDefinition } from './company'; import type { Definitions, @@ -21,6 +22,7 @@ export type { Formats, AnimalDefinitions, AddressDefinitions, + CommerceDefinitions, CompanyDefinition, NameDefinitions, NameTitleDefinitions, From 8d970e41bdd2d70deecda63e821c6cf23ad49245 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 16:03:15 +0100 Subject: [PATCH 10/37] feat: split database to its own file --- src/definitions/database.ts | 34 ++++++++++++++++++++++++++++++++++ src/definitions/definitions.ts | 20 ++++++-------------- src/definitions/index.ts | 8 +++++++- 3 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 src/definitions/database.ts diff --git a/src/definitions/database.ts b/src/definitions/database.ts new file mode 100644 index 00000000000..d41dd3a4149 --- /dev/null +++ b/src/definitions/database.ts @@ -0,0 +1,34 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +/** + * The possible definitions related to databases. + */ +export interface DatabaseDefinition { + /** + * Database Engine + */ + engine: Texts; + /** + * Database Collation + */ + collation: Texts; + /** + * Column names + */ + column: Texts; + /** + * Column types + */ + type: Texts; +} + +/** + * Internal: A list of all keys for the DatabaseDefinition. + */ +export const database = allOf()( + 'collation', + 'column', + 'engine', + 'type' +); diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 9898cedfb8b..d47d669958c 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -6,6 +6,8 @@ import type { CommerceDefinitions } from './commerce'; import { commerce } from './commerce'; import type { CompanyDefinition } from './company'; import { companies } from './company'; +import type { DatabaseDefinition } from './database'; +import { database } from './database'; import type { NameDefinitions } from './name'; import { names } from './name'; @@ -17,12 +19,7 @@ export interface Definitions { animal: AnimalDefinitions; commerce: CommerceDefinitions; company: CompanyDefinition; - database: { - collation; - column; - engine; - type; - }; + database: DatabaseDefinition; date: { month; weekday; @@ -107,12 +104,7 @@ export interface LocaleDefinition { }>; commerce?: Partial; company?: Partial; - database?: Partial<{ - collation: any[]; - column: any[]; - engine: any[]; - type: any[]; - }>; + database?: Partial; date?: Partial<{ month: any[]; weekday: any[]; @@ -188,6 +180,7 @@ export interface DefinitionTypes { readonly animal: typeof animals; readonly commerce: typeof commerce; readonly company: typeof companies; + readonly database: typeof database; readonly name: typeof names; readonly lorem: string[]; @@ -195,7 +188,6 @@ export interface DefinitionTypes { readonly phone_number: string[]; readonly finance: string[]; readonly internet: string[]; - readonly database: string[]; readonly system: string[]; readonly date: string[]; readonly vehicle: string[]; @@ -233,7 +225,7 @@ export const definitions: DefinitionTypes = { 'example_email', 'password', ], - database: ['collation', 'column', 'engine', 'type'], + database, system: ['mimeTypes', 'directoryPaths'], date: ['month', 'weekday'], vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], diff --git a/src/definitions/index.ts b/src/definitions/index.ts index 5e7a29437c2..1a1ce3bb5a0 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -1,7 +1,11 @@ import type { AddressDefinitions } from './address'; import type { AnimalDefinitions } from './animal'; -import type { CommerceDefinitions } from './commerce'; +import type { + CommerceDefinitions, + CommerceProductNameDefinitions, +} from './commerce'; import type { CompanyDefinition } from './company'; +import type { DatabaseDefinition } from './database'; import type { Definitions, DefinitionTypes, @@ -23,7 +27,9 @@ export type { AnimalDefinitions, AddressDefinitions, CommerceDefinitions, + CommerceProductNameDefinitions, CompanyDefinition, + DatabaseDefinition, NameDefinitions, NameTitleDefinitions, }; From 8865608c7a0c840c7bdce062595d5e6e0c3b2405 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 17:29:51 +0100 Subject: [PATCH 11/37] feat: split database to its own file --- src/locales/en/database/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/locales/en/database/index.ts b/src/locales/en/database/index.ts index 8be270761e9..c6761228d07 100644 --- a/src/locales/en/database/index.ts +++ b/src/locales/en/database/index.ts @@ -1,9 +1,10 @@ +import type { DatabaseDefinition } from '../../../definitions'; import collation from './collation'; import column from './column'; import engine from './engine'; import type from './type'; -const database: any = { +const database: DatabaseDefinition = { collation, column, engine, From 8b3f166c554fdb42bd9065e5b7fcb70c3c5476db Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 17:39:42 +0100 Subject: [PATCH 12/37] feat: split date to its own file --- src/definitions/date.ts | 45 ++++++++++++++++++++++++++++++++++ src/definitions/definitions.ts | 16 +++++------- src/definitions/index.ts | 3 +++ src/locales/en/date/index.ts | 3 ++- 4 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 src/definitions/date.ts diff --git a/src/definitions/date.ts b/src/definitions/date.ts new file mode 100644 index 00000000000..87ea0a70609 --- /dev/null +++ b/src/definitions/date.ts @@ -0,0 +1,45 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +/** + * The possible definitions related to dates. + */ +export interface DateDefinition { + /** + * The translations for months (January - December). + */ + month: DateEntryDefinition; + /** + * The translations for weekdays (Sunday - Saturday). + */ + weekday: DateEntryDefinition; +} + +/** + * The possible definitions related to date entries. + */ +export interface DateEntryDefinition { + /** + * The long name of the entry. + */ + wide: Texts; + /** + * The short name/abbreviation of the entry. + */ + abbr: Texts; + /** + * The wide name of the entry when used in context. If absent wide will be used instead. + * It is used to specify a word in context, which may differ from a stand-alone word. + */ + wide_context?: Texts; + /** + * The short name/abbreviation name of the entry when used in context. If absent abbr will be used instead. + * It is used to specify a word in context, which may differ from a stand-alone word. + */ + abbr_context?: Texts; +} + +/** + * Internal: A list of all keys for the DateDefinition. + */ +export const date = allOf()('month', 'weekday'); diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index d47d669958c..85f7a7222a1 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -8,6 +8,8 @@ import type { CompanyDefinition } from './company'; import { companies } from './company'; import type { DatabaseDefinition } from './database'; import { database } from './database'; +import type { DateDefinition } from './date'; +import { date } from './date'; import type { NameDefinitions } from './name'; import { names } from './name'; @@ -20,10 +22,7 @@ export interface Definitions { commerce: CommerceDefinitions; company: CompanyDefinition; database: DatabaseDefinition; - date: { - month; - weekday; - }; + date: DateDefinition; finance: { account_type; credit_card; @@ -105,10 +104,7 @@ export interface LocaleDefinition { commerce?: Partial; company?: Partial; database?: Partial; - date?: Partial<{ - month: any[]; - weekday: any[]; - }>; + date?: Partial; finance?: Partial<{ account_type: any[]; credit_card: any[]; @@ -181,6 +177,7 @@ export interface DefinitionTypes { readonly commerce: typeof commerce; readonly company: typeof companies; readonly database: typeof database; + readonly date: typeof date; readonly name: typeof names; readonly lorem: string[]; @@ -189,7 +186,6 @@ export interface DefinitionTypes { readonly finance: string[]; readonly internet: string[]; readonly system: string[]; - readonly date: string[]; readonly vehicle: string[]; readonly music: string[]; readonly word: string[]; @@ -227,7 +223,7 @@ export const definitions: DefinitionTypes = { ], database, system: ['mimeTypes', 'directoryPaths'], - date: ['month', 'weekday'], + date, vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], music: ['genre'], word: [ diff --git a/src/definitions/index.ts b/src/definitions/index.ts index 1a1ce3bb5a0..0b83fa87e7c 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -6,6 +6,7 @@ import type { } from './commerce'; import type { CompanyDefinition } from './company'; import type { DatabaseDefinition } from './database'; +import type { DateDefinition, DateEntryDefinition } from './date'; import type { Definitions, DefinitionTypes, @@ -30,6 +31,8 @@ export type { CommerceProductNameDefinitions, CompanyDefinition, DatabaseDefinition, + DateDefinition, + DateEntryDefinition, NameDefinitions, NameTitleDefinitions, }; diff --git a/src/locales/en/date/index.ts b/src/locales/en/date/index.ts index 35b1df67c7d..3fbc78c67ef 100644 --- a/src/locales/en/date/index.ts +++ b/src/locales/en/date/index.ts @@ -1,7 +1,8 @@ +import type { DateDefinition } from '../../../definitions'; import month from './month'; import weekday from './weekday'; -const date: any = { +const date: DateDefinition = { month, weekday, }; From b09cfc719076cfac79bf7466b5dbe21749bf5e48 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 17:48:56 +0100 Subject: [PATCH 13/37] chore: cleanup --- src/definitions/address.ts | 2 +- src/definitions/animal.ts | 2 +- src/definitions/company.ts | 2 +- src/definitions/definitions.ts | 24 ++++++++++++------------ src/definitions/name.ts | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/definitions/address.ts b/src/definitions/address.ts index 9487720b5cf..7c2134f7e83 100644 --- a/src/definitions/address.ts +++ b/src/definitions/address.ts @@ -48,7 +48,7 @@ export interface AddressDefinitions { /** * Internal: A list of all keys for the AddressDefinitions. */ -export const addresses = allOf()( +export const address = allOf()( 'postcode_by_state', 'postcode', diff --git a/src/definitions/animal.ts b/src/definitions/animal.ts index e3fbf6b8cb2..e8d2993ed03 100644 --- a/src/definitions/animal.ts +++ b/src/definitions/animal.ts @@ -24,7 +24,7 @@ export interface AnimalDefinitions { /** * Internal: A list of all keys for the AnimalDefinitions. */ -export const animals = allOf()( +export const animal = allOf()( 'dog', 'cat', 'snake', diff --git a/src/definitions/company.ts b/src/definitions/company.ts index 1e709abddc7..b319681b9df 100644 --- a/src/definitions/company.ts +++ b/src/definitions/company.ts @@ -20,7 +20,7 @@ export interface CompanyDefinition { /** * Internal: A list of all keys for the CompanyDefinition. */ -export const companies = allOf()( +export const company = allOf()( 'bs_adjective', 'bs_noun', 'bs_verb', diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 85f7a7222a1..507612d5de8 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -1,17 +1,17 @@ import type { AddressDefinitions } from './address'; -import { addresses } from './address'; +import { address } from './address'; import type { AnimalDefinitions } from './animal'; -import { animals } from './animal'; +import { animal } from './animal'; import type { CommerceDefinitions } from './commerce'; import { commerce } from './commerce'; import type { CompanyDefinition } from './company'; -import { companies } from './company'; +import { company } from './company'; import type { DatabaseDefinition } from './database'; import { database } from './database'; import type { DateDefinition } from './date'; import { date } from './date'; import type { NameDefinitions } from './name'; -import { names } from './name'; +import { name } from './name'; /** * The definitions as used by the Faker modules. @@ -172,13 +172,13 @@ export interface DefinitionTypes { readonly title: string; readonly separator: string; - readonly address: typeof addresses; - readonly animal: typeof animals; + readonly address: typeof address; + readonly animal: typeof animal; readonly commerce: typeof commerce; - readonly company: typeof companies; + readonly company: typeof company; readonly database: typeof database; readonly date: typeof date; - readonly name: typeof names; + readonly name: typeof name; readonly lorem: string[]; readonly hacker: string[]; @@ -199,11 +199,11 @@ export const definitions: DefinitionTypes = { title: '', separator: '', - address: addresses, - animal: animals, - company: companies, + address, + animal, + company, commerce, - name: names, + name, lorem: ['words'], hacker: ['abbreviation', 'adjective', 'noun', 'verb', 'ingverb', 'phrase'], phone_number: ['formats'], diff --git a/src/definitions/name.ts b/src/definitions/name.ts index 3f28716523d..96a55547be2 100644 --- a/src/definitions/name.ts +++ b/src/definitions/name.ts @@ -43,7 +43,7 @@ export interface NameTitleDefinitions { /** * Internal: A list of all keys for the NameDefinitions. */ -export const names = allOf()( +export const name = allOf()( 'gender', 'binary_gender', From 74c8bcc46e55b602aad270b84e4f090d01b2e375 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 19:21:36 +0100 Subject: [PATCH 14/37] feat: split finance to its own file --- src/definitions/definitions.ts | 26 ++------ src/definitions/finance.ts | 73 +++++++++++++++++++++ src/definitions/index.ts | 12 ++++ src/finance.ts | 1 + src/locales/el/credit_card/index.ts | 3 +- src/locales/el/finance/index.ts | 3 +- src/locales/en/finance/credit_card/index.ts | 3 +- src/locales/en/finance/index.ts | 3 +- src/locales/fa/finance/credit_card/index.ts | 3 +- src/locales/fa/finance/index.ts | 3 +- 10 files changed, 104 insertions(+), 26 deletions(-) create mode 100644 src/definitions/finance.ts diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 507612d5de8..8c15e2276f6 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -10,6 +10,8 @@ import type { DatabaseDefinition } from './database'; import { database } from './database'; import type { DateDefinition } from './date'; import { date } from './date'; +import type { FinanceDefinitions } from './finance'; +import { finance } from './finance'; import type { NameDefinitions } from './name'; import { name } from './name'; @@ -23,12 +25,7 @@ export interface Definitions { company: CompanyDefinition; database: DatabaseDefinition; date: DateDefinition; - finance: { - account_type; - credit_card; - currency: Record; - transaction_type; - }; + finance: FinanceDefinitions; hacker: { abbreviation; adjective; @@ -105,12 +102,7 @@ export interface LocaleDefinition { company?: Partial; database?: Partial; date?: Partial; - finance?: Partial<{ - account_type: any[]; - credit_card: any[]; - currency: any[]; - transaction_type: any[]; - }>; + finance?: Partial; hacker?: Partial<{ abbreviation: any[]; adjective: any[]; @@ -178,12 +170,12 @@ export interface DefinitionTypes { readonly company: typeof company; readonly database: typeof database; readonly date: typeof date; + readonly finance: typeof finance; readonly name: typeof name; readonly lorem: string[]; readonly hacker: string[]; readonly phone_number: string[]; - readonly finance: string[]; readonly internet: string[]; readonly system: string[]; readonly vehicle: string[]; @@ -207,13 +199,7 @@ export const definitions: DefinitionTypes = { lorem: ['words'], hacker: ['abbreviation', 'adjective', 'noun', 'verb', 'ingverb', 'phrase'], phone_number: ['formats'], - finance: [ - 'account_type', - 'transaction_type', - 'currency', - 'iban', - 'credit_card', - ], + finance, internet: [ 'avatar_uri', 'domain_suffix', diff --git a/src/definitions/finance.ts b/src/definitions/finance.ts new file mode 100644 index 00000000000..3a7f5bf7189 --- /dev/null +++ b/src/definitions/finance.ts @@ -0,0 +1,73 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +/** + * The possible definitions related to finances. + */ +export interface FinanceDefinitions { + /** + * The types of accounts/purposes of an account (e.g. `Savings` account). + */ + account_type: Texts; + /** + * Patterns for credit cards used in this locale. + */ + credit_card: FinanceCreditCardDefinitions; + /** + * Currencies and their symbols (e.g. `US Dollar` -> `USD` / `$`). + */ + currency: FinanceCurrencyDefinitions; + /** + * Types of transactions (e.g. `deposit`). + */ + transaction_type: Texts; +} + +/** + * The credit card patterns by provider (e.g. Visa -> ['34##-######-####L']) + */ +export interface FinanceCreditCardDefinitions { + [provider: string]: FinanceCreditCardPattern[]; +} + +/** + * The pattern used to generate credit card codes. + * `L` will be replaced by the check bit. + * + * @see Helpers.replaceCreditCardSymbols() + */ +export type FinanceCreditCardPattern = string; + +/** + * The possible definitions related to currencies. + */ +export interface FinanceCurrencyDefinitions { + /** + * The information about currencies by their full name. + */ + [currencyName: string]: FinanceCurrencyEntryDefinitions; +} + +/** + * The possible definitions related to currency entries. + */ +export interface FinanceCurrencyEntryDefinitions { + /** + * The code/short text/abbreviation for the currency (e.g. `USD`). + */ + code: string; + /** + * The symbol for the currency (e.g. `$`). + */ + 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/index.ts b/src/definitions/index.ts index 0b83fa87e7c..5a20b618e0d 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -13,6 +13,13 @@ import type { LocaleDefinition, } from './definitions'; import { definitions } from './definitions'; +import type { + FinanceCreditCardDefinitions, + FinanceCreditCardPattern, + FinanceCurrencyDefinitions, + FinanceCurrencyEntryDefinitions, + FinanceDefinitions, +} from './finance'; import type { NameDefinitions, NameTitleDefinitions } from './name'; import type { Format, Formats, Texts, Values } from './utils'; @@ -33,6 +40,11 @@ export type { DatabaseDefinition, DateDefinition, DateEntryDefinition, + FinanceDefinitions, + FinanceCreditCardDefinitions, + FinanceCreditCardPattern, + FinanceCurrencyDefinitions, + FinanceCurrencyEntryDefinitions, NameDefinitions, NameTitleDefinitions, }; diff --git a/src/finance.ts b/src/finance.ts index 719d1198e95..9a7592518b5 100644 --- a/src/finance.ts +++ b/src/finance.ts @@ -244,6 +244,7 @@ export class Finance { format = provider; } else { // Choose a random provider + // TODO ST-DDT 2022-01-30: #375 This is impossible to access if (typeof localeFormat === 'string') { format = localeFormat; } else if (typeof localeFormat === 'object') { diff --git a/src/locales/el/credit_card/index.ts b/src/locales/el/credit_card/index.ts index 3ed856dc133..5222f34e3f0 100644 --- a/src/locales/el/credit_card/index.ts +++ b/src/locales/el/credit_card/index.ts @@ -1,10 +1,11 @@ +import type { FinanceCreditCardDefinitions } from '../../../definitions'; import american_express from './american_express'; import discover from './discover'; import maestro from './maestro'; import mastercard from './mastercard'; import visa from './visa'; -const credit_card: any = { +const credit_card: FinanceCreditCardDefinitions = { american_express, discover, maestro, diff --git a/src/locales/el/finance/index.ts b/src/locales/el/finance/index.ts index d899702fd31..76e0fa8d062 100644 --- a/src/locales/el/finance/index.ts +++ b/src/locales/el/finance/index.ts @@ -1,8 +1,9 @@ +import type { FinanceDefinitions } from '../../../definitions'; import account_type from './account_type'; import currency from './currency'; import transaction_type from './transaction_type'; -const finance: any = { +const finance: Partial = { account_type, currency, transaction_type, diff --git a/src/locales/en/finance/credit_card/index.ts b/src/locales/en/finance/credit_card/index.ts index 47b74b5a06c..69347729fd0 100644 --- a/src/locales/en/finance/credit_card/index.ts +++ b/src/locales/en/finance/credit_card/index.ts @@ -1,3 +1,4 @@ +import type { FinanceCreditCardDefinitions } from '../../../../definitions'; import american_express from './american_express'; import diners_club from './diners_club'; import discover from './discover'; @@ -10,7 +11,7 @@ import solo from './solo'; import switch_ from './switch'; import visa from './visa'; -const credit_card: any = { +const credit_card: FinanceCreditCardDefinitions = { american_express, diners_club, discover, diff --git a/src/locales/en/finance/index.ts b/src/locales/en/finance/index.ts index 969746b0687..004d53143cb 100644 --- a/src/locales/en/finance/index.ts +++ b/src/locales/en/finance/index.ts @@ -1,9 +1,10 @@ +import type { FinanceDefinitions } from '../../../definitions'; import account_type from './account_type'; import credit_card from './credit_card'; import currency from './currency'; import transaction_type from './transaction_type'; -const finance: any = { +const finance: FinanceDefinitions = { account_type, credit_card, currency, diff --git a/src/locales/fa/finance/credit_card/index.ts b/src/locales/fa/finance/credit_card/index.ts index a05f43510f4..14276be0eed 100644 --- a/src/locales/fa/finance/credit_card/index.ts +++ b/src/locales/fa/finance/credit_card/index.ts @@ -1,7 +1,8 @@ +import type { FinanceCreditCardDefinitions } from '../../../../definitions'; import mastercard from './mastercard'; import visa from './visa'; -const credit_card: any = { +const credit_card: FinanceCreditCardDefinitions = { mastercard, visa, }; diff --git a/src/locales/fa/finance/index.ts b/src/locales/fa/finance/index.ts index 969746b0687..004d53143cb 100644 --- a/src/locales/fa/finance/index.ts +++ b/src/locales/fa/finance/index.ts @@ -1,9 +1,10 @@ +import type { FinanceDefinitions } from '../../../definitions'; import account_type from './account_type'; import credit_card from './credit_card'; import currency from './currency'; import transaction_type from './transaction_type'; -const finance: any = { +const finance: FinanceDefinitions = { account_type, credit_card, currency, From e73248e6f8d6f70752309ab790a3c4c307b95202 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 20:00:23 +0100 Subject: [PATCH 15/37] chore: fix definitions to match new linting rules --- src/definitions/utils.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/definitions/utils.ts b/src/definitions/utils.ts index 13e1b6b61fc..da7291753fd 100644 --- a/src/definitions/utils.ts +++ b/src/definitions/utils.ts @@ -1,11 +1,11 @@ // https://stackoverflow.com/a/53395649/4573065 type AllOf = ['Needs to be all of', T]; -export const allOf = - () => - ( - ...array: U & ([T] extends [U[number]] ? unknown : AllOf[]) - ) => - array; + +export function allOf(): ( + ...array: U & ([T] extends [U[number]] ? unknown : AllOf[]) +) => U & ([T] extends [U[number]] ? unknown : AllOf[]) { + return (...array) => array; +} // A list of values that can be used as is. export type Values = readonly T[]; From 8eeff0bf2551fedcba267f504dac35f110aa7d1d Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 20:47:39 +0100 Subject: [PATCH 16/37] feat: split hacker to its own file --- src/definitions/definitions.ts | 30 ++++++-------------- src/definitions/hacker.ts | 51 ++++++++++++++++++++++++++++++++++ src/definitions/index.ts | 3 ++ src/locales/el/hacker/index.ts | 3 +- src/locales/en/hacker/index.ts | 3 +- src/locales/nl/hacker/index.ts | 3 +- src/locales/ru/hacker/index.ts | 3 +- 7 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 src/definitions/hacker.ts diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 8c15e2276f6..3fda7c562e2 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -12,6 +12,8 @@ import type { DateDefinition } 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 { NameDefinitions } from './name'; import { name } from './name'; @@ -26,14 +28,7 @@ export interface Definitions { database: DatabaseDefinition; date: DateDefinition; finance: FinanceDefinitions; - hacker: { - abbreviation; - adjective; - ingverb; - noun; - phrase; - verb; - }; + hacker: HackerDefinitions; internet: { domain_suffix; example_email; @@ -103,14 +98,7 @@ export interface LocaleDefinition { database?: Partial; date?: Partial; finance?: Partial; - hacker?: Partial<{ - abbreviation: any[]; - adjective: any[]; - ingverb: any[]; - noun: any[]; - phrase: any[]; - verb: any[]; - }>; + hacker?: Partial; internet?: Partial<{ avatar_uri: any[]; domain_suffix: any[]; @@ -171,10 +159,10 @@ export interface DefinitionTypes { readonly database: typeof database; readonly date: typeof date; readonly finance: typeof finance; + readonly hacker: typeof hacker; readonly name: typeof name; readonly lorem: string[]; - readonly hacker: string[]; readonly phone_number: string[]; readonly internet: string[]; readonly system: string[]; @@ -195,11 +183,13 @@ export const definitions: DefinitionTypes = { animal, company, commerce, + database, + date, + finance, + hacker: hacker, name, lorem: ['words'], - hacker: ['abbreviation', 'adjective', 'noun', 'verb', 'ingverb', 'phrase'], phone_number: ['formats'], - finance, internet: [ 'avatar_uri', 'domain_suffix', @@ -207,9 +197,7 @@ export const definitions: DefinitionTypes = { 'example_email', 'password', ], - database, system: ['mimeTypes', 'directoryPaths'], - date, vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], music: ['genre'], word: [ diff --git a/src/definitions/hacker.ts b/src/definitions/hacker.ts new file mode 100644 index 00000000000..b92c0a51b4b --- /dev/null +++ b/src/definitions/hacker.ts @@ -0,0 +1,51 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +/** + * The possible definitions related to computers. + */ +export interface HackerDefinitions { + /** + * Generic computer related abbreviations (e.g. `RAM`, `EXE`). + */ + abbreviation: Texts; + /** + * Some computer related adjectives or descriptors (e.g. `digital`, `bluetooth`) + */ + adjective: Texts; + /** + * Some computer related verbs for continuous actions (en: `ing` suffix; e.g. `hacking`). + */ + ingverb: Texts; + /** + * Some computer related nouns (e.g. `protocol`, `sensor`) + */ + noun: Texts; + /** + * Some phrases that will be injected with random hacker values. + */ + phrase: HackerPhraseDefinitions; + /** + * Some computer related verbs (e.g. `hack`). + */ + verb: Texts; +} + +/** + * An array of phrases that will have its placeholders filled with some hacker terms. + * May use any of the HackerDefinition keys wrapped in double braces. + * (e.g. `I'm {{ingverb}} {{adjective}} {{noun}}` ) + */ +export type HackerPhraseDefinitions = 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 5a20b618e0d..ad912219a35 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -20,6 +20,7 @@ import type { FinanceCurrencyEntryDefinitions, FinanceDefinitions, } from './finance'; +import type { HackerDefinitions, HackerPhraseDefinitions } from './hacker'; import type { NameDefinitions, NameTitleDefinitions } from './name'; import type { Format, Formats, Texts, Values } from './utils'; @@ -45,6 +46,8 @@ export type { FinanceCreditCardPattern, FinanceCurrencyDefinitions, FinanceCurrencyEntryDefinitions, + HackerDefinitions, + HackerPhraseDefinitions, NameDefinitions, NameTitleDefinitions, }; diff --git a/src/locales/el/hacker/index.ts b/src/locales/el/hacker/index.ts index 35032f5227c..28143c2bd80 100644 --- a/src/locales/el/hacker/index.ts +++ b/src/locales/el/hacker/index.ts @@ -1,9 +1,10 @@ +import type { HackerDefinitions } from '../../../definitions'; import abbreviation from './abbreviation'; import adjective from './adjective'; import noun from './noun'; import verb from './verb'; -const hacker: any = { +const hacker: Partial = { abbreviation, adjective, noun, diff --git a/src/locales/en/hacker/index.ts b/src/locales/en/hacker/index.ts index 959b7e0a14c..196657a8320 100644 --- a/src/locales/en/hacker/index.ts +++ b/src/locales/en/hacker/index.ts @@ -1,3 +1,4 @@ +import type { HackerDefinitions } from '../../../definitions'; import abbreviation from './abbreviation'; import adjective from './adjective'; import ingverb from './ingverb'; @@ -5,7 +6,7 @@ import noun from './noun'; import phrase from './phrase'; import verb from './verb'; -const hacker: any = { +const hacker: HackerDefinitions = { abbreviation, adjective, ingverb, diff --git a/src/locales/nl/hacker/index.ts b/src/locales/nl/hacker/index.ts index 34dc68f20d0..12c95cf77dc 100644 --- a/src/locales/nl/hacker/index.ts +++ b/src/locales/nl/hacker/index.ts @@ -1,9 +1,10 @@ +import type { HackerDefinitions } from '../../../definitions'; import adjective from './adjective'; import noun from './noun'; import phrase from './phrase'; import verb from './verb'; -const hacker: any = { +const hacker: Partial = { adjective, noun, phrase, diff --git a/src/locales/ru/hacker/index.ts b/src/locales/ru/hacker/index.ts index 959b7e0a14c..d19ca4b25d0 100644 --- a/src/locales/ru/hacker/index.ts +++ b/src/locales/ru/hacker/index.ts @@ -1,3 +1,4 @@ +import type { HackerDefinitions } from '../../../definitions'; import abbreviation from './abbreviation'; import adjective from './adjective'; import ingverb from './ingverb'; @@ -5,7 +6,7 @@ import noun from './noun'; import phrase from './phrase'; import verb from './verb'; -const hacker: any = { +const hacker: Partial = { abbreviation, adjective, ingverb, From 30e13ba67fff7d377a3c5ec0fe8197331ee83f64 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 21:26:40 +0100 Subject: [PATCH 17/37] feat: split internet to its own file --- src/definitions/definitions.ts | 27 +++++++-------------------- src/definitions/index.ts | 2 ++ src/definitions/internet.ts | 29 +++++++++++++++++++++++++++++ src/locales/en/internet/index.ts | 5 +++-- 4 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 src/definitions/internet.ts diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 3fda7c562e2..03008636513 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -14,6 +14,8 @@ 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 { NameDefinitions } from './name'; import { name } from './name'; @@ -29,11 +31,7 @@ export interface Definitions { date: DateDefinition; finance: FinanceDefinitions; hacker: HackerDefinitions; - internet: { - domain_suffix; - example_email; - free_email; - }; + internet: InternetDefinitions; lorem: { words; }; @@ -99,12 +97,7 @@ export interface LocaleDefinition { date?: Partial; finance?: Partial; hacker?: Partial; - internet?: Partial<{ - avatar_uri: any[]; - domain_suffix: any[]; - example_email: any[]; - free_email: any[]; - }>; + internet?: Partial; lorem?: Partial<{ supplemental: any[]; words: any[]; @@ -160,11 +153,11 @@ export interface DefinitionTypes { readonly date: typeof date; readonly finance: typeof finance; readonly hacker: typeof hacker; + readonly internet: typeof internet; readonly name: typeof name; readonly lorem: string[]; readonly phone_number: string[]; - readonly internet: string[]; readonly system: string[]; readonly vehicle: string[]; readonly music: string[]; @@ -186,17 +179,11 @@ export const definitions: DefinitionTypes = { database, date, finance, - hacker: hacker, + hacker, + internet, name, lorem: ['words'], phone_number: ['formats'], - internet: [ - 'avatar_uri', - 'domain_suffix', - 'free_email', - 'example_email', - 'password', - ], system: ['mimeTypes', 'directoryPaths'], vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], music: ['genre'], diff --git a/src/definitions/index.ts b/src/definitions/index.ts index ad912219a35..e9021ce6aed 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -21,6 +21,7 @@ import type { FinanceDefinitions, } from './finance'; import type { HackerDefinitions, HackerPhraseDefinitions } from './hacker'; +import type { InternetDefinitions } from './internet'; import type { NameDefinitions, NameTitleDefinitions } from './name'; import type { Format, Formats, Texts, Values } from './utils'; @@ -48,6 +49,7 @@ export type { FinanceCurrencyEntryDefinitions, HackerDefinitions, HackerPhraseDefinitions, + InternetDefinitions, NameDefinitions, NameTitleDefinitions, }; diff --git a/src/definitions/internet.ts b/src/definitions/internet.ts new file mode 100644 index 00000000000..e06142663ca --- /dev/null +++ b/src/definitions/internet.ts @@ -0,0 +1,29 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +/** + * The possible definitions related to internet stuff. + */ +export interface InternetDefinitions { + /** + * Common top level and similar domains (e.g `de`, `co.uk`). + */ + domain_suffix: Texts; + /** + * Some email domains containing `example` (e.g. `example.com`). + */ + example_email: Texts; + /** + * Some free-mail domains used in that country (e.g. `gmail.de`). + */ + free_email: Texts; +} + +/** + * Internal: A list of all keys for the InternetDefinitions. + */ +export const internet = allOf()( + 'domain_suffix', + 'example_email', + 'free_email' +); diff --git a/src/locales/en/internet/index.ts b/src/locales/en/internet/index.ts index 028fd227691..a1788c66178 100644 --- a/src/locales/en/internet/index.ts +++ b/src/locales/en/internet/index.ts @@ -1,13 +1,14 @@ +import type { InternetDefinitions } from '../../../definitions'; import avatar_uri from './avatar_uri'; import domain_suffix from './domain_suffix'; import example_email from './example_email'; import free_email from './free_email'; -const internet: any = { +const internet = { avatar_uri, domain_suffix, example_email, free_email, -}; +} as InternetDefinitions; export default internet; From 09d13e8aca8e6a66c163e5940697cd7287c136d4 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 21:43:30 +0100 Subject: [PATCH 18/37] feat: split lorem to its own file --- src/definitions/definitions.ts | 15 ++++++--------- src/definitions/index.ts | 2 ++ src/definitions/lorem.ts | 14 ++++++++++++++ src/locales/en/lorem/index.ts | 5 +++-- src/lorem.ts | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 src/definitions/lorem.ts diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 03008636513..11518253816 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -16,6 +16,8 @@ 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 { NameDefinitions } from './name'; import { name } from './name'; @@ -32,9 +34,7 @@ export interface Definitions { finance: FinanceDefinitions; hacker: HackerDefinitions; internet: InternetDefinitions; - lorem: { - words; - }; + lorem: LoremDefinitions; music: { genre; }; @@ -98,10 +98,7 @@ export interface LocaleDefinition { finance?: Partial; hacker?: Partial; internet?: Partial; - lorem?: Partial<{ - supplemental: any[]; - words: any[]; - }>; + lorem?: Partial; music?: Partial<{ genre: any[]; }>; @@ -154,9 +151,9 @@ export interface DefinitionTypes { readonly finance: typeof finance; readonly hacker: typeof hacker; readonly internet: typeof internet; + readonly lorem: typeof lorem; readonly name: typeof name; - readonly lorem: string[]; readonly phone_number: string[]; readonly system: string[]; readonly vehicle: string[]; @@ -182,7 +179,7 @@ export const definitions: DefinitionTypes = { hacker, internet, name, - lorem: ['words'], + lorem, phone_number: ['formats'], system: ['mimeTypes', 'directoryPaths'], vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], diff --git a/src/definitions/index.ts b/src/definitions/index.ts index e9021ce6aed..dfee56eeb2b 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -22,6 +22,7 @@ import type { } from './finance'; import type { HackerDefinitions, HackerPhraseDefinitions } from './hacker'; import type { InternetDefinitions } from './internet'; +import type { LoremDefinitions } from './lorem'; import type { NameDefinitions, NameTitleDefinitions } from './name'; import type { Format, Formats, Texts, Values } from './utils'; @@ -50,6 +51,7 @@ export type { HackerDefinitions, HackerPhraseDefinitions, InternetDefinitions, + LoremDefinitions, NameDefinitions, NameTitleDefinitions, }; diff --git a/src/definitions/lorem.ts b/src/definitions/lorem.ts new file mode 100644 index 00000000000..f2dd8e8036b --- /dev/null +++ b/src/definitions/lorem.ts @@ -0,0 +1,14 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +/** + * The possible definitions related to lorem texts. + */ +export interface LoremDefinitions { + words: Texts; +} + +/** + * Internal: A list of all keys for the LoremDefinitions. + */ +export const lorem = allOf()('words'); diff --git a/src/locales/en/lorem/index.ts b/src/locales/en/lorem/index.ts index 62962376cd4..9f1838e169e 100644 --- a/src/locales/en/lorem/index.ts +++ b/src/locales/en/lorem/index.ts @@ -1,9 +1,10 @@ +import type { LoremDefinitions } from '../../../definitions'; import supplemental from './supplemental'; import words from './words'; -const lorem: any = { +const lorem = { supplemental, words, -}; +} as LoremDefinitions; export default lorem; diff --git a/src/lorem.ts b/src/lorem.ts index 9368ec019fa..afbc6df36e6 100644 --- a/src/lorem.ts +++ b/src/lorem.ts @@ -24,7 +24,7 @@ export class Lorem { */ word(length?: number): string { const hasRightLength = (word: string) => word.length === length; - let properLengthWords: string[]; + let properLengthWords: readonly string[]; if (typeof length === 'undefined') { properLengthWords = this.faker.definitions.lorem.words; } else { From 61e8787d233e2a81fd6d1c4d599d11146278d3ed Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 22:56:01 +0100 Subject: [PATCH 19/37] chore: add lorem jsdocs --- src/definitions/lorem.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/definitions/lorem.ts b/src/definitions/lorem.ts index f2dd8e8036b..b259d1d24b5 100644 --- a/src/definitions/lorem.ts +++ b/src/definitions/lorem.ts @@ -5,6 +5,9 @@ import { allOf } from './utils'; * The possible definitions related to lorem texts. */ export interface LoremDefinitions { + /** + * Lorem words used to generate dummy texts. + */ words: Texts; } From 74f60850b95bfeec4185ad58123b5d942d9015bc Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 23:02:52 +0100 Subject: [PATCH 20/37] feat: split music to its own file --- src/definitions/definitions.ts | 16 +++++++--------- src/definitions/index.ts | 2 ++ src/definitions/music.ts | 17 +++++++++++++++++ src/locales/en/music/index.ts | 3 ++- 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 src/definitions/music.ts diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 11518253816..ae124eb3ea3 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -18,6 +18,8 @@ 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'; @@ -35,9 +37,7 @@ export interface Definitions { hacker: HackerDefinitions; internet: InternetDefinitions; lorem: LoremDefinitions; - music: { - genre; - }; + music: MusicDefinitions; name: NameDefinitions; phone_number: { formats; @@ -99,9 +99,7 @@ export interface LocaleDefinition { hacker?: Partial; internet?: Partial; lorem?: Partial; - music?: Partial<{ - genre: any[]; - }>; + music?: Partial; name?: Partial; phone_number?: Partial<{ formats: any[]; @@ -153,11 +151,11 @@ export interface DefinitionTypes { readonly internet: typeof internet; readonly lorem: typeof lorem; readonly name: typeof name; + readonly music: typeof music; readonly phone_number: string[]; readonly system: string[]; readonly vehicle: string[]; - readonly music: string[]; readonly word: string[]; } @@ -178,12 +176,12 @@ export const definitions: DefinitionTypes = { finance, hacker, internet, - name, lorem, + music, + name, phone_number: ['formats'], system: ['mimeTypes', 'directoryPaths'], vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], - music: ['genre'], word: [ 'adjective', 'adverb', diff --git a/src/definitions/index.ts b/src/definitions/index.ts index dfee56eeb2b..acb6b89d154 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -23,6 +23,7 @@ import type { import type { HackerDefinitions, HackerPhraseDefinitions } from './hacker'; import type { InternetDefinitions } from './internet'; import type { LoremDefinitions } from './lorem'; +import type { MusicDefinitions } from './music'; import type { NameDefinitions, NameTitleDefinitions } from './name'; import type { Format, Formats, Texts, Values } from './utils'; @@ -52,6 +53,7 @@ export type { HackerPhraseDefinitions, InternetDefinitions, LoremDefinitions, + MusicDefinitions, NameDefinitions, NameTitleDefinitions, }; diff --git a/src/definitions/music.ts b/src/definitions/music.ts new file mode 100644 index 00000000000..5fb6a6a4e02 --- /dev/null +++ b/src/definitions/music.ts @@ -0,0 +1,17 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +/** + * The possible definitions related to music. + */ +export interface MusicDefinitions { + /** + * The names of some music genres. + */ + genre: Texts; +} + +/** + * Internal: A list of all keys for the LoremDefinitions. + */ +export const music = allOf()('genre'); diff --git a/src/locales/en/music/index.ts b/src/locales/en/music/index.ts index 54b9163ea41..3347664de77 100644 --- a/src/locales/en/music/index.ts +++ b/src/locales/en/music/index.ts @@ -1,6 +1,7 @@ +import type { MusicDefinitions } from '../../../definitions'; import genre from './genre'; -const music: any = { +const music: MusicDefinitions = { genre, }; From ebe421fe759a2575bd94b18e657c8a6bd2181e90 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 23:24:07 +0100 Subject: [PATCH 21/37] feat: split phone_number to its own file --- src/definitions/definitions.ts | 14 ++++++-------- src/definitions/index.ts | 6 ++++++ src/definitions/music.ts | 2 +- src/definitions/phone_number.ts | 26 ++++++++++++++++++++++++++ src/locales/en/phone_number/index.ts | 3 ++- 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/definitions/phone_number.ts diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index ae124eb3ea3..c33e8d76490 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -22,6 +22,8 @@ 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'; /** * The definitions as used by the Faker modules. @@ -39,9 +41,7 @@ export interface Definitions { lorem: LoremDefinitions; music: MusicDefinitions; name: NameDefinitions; - phone_number: { - formats; - }; + phone_number: PhoneNumberDefinitions; system: { directoryPaths; mimeTypes; @@ -101,9 +101,7 @@ export interface LocaleDefinition { lorem?: Partial; music?: Partial; name?: Partial; - phone_number?: Partial<{ - formats: any[]; - }>; + phone_number?: Partial; system?: Partial<{ directoryPaths: any[]; mimeTypes: any[]; @@ -152,8 +150,8 @@ export interface DefinitionTypes { readonly lorem: typeof lorem; readonly name: typeof name; readonly music: typeof music; + readonly phone_number: typeof phone_number; - readonly phone_number: string[]; readonly system: string[]; readonly vehicle: string[]; readonly word: string[]; @@ -179,7 +177,7 @@ export const definitions: DefinitionTypes = { lorem, music, name, - phone_number: ['formats'], + phone_number: phone_number, system: ['mimeTypes', 'directoryPaths'], vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], word: [ diff --git a/src/definitions/index.ts b/src/definitions/index.ts index acb6b89d154..bc1182ec06e 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -25,6 +25,10 @@ import type { InternetDefinitions } from './internet'; import type { LoremDefinitions } from './lorem'; import type { MusicDefinitions } from './music'; import type { NameDefinitions, NameTitleDefinitions } from './name'; +import type { + PhoneNumberDefinitions, + PhoneNumberFormatDefinitions, +} from './phone_number'; import type { Format, Formats, Texts, Values } from './utils'; export { definitions }; @@ -56,4 +60,6 @@ export type { MusicDefinitions, NameDefinitions, NameTitleDefinitions, + PhoneNumberDefinitions, + PhoneNumberFormatDefinitions, }; diff --git a/src/definitions/music.ts b/src/definitions/music.ts index 5fb6a6a4e02..25079608b95 100644 --- a/src/definitions/music.ts +++ b/src/definitions/music.ts @@ -12,6 +12,6 @@ export interface MusicDefinitions { } /** - * Internal: A list of all keys for the LoremDefinitions. + * Internal: A list of all keys for the MusicDefinitions. */ export const music = allOf()('genre'); diff --git a/src/definitions/phone_number.ts b/src/definitions/phone_number.ts new file mode 100644 index 00000000000..d1e9bd3f27d --- /dev/null +++ b/src/definitions/phone_number.ts @@ -0,0 +1,26 @@ +import { allOf } from './utils'; + +/** + * The possible definitions related to phone numbers. + */ +export interface PhoneNumberDefinitions { + /** + * Some formats for phone numbers. + */ + formats: PhoneNumberFormatDefinitions; +} + +/** + * An array of phone number patterns. + * `#` will be replaced by a random digit (0-9). + * `!` will be replaced by a random digit (2-9). + * (e.g. `!##-!##-####` -> 272-285-0453) + * + * @see Helpers.replaceSymbolWithNumber(format) + */ +export type PhoneNumberFormatDefinitions = string[]; + +/** + * Internal: A list of all keys for the PhoneNumberDefinitions. + */ +export const phone_number = allOf()('formats'); diff --git a/src/locales/en/phone_number/index.ts b/src/locales/en/phone_number/index.ts index f760b9e1550..6b8f73b0266 100644 --- a/src/locales/en/phone_number/index.ts +++ b/src/locales/en/phone_number/index.ts @@ -1,6 +1,7 @@ +import type { PhoneNumberDefinitions } from '../../../definitions'; import formats from './formats'; -const phone_number: any = { +const phone_number: PhoneNumberDefinitions = { formats, }; From 139bf61bae3b6d0d550de099d65d4658d235c4f9 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sun, 30 Jan 2022 23:49:01 +0100 Subject: [PATCH 22/37] feat: split system into onw file --- src/definitions/definitions.ts | 16 ++++++-------- src/definitions/index.ts | 8 +++++++ src/definitions/system.ts | 38 ++++++++++++++++++++++++++++++++++ src/locales/en/system/index.ts | 3 ++- 4 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 src/definitions/system.ts diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index c33e8d76490..1c787ea9f4d 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -24,6 +24,8 @@ 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'; /** * The definitions as used by the Faker modules. @@ -42,10 +44,7 @@ export interface Definitions { music: MusicDefinitions; name: NameDefinitions; phone_number: PhoneNumberDefinitions; - system: { - directoryPaths; - mimeTypes; - }; + system: SystemDefinitions; vehicle: { bicycle_type; fuel; @@ -102,10 +101,7 @@ export interface LocaleDefinition { music?: Partial; name?: Partial; phone_number?: Partial; - system?: Partial<{ - directoryPaths: any[]; - mimeTypes: any[]; - }>; + system?: Partial; team?: Partial<{ creature: any[]; name: any[]; @@ -151,8 +147,8 @@ export interface DefinitionTypes { readonly name: typeof name; readonly music: typeof music; readonly phone_number: typeof phone_number; + readonly system: typeof system; - readonly system: string[]; readonly vehicle: string[]; readonly word: string[]; } @@ -178,7 +174,7 @@ export const definitions: DefinitionTypes = { music, name, phone_number: phone_number, - system: ['mimeTypes', 'directoryPaths'], + system, vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], word: [ 'adjective', diff --git a/src/definitions/index.ts b/src/definitions/index.ts index bc1182ec06e..ca6ef131c79 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -29,6 +29,11 @@ import type { PhoneNumberDefinitions, PhoneNumberFormatDefinitions, } from './phone_number'; +import type { + SystemDefinitions, + SystemMimeTypeDefinitions, + SystemMimeTypeEntryDefinitions, +} from './system'; import type { Format, Formats, Texts, Values } from './utils'; export { definitions }; @@ -62,4 +67,7 @@ export type { NameTitleDefinitions, PhoneNumberDefinitions, PhoneNumberFormatDefinitions, + SystemDefinitions, + SystemMimeTypeDefinitions, + SystemMimeTypeEntryDefinitions, }; diff --git a/src/definitions/system.ts b/src/definitions/system.ts new file mode 100644 index 00000000000..34231e2c067 --- /dev/null +++ b/src/definitions/system.ts @@ -0,0 +1,38 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +/** + * The possible definitions related to files and the system. + */ +export interface SystemDefinitions { + /** + * Returns some common file paths. + */ + directoryPaths: Texts; + mimeTypes: SystemMimeTypeDefinitions; +} + +/** + * The mime type definitions with some additional information. + */ +export interface SystemMimeTypeDefinitions { + [mimeType: string]: SystemMimeTypeEntryDefinitions; +} + +/** + * The mime type entry details. + */ +export interface SystemMimeTypeEntryDefinitions { + source?: string; + extensions?: string[]; + compressible?: boolean; + charset?: string; +} + +/** + * Internal: A list of all keys for the SystemDefinitions. + */ +export const system = allOf()( + 'directoryPaths', + 'mimeTypes' +); diff --git a/src/locales/en/system/index.ts b/src/locales/en/system/index.ts index 3fde96086c0..c873d9d702a 100644 --- a/src/locales/en/system/index.ts +++ b/src/locales/en/system/index.ts @@ -1,7 +1,8 @@ +import type { SystemDefinitions } from '../../../definitions'; import directoryPaths from './directoryPaths'; import mimeTypes from './mimeTypes'; -const system: any = { +const system: SystemDefinitions = { directoryPaths, mimeTypes, }; From 02ae94347241d46768a14552d722f93763fd0320 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 00:11:53 +0100 Subject: [PATCH 23/37] feat: split vehicle into own file --- src/definitions/definitions.ts | 23 +++++-------------- src/definitions/index.ts | 2 ++ src/definitions/vehicle.ts | 39 +++++++++++++++++++++++++++++++++ src/locales/en/vehicle/index.ts | 5 +++-- 4 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 src/definitions/vehicle.ts diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 1c787ea9f4d..a525e7ea11b 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -26,6 +26,8 @@ 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'; /** * The definitions as used by the Faker modules. @@ -45,13 +47,7 @@ export interface Definitions { name: NameDefinitions; phone_number: PhoneNumberDefinitions; system: SystemDefinitions; - vehicle: { - bicycle_type; - fuel; - manufacturer; - model; - type; - }; + vehicle: VehicleDefinitions; word: { adjective: string[]; adverb: string[]; @@ -106,13 +102,7 @@ export interface LocaleDefinition { creature: any[]; name: any[]; }>; - vehicle?: Partial<{ - bicycle: any[]; - fuel: any[]; - manufacturer: any[]; - model: any[]; - type: any[]; - }>; + vehicle?: Partial; word?: Partial<{ adjective: any[]; adverb: any[]; @@ -148,8 +138,7 @@ export interface DefinitionTypes { readonly music: typeof music; readonly phone_number: typeof phone_number; readonly system: typeof system; - - readonly vehicle: string[]; + readonly vehicle: typeof vehicle; readonly word: string[]; } @@ -175,7 +164,7 @@ export const definitions: DefinitionTypes = { name, phone_number: phone_number, system, - vehicle: ['vehicle', 'manufacturer', 'model', 'type', 'fuel', 'vin', 'color'], + vehicle, word: [ 'adjective', 'adverb', diff --git a/src/definitions/index.ts b/src/definitions/index.ts index ca6ef131c79..53660d0ea7f 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -35,6 +35,7 @@ import type { SystemMimeTypeEntryDefinitions, } from './system'; import type { Format, Formats, Texts, Values } from './utils'; +import type { VehicleDefinitions } from './vehicle'; export { definitions }; export type { @@ -70,4 +71,5 @@ export type { SystemDefinitions, SystemMimeTypeDefinitions, SystemMimeTypeEntryDefinitions, + VehicleDefinitions, }; diff --git a/src/definitions/vehicle.ts b/src/definitions/vehicle.ts new file mode 100644 index 00000000000..74d40e41cb6 --- /dev/null +++ b/src/definitions/vehicle.ts @@ -0,0 +1,39 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +/** + * The possible definitions related to vehicles. + */ +export interface VehicleDefinitions { + /** + * Some types of bicycles. + */ + bicycle_type: Texts; + /** + * Some types of fuel (e.g. `Gasoline`). + */ + fuel: Texts; + /** + * Some brands of manufactures (e.g. `Tesla`). + */ + manufacturer: Texts; + /** + * Some names of models (e.g. `Fiesta`). + */ + model: Texts; + /** + * Some types of vehicles (e.g. `Minivan`). + */ + type: Texts; +} + +/** + * Internal: A list of all keys for the VehicleDefinitions. + */ +export const vehicle = allOf()( + 'bicycle_type', + 'fuel', + 'manufacturer', + 'model', + 'type' +); diff --git a/src/locales/en/vehicle/index.ts b/src/locales/en/vehicle/index.ts index f48d68b37d1..01ecc1c034f 100644 --- a/src/locales/en/vehicle/index.ts +++ b/src/locales/en/vehicle/index.ts @@ -1,15 +1,16 @@ +import type { VehicleDefinitions } from '../../../definitions'; import bicycle from './bicycle'; import fuel from './fuel'; import manufacturer from './manufacturer'; import model from './model'; import type_ from './type'; -const vehicle: any = { +const vehicle = { bicycle, fuel, manufacturer, model, type: type_, -}; +} as Partial; export default vehicle; From 36b0a84748eab0e2165893f323e328b92982e84a Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 00:22:28 +0100 Subject: [PATCH 24/37] feat: split word into own file --- src/definitions/definitions.ts | 36 +++++++--------------------------- src/definitions/index.ts | 2 ++ src/definitions/word.ts | 28 ++++++++++++++++++++++++++ src/locales/en/word/index.ts | 3 ++- 4 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 src/definitions/word.ts diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index a525e7ea11b..c1c9d8420aa 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -28,6 +28,8 @@ 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. @@ -48,15 +50,7 @@ export interface Definitions { phone_number: PhoneNumberDefinitions; system: SystemDefinitions; vehicle: VehicleDefinitions; - word: { - adjective: string[]; - adverb: string[]; - conjunction: string[]; - interjection: string[]; - noun: string[]; - preposition: string[]; - verb: string[]; - }; + word: WordDefinitions; } /** @@ -103,15 +97,7 @@ export interface LocaleDefinition { name: any[]; }>; vehicle?: Partial; - word?: Partial<{ - adjective: any[]; - adverb: any[]; - conjunction: any[]; - interjection: any[]; - noun: any[]; - preposition: any[]; - verb: any[]; - }>; + word?: Partial; [group: string]: any; } @@ -139,7 +125,7 @@ export interface DefinitionTypes { readonly phone_number: typeof phone_number; readonly system: typeof system; readonly vehicle: typeof vehicle; - readonly word: string[]; + readonly word: typeof word; } /** @@ -162,16 +148,8 @@ export const definitions: DefinitionTypes = { lorem, music, name, - phone_number: phone_number, + phone_number, system, vehicle, - word: [ - 'adjective', - 'adverb', - 'conjunction', - 'interjection', - 'noun', - 'preposition', - 'verb', - ], + word, }; diff --git a/src/definitions/index.ts b/src/definitions/index.ts index 53660d0ea7f..de0ca11b1b3 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -36,6 +36,7 @@ import type { } from './system'; import type { Format, Formats, Texts, Values } from './utils'; import type { VehicleDefinitions } from './vehicle'; +import type { WordDefinitions } from './word'; export { definitions }; export type { @@ -72,4 +73,5 @@ export type { SystemMimeTypeDefinitions, SystemMimeTypeEntryDefinitions, VehicleDefinitions, + WordDefinitions, }; diff --git a/src/definitions/word.ts b/src/definitions/word.ts new file mode 100644 index 00000000000..6780d1c2ea8 --- /dev/null +++ b/src/definitions/word.ts @@ -0,0 +1,28 @@ +import type { Texts } from '.'; +import { allOf } from './utils'; + +/** + * The possible definitions related to words. + */ +export interface WordDefinitions { + adjective: Texts; + adverb: Texts; + conjunction: Texts; + interjection: Texts; + noun: Texts; + preposition: Texts; + verb: Texts; +} + +/** + * Internal: A list of all keys for the WordDefinitions. + */ +export const word = allOf()( + 'adjective', + 'adverb', + 'conjunction', + 'interjection', + 'noun', + 'preposition', + 'verb' +); diff --git a/src/locales/en/word/index.ts b/src/locales/en/word/index.ts index 7fed2b4375c..8f76f579b7b 100644 --- a/src/locales/en/word/index.ts +++ b/src/locales/en/word/index.ts @@ -1,3 +1,4 @@ +import type { WordDefinitions } from '../../../definitions'; import adjective from './adjective'; import adverb from './adverb'; import conjunction from './conjunction'; @@ -6,7 +7,7 @@ import noun from './noun'; import preposition from './preposition'; import verb from './verb'; -const word: any = { +const word: WordDefinitions = { adjective, adverb, conjunction, From 7ad45972bcad7e0d942690e7663d81666e17e9b2 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 00:24:27 +0100 Subject: [PATCH 25/37] feat: remove non-api entries from locale definitions --- src/definitions/definitions.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index c1c9d8420aa..70cdc825324 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -67,19 +67,6 @@ export interface LocaleDefinition { address?: Partial; animal?: Partial; - app?: Partial<{ - author: any[]; - name: any[]; - version: any[]; - }>; - business?: Partial<{ - credit_card_expiry_dates: any[]; - credit_card_numbers: any[]; - credit_card_types: any[]; - }>; - cell_phone?: Partial<{ - formats: any[]; - }>; commerce?: Partial; company?: Partial; database?: Partial; @@ -92,10 +79,6 @@ export interface LocaleDefinition { name?: Partial; phone_number?: Partial; system?: Partial; - team?: Partial<{ - creature: any[]; - name: any[]; - }>; vehicle?: Partial; word?: Partial; [group: string]: any; From 0ea2ef8865c3e333cb319c7102275330281c6402 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 00:33:34 +0100 Subject: [PATCH 26/37] chore: fix some style differences --- src/definitions/address.ts | 68 +++++++++++++++++++++++++++++-------- src/definitions/company.ts | 6 ++-- src/definitions/database.ts | 6 ++-- src/definitions/date.ts | 6 ++-- 4 files changed, 62 insertions(+), 24 deletions(-) diff --git a/src/definitions/address.ts b/src/definitions/address.ts index 7c2134f7e83..01e607115a3 100644 --- a/src/definitions/address.ts +++ b/src/definitions/address.ts @@ -5,43 +5,81 @@ import { allOf } from './utils'; * The possible definitions related to addresses. */ export interface AddressDefinitions { - // address.zipCodeByState() expects only { [state: string]: Range } + /** + * Postscodes patterns by state + */ + // TODO ST-DDT 2022-01-31: address.zipCodeByState() expects only { [state: string]: Range } postcode_by_state: Formats | { [state: string]: Range }; + /** + * Postscodes patterns + */ postcode: Format | Formats; - // Names of actual cities + /** + * Names of actual cities + */ city_name?: Texts; - // Common city prefixes + /** + * Common city prefixes + */ city_prefix: Texts; - // Common city suffixes + /** + * Common city suffixes + */ city_suffix: Texts; - // The names of all countries + /** + * The names of all countries + */ country: Texts; - // The names of this country's states + /** + * The names of this country's states + */ state: Texts; + /** + * The abbreviated names of this country's states + */ state_abbr: Texts; - // The names of counties inside the country or state + /** + * The names of counties inside the country or state + */ county: Texts; - // The names of the compass directions. - // First the 4 cardinal directions, then the 4 ordinal directions + /** + * The names of the compass directions. + * First the 4 cardinal directions, then the 4 ordinal directions + */ direction: Texts; + /** + * The abbreviated names of the compass directions. + * First the 4 cardinal directions, then the 4 ordinal directions + */ direction_abbr: Texts; - // Common street prefixes + /** + * Common street prefixes + */ street_prefix: Texts; - // Common street suffixes + /** + * Common street suffixes + */ street_suffix: Texts; - // The address "inside" an address/e.g. an apartment or office. + /** + * The address "inside" an address/e.g. an apartment or office. + */ secondary_address: Texts; - // The iso country codes - country_code: Texts; // Alpha 2 + /** + * The ISO-3166-1 ALPHA-2 country codes + */ + country_code: Texts; + /** + * The ISO-3166-1 ALPHA-3 country codes + */ country_code_alpha_3: Texts; - // The ISO? names of the timezones + // A list of timezones names. time_zone: Texts; } diff --git a/src/definitions/company.ts b/src/definitions/company.ts index b319681b9df..2ff68a5a91b 100644 --- a/src/definitions/company.ts +++ b/src/definitions/company.ts @@ -4,7 +4,7 @@ import { allOf } from './utils'; /** * The possible definitions related to companies. */ -export interface CompanyDefinition { +export interface CompanyDefinitions { // Business/products related words bs_adjective: Texts; bs_noun; @@ -18,9 +18,9 @@ export interface CompanyDefinition { } /** - * Internal: A list of all keys for the CompanyDefinition. + * Internal: A list of all keys for the CompanyDefinitions. */ -export const company = allOf()( +export const company = allOf()( 'bs_adjective', 'bs_noun', 'bs_verb', diff --git a/src/definitions/database.ts b/src/definitions/database.ts index d41dd3a4149..a5a2aeb304c 100644 --- a/src/definitions/database.ts +++ b/src/definitions/database.ts @@ -4,7 +4,7 @@ import { allOf } from './utils'; /** * The possible definitions related to databases. */ -export interface DatabaseDefinition { +export interface DatabaseDefinitions { /** * Database Engine */ @@ -24,9 +24,9 @@ export interface DatabaseDefinition { } /** - * Internal: A list of all keys for the DatabaseDefinition. + * Internal: A list of all keys for the DatabaseDefinitions. */ -export const database = allOf()( +export const database = allOf()( 'collation', 'column', 'engine', diff --git a/src/definitions/date.ts b/src/definitions/date.ts index 87ea0a70609..de35a649a6b 100644 --- a/src/definitions/date.ts +++ b/src/definitions/date.ts @@ -4,7 +4,7 @@ import { allOf } from './utils'; /** * The possible definitions related to dates. */ -export interface DateDefinition { +export interface DateDefinitions { /** * The translations for months (January - December). */ @@ -40,6 +40,6 @@ export interface DateEntryDefinition { } /** - * Internal: A list of all keys for the DateDefinition. + * Internal: A list of all keys for the DateDefinitions. */ -export const date = allOf()('month', 'weekday'); +export const date = allOf()('month', 'weekday'); From c7e7eea01f00ed8a44a8489374f5afb8b4bcb792 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 00:34:48 +0100 Subject: [PATCH 27/37] chore: fix some style differences --- src/definitions/definitions.ts | 18 +++++++++--------- src/definitions/index.ts | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 70cdc825324..a51d414bc21 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -4,11 +4,11 @@ import type { AnimalDefinitions } from './animal'; import { animal } from './animal'; import type { CommerceDefinitions } from './commerce'; import { commerce } from './commerce'; -import type { CompanyDefinition } from './company'; +import type { CompanyDefinitions } from './company'; import { company } from './company'; -import type { DatabaseDefinition } from './database'; +import type { DatabaseDefinitions } from './database'; import { database } from './database'; -import type { DateDefinition } from './date'; +import type { DateDefinitions } from './date'; import { date } from './date'; import type { FinanceDefinitions } from './finance'; import { finance } from './finance'; @@ -38,9 +38,9 @@ export interface Definitions { address: AddressDefinitions; animal: AnimalDefinitions; commerce: CommerceDefinitions; - company: CompanyDefinition; - database: DatabaseDefinition; - date: DateDefinition; + company: CompanyDefinitions; + database: DatabaseDefinitions; + date: DateDefinitions; finance: FinanceDefinitions; hacker: HackerDefinitions; internet: InternetDefinitions; @@ -68,9 +68,9 @@ export interface LocaleDefinition { address?: Partial; animal?: Partial; commerce?: Partial; - company?: Partial; - database?: Partial; - date?: Partial; + company?: Partial; + database?: Partial; + date?: Partial; finance?: Partial; hacker?: Partial; internet?: Partial; diff --git a/src/definitions/index.ts b/src/definitions/index.ts index de0ca11b1b3..f23f41c0148 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -4,9 +4,9 @@ import type { CommerceDefinitions, CommerceProductNameDefinitions, } from './commerce'; -import type { CompanyDefinition } from './company'; -import type { DatabaseDefinition } from './database'; -import type { DateDefinition, DateEntryDefinition } from './date'; +import type { CompanyDefinitions } from './company'; +import type { DatabaseDefinitions } from './database'; +import type { DateDefinitions, DateEntryDefinition } from './date'; import type { Definitions, DefinitionTypes, @@ -51,9 +51,9 @@ export type { AddressDefinitions, CommerceDefinitions, CommerceProductNameDefinitions, - CompanyDefinition, - DatabaseDefinition, - DateDefinition, + CompanyDefinitions as CompanyDefinition, + DatabaseDefinitions as DatabaseDefinition, + DateDefinitions as DateDefinition, DateEntryDefinition, FinanceDefinitions, FinanceCreditCardDefinitions, From 332429ef55f48fb72614e5e96022faea9ec176e6 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 00:56:44 +0100 Subject: [PATCH 28/37] chore: add missing type --- src/locales/en/commerce/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/locales/en/commerce/index.ts b/src/locales/en/commerce/index.ts index 74ccad9a532..30ab7e1ee56 100644 --- a/src/locales/en/commerce/index.ts +++ b/src/locales/en/commerce/index.ts @@ -1,9 +1,10 @@ +import type { CommerceDefinitions } from '../../../definitions'; import color from './color'; import department from './department'; import product_description from './product_description'; import product_name from './product_name'; -const commerce: any = { +const commerce: CommerceDefinitions = { color, department, product_description, From fdb57b25216b03fa0365a054d513917cfbffebc9 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 09:40:54 +0100 Subject: [PATCH 29/37] chore: fix typo --- src/definitions/address.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/definitions/address.ts b/src/definitions/address.ts index 01e607115a3..caba502d04e 100644 --- a/src/definitions/address.ts +++ b/src/definitions/address.ts @@ -6,12 +6,12 @@ import { allOf } from './utils'; */ export interface AddressDefinitions { /** - * Postscodes patterns by state + * Postcodes patterns by state */ // TODO ST-DDT 2022-01-31: address.zipCodeByState() expects only { [state: string]: Range } postcode_by_state: Formats | { [state: string]: Range }; /** - * Postscodes patterns + * Postcodes patterns */ postcode: Format | Formats; From 98c4d58d0318e891d03d54565b0705ac0152f292 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 19:06:58 +0100 Subject: [PATCH 30/37] chore: applychanges from review --- src/definitions/address.ts | 2 +- src/definitions/animal.ts | 2 +- src/definitions/commerce.ts | 2 +- src/definitions/company.ts | 30 ++++++++-- src/definitions/database.ts | 2 +- src/definitions/date.ts | 2 +- src/definitions/definitions.ts | 98 ++++++++++++++++---------------- src/definitions/finance.ts | 2 +- src/definitions/hacker.ts | 2 +- src/definitions/index.ts | 10 ++-- src/definitions/internet.ts | 2 +- src/definitions/lorem.ts | 2 +- src/definitions/music.ts | 2 +- src/definitions/name.ts | 2 +- src/definitions/phone_number.ts | 2 +- src/definitions/system.ts | 2 +- src/definitions/vehicle.ts | 2 +- src/definitions/word.ts | 2 +- src/index.ts | 13 ++--- src/locales/en/company/index.ts | 4 +- src/locales/en/database/index.ts | 4 +- src/locales/en/date/index.ts | 4 +- 22 files changed, 104 insertions(+), 89 deletions(-) diff --git a/src/definitions/address.ts b/src/definitions/address.ts index caba502d04e..7ea3c198d35 100644 --- a/src/definitions/address.ts +++ b/src/definitions/address.ts @@ -86,7 +86,7 @@ export interface AddressDefinitions { /** * Internal: A list of all keys for the AddressDefinitions. */ -export const address = allOf()( +export const ADDRESS = allOf()( 'postcode_by_state', 'postcode', diff --git a/src/definitions/animal.ts b/src/definitions/animal.ts index e8d2993ed03..781a9ee8c97 100644 --- a/src/definitions/animal.ts +++ b/src/definitions/animal.ts @@ -24,7 +24,7 @@ export interface AnimalDefinitions { /** * Internal: A list of all keys for the AnimalDefinitions. */ -export const animal = allOf()( +export const ANIMAL = allOf()( 'dog', 'cat', 'snake', diff --git a/src/definitions/commerce.ts b/src/definitions/commerce.ts index c063a236957..c3341101b62 100644 --- a/src/definitions/commerce.ts +++ b/src/definitions/commerce.ts @@ -44,7 +44,7 @@ export interface CommerceProductNameDefinitions { /** * Internal: A list of all keys for the CommerceDefinitions. */ -export const commerce = allOf()( +export const COMMERCE = allOf()( 'color', 'department', 'product_name', diff --git a/src/definitions/company.ts b/src/definitions/company.ts index 2ff68a5a91b..c600051e353 100644 --- a/src/definitions/company.ts +++ b/src/definitions/company.ts @@ -5,22 +5,40 @@ import { allOf } from './utils'; * The possible definitions related to companies. */ export interface CompanyDefinitions { - // Business/products related words + /** + * Business/products related adjectives. + */ bs_adjective: Texts; - bs_noun; - bs_verb; - // Catch phrases + /** + * Business/products related nouns. + */ + bs_noun: Texts; + /** + * Business/products related verbs. + */ + bs_verb: Texts; + /** + * Catch phrase adjectives. + */ adjective: Texts; + /** + * Catch phrase adjectives. + */ descriptor: Texts; + /** + * Catch phrase adjectives. + */ noun: Texts; - // Company suffixes + /** + * Company suffixes + */ suffix: Texts; } /** * Internal: A list of all keys for the CompanyDefinitions. */ -export const company = allOf()( +export const COMPANY = allOf()( 'bs_adjective', 'bs_noun', 'bs_verb', diff --git a/src/definitions/database.ts b/src/definitions/database.ts index a5a2aeb304c..f8780b4cefb 100644 --- a/src/definitions/database.ts +++ b/src/definitions/database.ts @@ -26,7 +26,7 @@ export interface DatabaseDefinitions { /** * Internal: A list of all keys for the DatabaseDefinitions. */ -export const database = allOf()( +export const DATABASE = allOf()( 'collation', 'column', 'engine', diff --git a/src/definitions/date.ts b/src/definitions/date.ts index de35a649a6b..0ca5feda498 100644 --- a/src/definitions/date.ts +++ b/src/definitions/date.ts @@ -42,4 +42,4 @@ export interface DateEntryDefinition { /** * Internal: A list of all keys for the DateDefinitions. */ -export const date = allOf()('month', 'weekday'); +export const DATE = allOf()('month', 'weekday'); diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index a51d414bc21..677bb937fd0 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -1,35 +1,35 @@ import type { AddressDefinitions } from './address'; -import { address } from './address'; +import { ADDRESS } from './address'; import type { AnimalDefinitions } from './animal'; -import { animal } from './animal'; +import { ANIMAL } from './animal'; import type { CommerceDefinitions } from './commerce'; -import { commerce } from './commerce'; +import { COMMERCE } from './commerce'; import type { CompanyDefinitions } from './company'; -import { company } from './company'; +import { COMPANY } from './company'; import type { DatabaseDefinitions } from './database'; -import { database } from './database'; +import { DATABASE } from './database'; import type { DateDefinitions } from './date'; -import { date } from './date'; +import { DATE } from './date'; import type { FinanceDefinitions } from './finance'; -import { finance } from './finance'; +import { FINANCE } from './finance'; import type { HackerDefinitions } from './hacker'; -import { hacker } from './hacker'; +import { HACKER } from './hacker'; import type { InternetDefinitions } from './internet'; -import { internet } from './internet'; +import { INTERNET } from './internet'; import type { LoremDefinitions } from './lorem'; -import { lorem } from './lorem'; +import { LOREM } from './lorem'; import type { MusicDefinitions } from './music'; -import { music } from './music'; +import { MUSIC } from './music'; import type { NameDefinitions } from './name'; -import { name } from './name'; +import { NAME } from './name'; import type { PhoneNumberDefinitions } from './phone_number'; -import { phone_number } from './phone_number'; +import { PHONE_NUMBER } from './phone_number'; import type { SystemDefinitions } from './system'; -import { system } from './system'; +import { SYSTEM } from './system'; import type { VehicleDefinitions } from './vehicle'; -import { vehicle } from './vehicle'; +import { VEHICLE } from './vehicle'; import type { WordDefinitions } from './word'; -import { word } from './word'; +import { WORD } from './word'; /** * The definitions as used by the Faker modules. @@ -93,46 +93,46 @@ export interface DefinitionTypes { readonly title: string; readonly separator: string; - readonly address: typeof address; - readonly animal: typeof animal; - readonly commerce: typeof commerce; - readonly company: typeof company; - readonly database: typeof database; - readonly date: typeof date; - readonly finance: typeof finance; - readonly hacker: typeof hacker; - readonly internet: typeof internet; - readonly lorem: typeof lorem; - readonly name: typeof name; - readonly music: typeof music; - readonly phone_number: typeof phone_number; - readonly system: typeof system; - readonly vehicle: typeof vehicle; - readonly word: typeof word; + readonly address: typeof ADDRESS; + readonly animal: typeof ANIMAL; + readonly commerce: typeof COMMERCE; + readonly company: typeof COMPANY; + readonly database: typeof DATABASE; + readonly date: typeof DATE; + readonly finance: typeof FINANCE; + readonly hacker: typeof HACKER; + readonly internet: typeof INTERNET; + readonly lorem: typeof LOREM; + readonly name: typeof NAME; + readonly music: typeof MUSIC; + readonly phone_number: typeof PHONE_NUMBER; + readonly system: typeof SYSTEM; + readonly vehicle: typeof VEHICLE; + readonly word: typeof WORD; } /** * Internal: List off all modules and their properties, * that needs to have a fallback generated in Faker.loadDefinitions(). */ -export const definitions: DefinitionTypes = { +export const DEFINITIONS: DefinitionTypes = { title: '', separator: '', - address, - animal, - company, - commerce, - database, - date, - finance, - hacker, - internet, - lorem, - music, - name, - phone_number, - system, - vehicle, - word, + 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 3a7f5bf7189..9722eb8092c 100644 --- a/src/definitions/finance.ts +++ b/src/definitions/finance.ts @@ -65,7 +65,7 @@ export interface FinanceCurrencyEntryDefinitions { /** * Internal: A list of all keys for the FinanceDefinitions. */ -export const finance = allOf()( +export const FINANCE = allOf()( 'account_type', 'credit_card', 'currency', diff --git a/src/definitions/hacker.ts b/src/definitions/hacker.ts index b92c0a51b4b..40c29af3ce5 100644 --- a/src/definitions/hacker.ts +++ b/src/definitions/hacker.ts @@ -41,7 +41,7 @@ export type HackerPhraseDefinitions = string[]; /** * Internal: A list of all keys for the HackerDefinitions. */ -export const hacker = allOf()( +export const HACKER = allOf()( 'abbreviation', 'adjective', 'ingverb', diff --git a/src/definitions/index.ts b/src/definitions/index.ts index f23f41c0148..d255f5a399d 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -12,7 +12,7 @@ import type { DefinitionTypes, LocaleDefinition, } from './definitions'; -import { definitions } from './definitions'; +import { DEFINITIONS } from './definitions'; import type { FinanceCreditCardDefinitions, FinanceCreditCardPattern, @@ -38,7 +38,7 @@ import type { Format, Formats, Texts, Values } from './utils'; import type { VehicleDefinitions } from './vehicle'; import type { WordDefinitions } from './word'; -export { definitions }; +export { DEFINITIONS }; export type { Definitions, LocaleDefinition, @@ -51,9 +51,9 @@ export type { AddressDefinitions, CommerceDefinitions, CommerceProductNameDefinitions, - CompanyDefinitions as CompanyDefinition, - DatabaseDefinitions as DatabaseDefinition, - DateDefinitions as DateDefinition, + CompanyDefinitions, + DatabaseDefinitions, + DateDefinitions, DateEntryDefinition, FinanceDefinitions, FinanceCreditCardDefinitions, diff --git a/src/definitions/internet.ts b/src/definitions/internet.ts index e06142663ca..de5a7fc472b 100644 --- a/src/definitions/internet.ts +++ b/src/definitions/internet.ts @@ -22,7 +22,7 @@ export interface InternetDefinitions { /** * Internal: A list of all keys for the InternetDefinitions. */ -export const internet = allOf()( +export const INTERNET = allOf()( 'domain_suffix', 'example_email', 'free_email' diff --git a/src/definitions/lorem.ts b/src/definitions/lorem.ts index b259d1d24b5..d5aeaca9751 100644 --- a/src/definitions/lorem.ts +++ b/src/definitions/lorem.ts @@ -14,4 +14,4 @@ export interface LoremDefinitions { /** * Internal: A list of all keys for the LoremDefinitions. */ -export const lorem = allOf()('words'); +export const LOREM = allOf()('words'); diff --git a/src/definitions/music.ts b/src/definitions/music.ts index 25079608b95..a7b8ef68bd3 100644 --- a/src/definitions/music.ts +++ b/src/definitions/music.ts @@ -14,4 +14,4 @@ export interface MusicDefinitions { /** * Internal: A list of all keys for the MusicDefinitions. */ -export const music = allOf()('genre'); +export const MUSIC = allOf()('genre'); diff --git a/src/definitions/name.ts b/src/definitions/name.ts index 96a55547be2..8bae3d2639d 100644 --- a/src/definitions/name.ts +++ b/src/definitions/name.ts @@ -43,7 +43,7 @@ export interface NameTitleDefinitions { /** * Internal: A list of all keys for the NameDefinitions. */ -export const name = allOf()( +export const NAME = allOf()( 'gender', 'binary_gender', diff --git a/src/definitions/phone_number.ts b/src/definitions/phone_number.ts index d1e9bd3f27d..4c6eb98a5ef 100644 --- a/src/definitions/phone_number.ts +++ b/src/definitions/phone_number.ts @@ -23,4 +23,4 @@ export type PhoneNumberFormatDefinitions = string[]; /** * Internal: A list of all keys for the PhoneNumberDefinitions. */ -export const phone_number = allOf()('formats'); +export const PHONE_NUMBER = allOf()('formats'); diff --git a/src/definitions/system.ts b/src/definitions/system.ts index 34231e2c067..586490debc3 100644 --- a/src/definitions/system.ts +++ b/src/definitions/system.ts @@ -32,7 +32,7 @@ export interface SystemMimeTypeEntryDefinitions { /** * Internal: A list of all keys for the SystemDefinitions. */ -export const system = allOf()( +export const SYSTEM = allOf()( 'directoryPaths', 'mimeTypes' ); diff --git a/src/definitions/vehicle.ts b/src/definitions/vehicle.ts index 74d40e41cb6..3015c3f1ac7 100644 --- a/src/definitions/vehicle.ts +++ b/src/definitions/vehicle.ts @@ -30,7 +30,7 @@ export interface VehicleDefinitions { /** * Internal: A list of all keys for the VehicleDefinitions. */ -export const vehicle = allOf()( +export const VEHICLE = allOf()( 'bicycle_type', 'fuel', 'manufacturer', diff --git a/src/definitions/word.ts b/src/definitions/word.ts index 6780d1c2ea8..94f8fa06d77 100644 --- a/src/definitions/word.ts +++ b/src/definitions/word.ts @@ -17,7 +17,7 @@ export interface WordDefinitions { /** * Internal: A list of all keys for the WordDefinitions. */ -export const word = allOf()( +export const WORD = allOf()( 'adjective', 'adverb', 'conjunction', diff --git a/src/index.ts b/src/index.ts index d7de3c03ce3..68dc2d61ca5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,7 @@ import type { DefinitionTypes, LocaleDefinition, } from './definitions'; -import { definitions } from './definitions'; +import { DEFINITIONS } from './definitions'; import { Fake } from './fake'; import { Finance } from './finance'; import { Git } from './git'; @@ -53,8 +53,6 @@ export class Faker { // @ts-expect-error: will be lazy filled by constructor readonly definitions: Definitions = {}; - // This will eventually be replaced by just the imported definitions - private readonly definitionTypes: DefinitionTypes = definitions; seedValue?: any[] | any; @@ -95,17 +93,16 @@ export class Faker { this.locale = this.locale || opts.locale || 'en'; this.localeFallback = this.localeFallback || opts.localeFallback || 'en'; - this.loadDefinitions(this.definitionTypes); + this.loadDefinitions(); } /** * Load the definitions contained in the locales file for the given types - * - * @param types */ - private loadDefinitions(types: DefinitionTypes): void { + private loadDefinitions(): void { // TODO @Shinigami92 2022-01-11: Find a way to load this even more dynamically // In a way so that we don't accidentally miss a definition + const types = DEFINITIONS; Object.keys(types).forEach((t: keyof DefinitionTypes) => { if (typeof this.definitions[t] === 'undefined') { this.definitions[t] = {}; @@ -117,7 +114,7 @@ export class Faker { } // TODO @Shinigami92 2022-01-11: We may have a bug here for the keys 'title' and 'separator' - // @ts-expect-error + // @ts-expect-error `types[t]` needs to be stored in a variable in order for ts to detect that there is no issue here types[t].forEach((p) => { Object.defineProperty(this.definitions[t], p, { get: () => { diff --git a/src/locales/en/company/index.ts b/src/locales/en/company/index.ts index 9c7ab51f91b..82326134396 100644 --- a/src/locales/en/company/index.ts +++ b/src/locales/en/company/index.ts @@ -1,4 +1,4 @@ -import type { CompanyDefinition } from '../../../definitions'; +import type { CompanyDefinitions } from '../../../definitions'; import adjective from './adjective'; import bs_adjective from './bs_adjective'; import bs_noun from './bs_noun'; @@ -20,6 +20,6 @@ const company = { suffix, name, -} as CompanyDefinition; +} as CompanyDefinitions; export default company; diff --git a/src/locales/en/database/index.ts b/src/locales/en/database/index.ts index c6761228d07..44774db2121 100644 --- a/src/locales/en/database/index.ts +++ b/src/locales/en/database/index.ts @@ -1,10 +1,10 @@ -import type { DatabaseDefinition } from '../../../definitions'; +import type { DatabaseDefinitions } from '../../../definitions'; import collation from './collation'; import column from './column'; import engine from './engine'; import type from './type'; -const database: DatabaseDefinition = { +const database: DatabaseDefinitions = { collation, column, engine, diff --git a/src/locales/en/date/index.ts b/src/locales/en/date/index.ts index 3fbc78c67ef..e722b683f7b 100644 --- a/src/locales/en/date/index.ts +++ b/src/locales/en/date/index.ts @@ -1,8 +1,8 @@ -import type { DateDefinition } from '../../../definitions'; +import type { DateDefinitions } from '../../../definitions'; import month from './month'; import weekday from './weekday'; -const date: DateDefinition = { +const date: DateDefinitions = { month, weekday, }; From c0b519c3cfa0705c22660e3d635ed36bd1bdf86b Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 20:06:20 +0100 Subject: [PATCH 31/37] chore: type magic --- src/definitions/definitions.ts | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 677bb937fd0..e85023d3cff 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -89,27 +89,11 @@ export interface LocaleDefinition { * This should be replaced with a Proxy based property access * that don't require prior getter generation in the future. */ -export interface DefinitionTypes { - readonly title: string; - readonly separator: string; - - readonly address: typeof ADDRESS; - readonly animal: typeof ANIMAL; - readonly commerce: typeof COMMERCE; - readonly company: typeof COMPANY; - readonly database: typeof DATABASE; - readonly date: typeof DATE; - readonly finance: typeof FINANCE; - readonly hacker: typeof HACKER; - readonly internet: typeof INTERNET; - readonly lorem: typeof LOREM; - readonly name: typeof NAME; - readonly music: typeof MUSIC; - readonly phone_number: typeof PHONE_NUMBER; - readonly system: typeof SYSTEM; - readonly vehicle: typeof VEHICLE; - readonly word: typeof WORD; -} +export type DefinitionTypes = { + readonly [module in keyof LocaleDefinition]-?: LocaleDefinition[module] extends string + ? string + : Array; +}; /** * Internal: List off all modules and their properties, @@ -135,4 +119,5 @@ export const DEFINITIONS: DefinitionTypes = { system: SYSTEM, vehicle: VEHICLE, word: WORD, + test: '', }; From 5f00c390e9723230f2b0a860f40c797fbce6519e Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 20:28:52 +0100 Subject: [PATCH 32/37] chore: type magic^2 --- src/definitions/definitions.ts | 38 ++++++++++++---------------------- src/definitions/index.ts | 7 +------ 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index e85023d3cff..27c7c45a32e 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -34,7 +34,7 @@ import { WORD } from './word'; /** * The definitions as used by the Faker modules. */ -export interface Definitions { +interface Definitions { address: AddressDefinitions; animal: AnimalDefinitions; commerce: CommerceDefinitions; @@ -58,31 +58,19 @@ export interface Definitions { * This is basically the same as Definitions with the exception, * that most properties are optional and extra properties are allowed. */ -export interface LocaleDefinition { +export type LocaleDefinition = { /** * The name of the language. */ title: string; separator?: string; - - address?: Partial; - animal?: Partial; - commerce?: Partial; - company?: Partial; - database?: Partial; - date?: Partial; - finance?: Partial; - hacker?: Partial; - internet?: Partial; - lorem?: Partial; - music?: Partial; - name?: Partial; - phone_number?: Partial; - system?: Partial; - vehicle?: Partial; - word?: Partial; - [group: string]: any; -} +} & { + // Known modules + [module in keyof Definitions]?: Partial; +} & { + // Unsupported & custom modules + [group: string]: Record; +}; /** * Internal: Compatibility type to ensure all modules have access to fallback locales. @@ -90,9 +78,10 @@ export interface LocaleDefinition { * that don't require prior getter generation in the future. */ export type DefinitionTypes = { - readonly [module in keyof LocaleDefinition]-?: LocaleDefinition[module] extends string - ? string - : Array; + readonly title: string; + readonly separator: string; +} & { + readonly [module in keyof Definitions]: Array; }; /** @@ -119,5 +108,4 @@ export const DEFINITIONS: DefinitionTypes = { system: SYSTEM, vehicle: VEHICLE, word: WORD, - test: '', }; diff --git a/src/definitions/index.ts b/src/definitions/index.ts index d255f5a399d..ea715680f93 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -7,11 +7,7 @@ import type { import type { CompanyDefinitions } from './company'; import type { DatabaseDefinitions } from './database'; import type { DateDefinitions, DateEntryDefinition } from './date'; -import type { - Definitions, - DefinitionTypes, - LocaleDefinition, -} from './definitions'; +import type { DefinitionTypes, LocaleDefinition } from './definitions'; import { DEFINITIONS } from './definitions'; import type { FinanceCreditCardDefinitions, @@ -40,7 +36,6 @@ import type { WordDefinitions } from './word'; export { DEFINITIONS }; export type { - Definitions, LocaleDefinition, DefinitionTypes, Values, From 3a5135095229f3616be5d9cf26fcb131bd6a58af Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 21:16:29 +0100 Subject: [PATCH 33/37] chore: type magic fixes --- src/definitions/definitions.ts | 2 +- src/index.ts | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 27c7c45a32e..d59f84fc859 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -69,7 +69,7 @@ export type LocaleDefinition = { [module in keyof Definitions]?: Partial; } & { // Unsupported & custom modules - [group: string]: Record; + [group: string]: Record | string; }; /** diff --git a/src/index.ts b/src/index.ts index 68dc2d61ca5..5c9c01acc06 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,11 +5,7 @@ import { Company } from './company'; import { Database } from './database'; import { Datatype } from './datatype'; import { _Date } from './date'; -import type { - Definitions, - DefinitionTypes, - LocaleDefinition, -} from './definitions'; +import type { LocaleDefinition } from './definitions'; import { DEFINITIONS } from './definitions'; import { Fake } from './fake'; import { Finance } from './finance'; @@ -38,7 +34,7 @@ type LiteralUnion = T | (U & { zz_IGNORE_ME?: never }); export type UsableLocale = LiteralUnion; export type UsedLocales = Partial>; -export type { Definitions, LocaleDefinition }; +export type { LocaleDefinition }; export interface FakerOptions { locales?: UsedLocales; @@ -51,8 +47,7 @@ export class Faker { locale: UsableLocale; localeFallback: UsableLocale; - // @ts-expect-error: will be lazy filled by constructor - readonly definitions: Definitions = {}; + readonly definitions: LocaleDefinition = { title: 'loading' }; seedValue?: any[] | any; @@ -103,7 +98,7 @@ export class Faker { // TODO @Shinigami92 2022-01-11: Find a way to load this even more dynamically // In a way so that we don't accidentally miss a definition const types = DEFINITIONS; - Object.keys(types).forEach((t: keyof DefinitionTypes) => { + Object.keys(types).forEach((t) => { if (typeof this.definitions[t] === 'undefined') { this.definitions[t] = {}; } @@ -113,8 +108,6 @@ export class Faker { return; } - // TODO @Shinigami92 2022-01-11: We may have a bug here for the keys 'title' and 'separator' - // @ts-expect-error `types[t]` needs to be stored in a variable in order for ts to detect that there is no issue here types[t].forEach((p) => { Object.defineProperty(this.definitions[t], p, { get: () => { From 6ed3e798d23df295da98909eb91fc45fad7c4ad5 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 21:45:12 +0100 Subject: [PATCH 34/37] chore: remove simple type aliases --- src/definitions/address.ts | 41 ++++++++++---------- src/definitions/animal.ts | 29 +++++++------- src/definitions/commerce.ts | 13 +++---- src/definitions/company.ts | 15 ++++---- src/definitions/database.ts | 9 ++--- src/definitions/date.ts | 9 ++--- src/definitions/finance.ts | 27 ++++--------- src/definitions/hacker.ts | 26 ++++++------- src/definitions/index.ts | 18 +-------- src/definitions/internet.ts | 7 ++-- src/definitions/lorem.ts | 3 +- src/definitions/music.ts | 3 +- src/definitions/name.ts | 42 +++++++++++---------- src/definitions/phone_number.ts | 19 ++++------ src/definitions/system.ts | 3 +- src/definitions/utils.ts | 12 ------ src/definitions/vehicle.ts | 11 +++--- src/definitions/word.ts | 15 ++++---- src/locales/el/credit_card/index.ts | 4 +- src/locales/en/address/postcode.ts | 4 +- src/locales/en/finance/credit_card/index.ts | 4 +- src/locales/fa/finance/credit_card/index.ts | 4 +- 22 files changed, 130 insertions(+), 188 deletions(-) diff --git a/src/definitions/address.ts b/src/definitions/address.ts index 7ea3c198d35..a5bf2d1c861 100644 --- a/src/definitions/address.ts +++ b/src/definitions/address.ts @@ -1,4 +1,3 @@ -import type { Format, Formats, Texts } from './utils'; import { allOf } from './utils'; /** @@ -8,79 +7,81 @@ export interface AddressDefinitions { /** * Postcodes patterns by state */ - // TODO ST-DDT 2022-01-31: address.zipCodeByState() expects only { [state: string]: Range } - postcode_by_state: Formats | { [state: string]: Range }; + // TODO ST-DDT 2022-01-31: address.zipCodeByState() expects only { [state: string]: { min: number; max: number } } + postcode_by_state: + | string[] + | { [state: string]: { min: number; max: number } }; /** - * Postcodes patterns + * Postcodes patterns (Fake-Pattern | Fake-Pattern[]). */ - postcode: Format | Formats; + postcode: string | string[]; /** * Names of actual cities */ - city_name?: Texts; + city_name?: string[]; /** * Common city prefixes */ - city_prefix: Texts; + city_prefix: string[]; /** * Common city suffixes */ - city_suffix: Texts; + city_suffix: string[]; /** * The names of all countries */ - country: Texts; + country: string[]; /** * The names of this country's states */ - state: Texts; + state: string[]; /** * The abbreviated names of this country's states */ - state_abbr: Texts; + state_abbr: string[]; /** * The names of counties inside the country or state */ - county: Texts; + county: string[]; /** * The names of the compass directions. * First the 4 cardinal directions, then the 4 ordinal directions */ - direction: Texts; + direction: string[]; /** * The abbreviated names of the compass directions. * First the 4 cardinal directions, then the 4 ordinal directions */ - direction_abbr: Texts; + direction_abbr: string[]; /** * Common street prefixes */ - street_prefix: Texts; + street_prefix: string[]; /** * Common street suffixes */ - street_suffix: Texts; + street_suffix: string[]; /** * The address "inside" an address/e.g. an apartment or office. */ - secondary_address: Texts; + secondary_address: string[]; /** * The ISO-3166-1 ALPHA-2 country codes */ - country_code: Texts; + country_code: string[]; /** * The ISO-3166-1 ALPHA-3 country codes */ - country_code_alpha_3: Texts; + country_code_alpha_3: string[]; // A list of timezones names. - time_zone: Texts; + time_zone: string[]; } /** diff --git a/src/definitions/animal.ts b/src/definitions/animal.ts index 781a9ee8c97..68fe0db24ae 100644 --- a/src/definitions/animal.ts +++ b/src/definitions/animal.ts @@ -1,24 +1,23 @@ -import type { Texts } from './utils'; import { allOf } from './utils'; /** * The possible definitions related to animals. */ export interface AnimalDefinitions { - bear: Texts; - bird: Texts; - cat: Texts; - cetacean: Texts; - cow: Texts; - crocodilia: Texts; - dog: Texts; - fish: Texts; - horse: Texts; - insect: Texts; - lion: Texts; - rabbit: Texts; - snake: Texts; - type: Texts; + bear: string[]; + bird: string[]; + cat: string[]; + cetacean: string[]; + cow: string[]; + crocodilia: string[]; + dog: string[]; + fish: string[]; + horse: string[]; + insect: string[]; + lion: string[]; + rabbit: string[]; + snake: string[]; + type: string[]; } /** diff --git a/src/definitions/commerce.ts b/src/definitions/commerce.ts index c3341101b62..dbe22f69949 100644 --- a/src/definitions/commerce.ts +++ b/src/definitions/commerce.ts @@ -1,4 +1,3 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** @@ -8,11 +7,11 @@ export interface CommerceDefinitions { /** * Human readable color names */ - color: Texts; + color: string[]; /** * Department names inside a shop. */ - department: Texts; + department: string[]; /** * Product name generation definitions. */ @@ -20,7 +19,7 @@ export interface CommerceDefinitions { /** * Descriptions for products. */ - product_description: Texts; + product_description: string[]; } /** @@ -30,15 +29,15 @@ export interface CommerceProductNameDefinitions { /** * Adjectives describing a product (e.g. tasty). */ - adjective: Texts; + adjective: string[]; /** * Materials describing a product (e.g. wood). */ - material: Texts; + material: string[]; /** * Types of products (e.g. chair). */ - product: Texts; + product: string[]; } /** diff --git a/src/definitions/company.ts b/src/definitions/company.ts index c600051e353..35947bde9f7 100644 --- a/src/definitions/company.ts +++ b/src/definitions/company.ts @@ -1,4 +1,3 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** @@ -8,31 +7,31 @@ export interface CompanyDefinitions { /** * Business/products related adjectives. */ - bs_adjective: Texts; + bs_adjective: string[]; /** * Business/products related nouns. */ - bs_noun: Texts; + bs_noun: string[]; /** * Business/products related verbs. */ - bs_verb: Texts; + bs_verb: string[]; /** * Catch phrase adjectives. */ - adjective: Texts; + adjective: string[]; /** * Catch phrase adjectives. */ - descriptor: Texts; + descriptor: string[]; /** * Catch phrase adjectives. */ - noun: Texts; + noun: string[]; /** * Company suffixes */ - suffix: Texts; + suffix: string[]; } /** diff --git a/src/definitions/database.ts b/src/definitions/database.ts index f8780b4cefb..935f35fcd98 100644 --- a/src/definitions/database.ts +++ b/src/definitions/database.ts @@ -1,4 +1,3 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** @@ -8,19 +7,19 @@ export interface DatabaseDefinitions { /** * Database Engine */ - engine: Texts; + engine: string[]; /** * Database Collation */ - collation: Texts; + collation: string[]; /** * Column names */ - column: Texts; + column: string[]; /** * Column types */ - type: Texts; + type: string[]; } /** diff --git a/src/definitions/date.ts b/src/definitions/date.ts index 0ca5feda498..2738bdb5e84 100644 --- a/src/definitions/date.ts +++ b/src/definitions/date.ts @@ -1,4 +1,3 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** @@ -22,21 +21,21 @@ export interface DateEntryDefinition { /** * The long name of the entry. */ - wide: Texts; + wide: string[]; /** * The short name/abbreviation of the entry. */ - abbr: Texts; + abbr: string[]; /** * The wide name of the entry when used in context. If absent wide will be used instead. * It is used to specify a word in context, which may differ from a stand-alone word. */ - wide_context?: Texts; + wide_context?: string[]; /** * The short name/abbreviation name of the entry when used in context. If absent abbr will be used instead. * It is used to specify a word in context, which may differ from a stand-alone word. */ - abbr_context?: Texts; + abbr_context?: string[]; } /** diff --git a/src/definitions/finance.ts b/src/definitions/finance.ts index 9722eb8092c..cbf61704d68 100644 --- a/src/definitions/finance.ts +++ b/src/definitions/finance.ts @@ -1,4 +1,3 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** @@ -8,11 +7,14 @@ export interface FinanceDefinitions { /** * The types of accounts/purposes of an account (e.g. `Savings` account). */ - account_type: Texts; + account_type: string[]; /** - * Patterns for credit cards used in this locale. + * The pattern by provider used to generate credit card codes. + * `L` will be replaced by the check bit. + * + * @see Helpers.replaceCreditCardSymbols() */ - credit_card: FinanceCreditCardDefinitions; + credit_card: { [provider: string]: string[] }; /** * Currencies and their symbols (e.g. `US Dollar` -> `USD` / `$`). */ @@ -20,24 +22,9 @@ export interface FinanceDefinitions { /** * Types of transactions (e.g. `deposit`). */ - transaction_type: Texts; + transaction_type: string[]; } -/** - * The credit card patterns by provider (e.g. Visa -> ['34##-######-####L']) - */ -export interface FinanceCreditCardDefinitions { - [provider: string]: FinanceCreditCardPattern[]; -} - -/** - * The pattern used to generate credit card codes. - * `L` will be replaced by the check bit. - * - * @see Helpers.replaceCreditCardSymbols() - */ -export type FinanceCreditCardPattern = string; - /** * The possible definitions related to currencies. */ diff --git a/src/definitions/hacker.ts b/src/definitions/hacker.ts index 40c29af3ce5..00aa3a40875 100644 --- a/src/definitions/hacker.ts +++ b/src/definitions/hacker.ts @@ -1,4 +1,3 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** @@ -8,36 +7,33 @@ export interface HackerDefinitions { /** * Generic computer related abbreviations (e.g. `RAM`, `EXE`). */ - abbreviation: Texts; + abbreviation: string[]; /** * Some computer related adjectives or descriptors (e.g. `digital`, `bluetooth`) */ - adjective: Texts; + adjective: string[]; /** * Some computer related verbs for continuous actions (en: `ing` suffix; e.g. `hacking`). */ - ingverb: Texts; + ingverb: string[]; /** * Some computer related nouns (e.g. `protocol`, `sensor`) */ - noun: Texts; + noun: string[]; /** - * Some phrases that will be injected with random hacker values. + * Some phrases that will be injected with random hacker words. + * May use any of the HackerDefinition keys wrapped in double braces. + * (e.g. `I'm {{ingverb}} {{adjective}} {{noun}}` ) + * + * @see Helpers.mustache() */ - phrase: HackerPhraseDefinitions; + phrase: string[]; /** * Some computer related verbs (e.g. `hack`). */ - verb: Texts; + verb: string[]; } -/** - * An array of phrases that will have its placeholders filled with some hacker terms. - * May use any of the HackerDefinition keys wrapped in double braces. - * (e.g. `I'm {{ingverb}} {{adjective}} {{noun}}` ) - */ -export type HackerPhraseDefinitions = string[]; - /** * Internal: A list of all keys for the HackerDefinitions. */ diff --git a/src/definitions/index.ts b/src/definitions/index.ts index ea715680f93..6bb681f6fa1 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -10,27 +10,21 @@ import type { DateDefinitions, DateEntryDefinition } from './date'; import type { DefinitionTypes, LocaleDefinition } from './definitions'; import { DEFINITIONS } from './definitions'; import type { - FinanceCreditCardDefinitions, - FinanceCreditCardPattern, FinanceCurrencyDefinitions, FinanceCurrencyEntryDefinitions, FinanceDefinitions, } from './finance'; -import type { HackerDefinitions, HackerPhraseDefinitions } from './hacker'; +import type { HackerDefinitions } from './hacker'; import type { InternetDefinitions } from './internet'; import type { LoremDefinitions } from './lorem'; import type { MusicDefinitions } from './music'; import type { NameDefinitions, NameTitleDefinitions } from './name'; -import type { - PhoneNumberDefinitions, - PhoneNumberFormatDefinitions, -} from './phone_number'; +import type { PhoneNumberDefinitions } from './phone_number'; import type { SystemDefinitions, SystemMimeTypeDefinitions, SystemMimeTypeEntryDefinitions, } from './system'; -import type { Format, Formats, Texts, Values } from './utils'; import type { VehicleDefinitions } from './vehicle'; import type { WordDefinitions } from './word'; @@ -38,10 +32,6 @@ export { DEFINITIONS }; export type { LocaleDefinition, DefinitionTypes, - Values, - Texts, - Format, - Formats, AnimalDefinitions, AddressDefinitions, CommerceDefinitions, @@ -51,19 +41,15 @@ export type { DateDefinitions, DateEntryDefinition, FinanceDefinitions, - FinanceCreditCardDefinitions, - FinanceCreditCardPattern, FinanceCurrencyDefinitions, FinanceCurrencyEntryDefinitions, HackerDefinitions, - HackerPhraseDefinitions, InternetDefinitions, LoremDefinitions, MusicDefinitions, NameDefinitions, NameTitleDefinitions, PhoneNumberDefinitions, - PhoneNumberFormatDefinitions, SystemDefinitions, SystemMimeTypeDefinitions, SystemMimeTypeEntryDefinitions, diff --git a/src/definitions/internet.ts b/src/definitions/internet.ts index de5a7fc472b..55448841d8c 100644 --- a/src/definitions/internet.ts +++ b/src/definitions/internet.ts @@ -1,4 +1,3 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** @@ -8,15 +7,15 @@ export interface InternetDefinitions { /** * Common top level and similar domains (e.g `de`, `co.uk`). */ - domain_suffix: Texts; + domain_suffix: string[]; /** * Some email domains containing `example` (e.g. `example.com`). */ - example_email: Texts; + example_email: string[]; /** * Some free-mail domains used in that country (e.g. `gmail.de`). */ - free_email: Texts; + free_email: string[]; } /** diff --git a/src/definitions/lorem.ts b/src/definitions/lorem.ts index d5aeaca9751..eb548e46fd4 100644 --- a/src/definitions/lorem.ts +++ b/src/definitions/lorem.ts @@ -1,4 +1,3 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** @@ -8,7 +7,7 @@ export interface LoremDefinitions { /** * Lorem words used to generate dummy texts. */ - words: Texts; + words: string[]; } /** diff --git a/src/definitions/music.ts b/src/definitions/music.ts index a7b8ef68bd3..1f2ffdd80bd 100644 --- a/src/definitions/music.ts +++ b/src/definitions/music.ts @@ -1,4 +1,3 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** @@ -8,7 +7,7 @@ export interface MusicDefinitions { /** * The names of some music genres. */ - genre: Texts; + genre: string[]; } /** diff --git a/src/definitions/name.ts b/src/definitions/name.ts index 8bae3d2639d..57926649b09 100644 --- a/src/definitions/name.ts +++ b/src/definitions/name.ts @@ -1,32 +1,34 @@ -import type { Formats, Texts } from './utils'; import { allOf } from './utils'; /** * The possible definitions related to people's names. */ export interface NameDefinitions { - gender: Texts; - binary_gender: Texts; + gender: string[]; + binary_gender: string[]; - prefix?: Texts; - female_prefix?: Texts; - male_prefix?: Texts; + prefix?: string[]; + female_prefix?: string[]; + male_prefix?: string[]; - first_name?: Texts; - female_first_name?: Texts; - male_first_name?: Texts; + first_name?: string[]; + female_first_name?: string[]; + male_first_name?: string[]; - middle_name?: Texts; - female_middle_name?: Texts; - male_middle_name?: Texts; + middle_name?: string[]; + female_middle_name?: string[]; + male_middle_name?: string[]; - last_name?: Texts; - female_last_name?: Texts; - male_last_name?: Texts; + last_name?: string[]; + female_last_name?: string[]; + male_last_name?: string[]; - suffix: Texts; + suffix: string[]; - name: Formats; + /** + * A list of patterns used to generate names (Fake-Pattern[]). + */ + name: string[]; title: NameTitleDefinitions; } @@ -35,9 +37,9 @@ export interface NameDefinitions { * The possible definitions related to people's titles. */ export interface NameTitleDefinitions { - descriptor?: Texts; - job: Texts; - level?: Texts; + descriptor?: string[]; + job: string[]; + level?: string[]; } /** diff --git a/src/definitions/phone_number.ts b/src/definitions/phone_number.ts index 4c6eb98a5ef..ed7353b552d 100644 --- a/src/definitions/phone_number.ts +++ b/src/definitions/phone_number.ts @@ -5,21 +5,16 @@ import { allOf } from './utils'; */ export interface PhoneNumberDefinitions { /** - * Some formats for phone numbers. + * Some patterns used to generate phone numbers. + * `#` will be replaced by a random digit (0-9). + * `!` will be replaced by a random digit (2-9). + * (e.g. `!##-!##-####` -> 272-285-0453) + * + * @see Helpers.replaceSymbolWithNumber(format) */ - formats: PhoneNumberFormatDefinitions; + formats: string[]; } -/** - * An array of phone number patterns. - * `#` will be replaced by a random digit (0-9). - * `!` will be replaced by a random digit (2-9). - * (e.g. `!##-!##-####` -> 272-285-0453) - * - * @see Helpers.replaceSymbolWithNumber(format) - */ -export type PhoneNumberFormatDefinitions = string[]; - /** * Internal: A list of all keys for the PhoneNumberDefinitions. */ diff --git a/src/definitions/system.ts b/src/definitions/system.ts index 586490debc3..70795ac6a67 100644 --- a/src/definitions/system.ts +++ b/src/definitions/system.ts @@ -1,4 +1,3 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** @@ -8,7 +7,7 @@ export interface SystemDefinitions { /** * Returns some common file paths. */ - directoryPaths: Texts; + directoryPaths: string[]; mimeTypes: SystemMimeTypeDefinitions; } diff --git a/src/definitions/utils.ts b/src/definitions/utils.ts index da7291753fd..dfa25be107f 100644 --- a/src/definitions/utils.ts +++ b/src/definitions/utils.ts @@ -6,15 +6,3 @@ export function allOf(): ( ) => U & ([T] extends [U[number]] ? unknown : AllOf[]) { return (...array) => array; } - -// A list of values that can be used as is. -export type Values = readonly T[]; -export type Texts = Values; -// A strings that might contain a placeholder for fake(). -export type Format = string; -export type Formats = readonly Format[]; - -export type Range = { - min: number; - max: number; -}; diff --git a/src/definitions/vehicle.ts b/src/definitions/vehicle.ts index 3015c3f1ac7..7fdc11f1de1 100644 --- a/src/definitions/vehicle.ts +++ b/src/definitions/vehicle.ts @@ -1,4 +1,3 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** @@ -8,23 +7,23 @@ export interface VehicleDefinitions { /** * Some types of bicycles. */ - bicycle_type: Texts; + bicycle_type: string[]; /** * Some types of fuel (e.g. `Gasoline`). */ - fuel: Texts; + fuel: string[]; /** * Some brands of manufactures (e.g. `Tesla`). */ - manufacturer: Texts; + manufacturer: string[]; /** * Some names of models (e.g. `Fiesta`). */ - model: Texts; + model: string[]; /** * Some types of vehicles (e.g. `Minivan`). */ - type: Texts; + type: string[]; } /** diff --git a/src/definitions/word.ts b/src/definitions/word.ts index 94f8fa06d77..dcbe47dd508 100644 --- a/src/definitions/word.ts +++ b/src/definitions/word.ts @@ -1,17 +1,16 @@ -import type { Texts } from '.'; import { allOf } from './utils'; /** * The possible definitions related to words. */ export interface WordDefinitions { - adjective: Texts; - adverb: Texts; - conjunction: Texts; - interjection: Texts; - noun: Texts; - preposition: Texts; - verb: Texts; + adjective: string[]; + adverb: string[]; + conjunction: string[]; + interjection: string[]; + noun: string[]; + preposition: string[]; + verb: string[]; } /** diff --git a/src/locales/el/credit_card/index.ts b/src/locales/el/credit_card/index.ts index 5222f34e3f0..92cf1e689f1 100644 --- a/src/locales/el/credit_card/index.ts +++ b/src/locales/el/credit_card/index.ts @@ -1,11 +1,11 @@ -import type { FinanceCreditCardDefinitions } from '../../../definitions'; +import type { FinanceDefinitions } from '../../../definitions'; import american_express from './american_express'; import discover from './discover'; import maestro from './maestro'; import mastercard from './mastercard'; import visa from './visa'; -const credit_card: FinanceCreditCardDefinitions = { +const credit_card: FinanceDefinitions['credit_card'] = { american_express, discover, maestro, diff --git a/src/locales/en/address/postcode.ts b/src/locales/en/address/postcode.ts index 24b2d2af457..4433f068b5e 100644 --- a/src/locales/en/address/postcode.ts +++ b/src/locales/en/address/postcode.ts @@ -1,3 +1 @@ -import type { Formats } from '../../../definitions'; - -export default ['#####', '#####-####'] as Formats; +export default ['#####', '#####-####']; diff --git a/src/locales/en/finance/credit_card/index.ts b/src/locales/en/finance/credit_card/index.ts index 69347729fd0..08f33e9cbc9 100644 --- a/src/locales/en/finance/credit_card/index.ts +++ b/src/locales/en/finance/credit_card/index.ts @@ -1,4 +1,4 @@ -import type { FinanceCreditCardDefinitions } from '../../../../definitions'; +import type { FinanceDefinitions } from '../../../../definitions'; import american_express from './american_express'; import diners_club from './diners_club'; import discover from './discover'; @@ -11,7 +11,7 @@ import solo from './solo'; import switch_ from './switch'; import visa from './visa'; -const credit_card: FinanceCreditCardDefinitions = { +const credit_card: FinanceDefinitions['credit_card'] = { american_express, diners_club, discover, diff --git a/src/locales/fa/finance/credit_card/index.ts b/src/locales/fa/finance/credit_card/index.ts index 14276be0eed..7a1430a4ac3 100644 --- a/src/locales/fa/finance/credit_card/index.ts +++ b/src/locales/fa/finance/credit_card/index.ts @@ -1,8 +1,8 @@ -import type { FinanceCreditCardDefinitions } from '../../../../definitions'; +import type { FinanceDefinitions } from '../../../../definitions'; import mastercard from './mastercard'; import visa from './visa'; -const credit_card: FinanceCreditCardDefinitions = { +const credit_card: FinanceDefinitions['credit_card'] = { mastercard, visa, }; From 42bf9015491b809325d44c68395e4d51790d5fa3 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 22:03:23 +0100 Subject: [PATCH 35/37] chore: inline more types --- src/definitions/finance.ts | 14 ++------------ src/definitions/index.ts | 4 ---- src/definitions/system.ts | 12 ++++-------- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/definitions/finance.ts b/src/definitions/finance.ts index cbf61704d68..afe3639b5b4 100644 --- a/src/definitions/finance.ts +++ b/src/definitions/finance.ts @@ -16,25 +16,15 @@ export interface FinanceDefinitions { */ credit_card: { [provider: string]: string[] }; /** - * Currencies and their symbols (e.g. `US Dollar` -> `USD` / `$`). + * Currencies by their full name and their symbols (e.g. `US Dollar` -> `USD` / `$`). */ - currency: FinanceCurrencyDefinitions; + currency: { [currencyName: string]: FinanceCurrencyEntryDefinitions }; /** * Types of transactions (e.g. `deposit`). */ transaction_type: string[]; } -/** - * The possible definitions related to currencies. - */ -export interface FinanceCurrencyDefinitions { - /** - * The information about currencies by their full name. - */ - [currencyName: string]: FinanceCurrencyEntryDefinitions; -} - /** * The possible definitions related to currency entries. */ diff --git a/src/definitions/index.ts b/src/definitions/index.ts index 6bb681f6fa1..6deef768568 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -10,7 +10,6 @@ import type { DateDefinitions, DateEntryDefinition } from './date'; import type { DefinitionTypes, LocaleDefinition } from './definitions'; import { DEFINITIONS } from './definitions'; import type { - FinanceCurrencyDefinitions, FinanceCurrencyEntryDefinitions, FinanceDefinitions, } from './finance'; @@ -22,7 +21,6 @@ import type { NameDefinitions, NameTitleDefinitions } from './name'; import type { PhoneNumberDefinitions } from './phone_number'; import type { SystemDefinitions, - SystemMimeTypeDefinitions, SystemMimeTypeEntryDefinitions, } from './system'; import type { VehicleDefinitions } from './vehicle'; @@ -41,7 +39,6 @@ export type { DateDefinitions, DateEntryDefinition, FinanceDefinitions, - FinanceCurrencyDefinitions, FinanceCurrencyEntryDefinitions, HackerDefinitions, InternetDefinitions, @@ -51,7 +48,6 @@ export type { NameTitleDefinitions, PhoneNumberDefinitions, SystemDefinitions, - SystemMimeTypeDefinitions, SystemMimeTypeEntryDefinitions, VehicleDefinitions, WordDefinitions, diff --git a/src/definitions/system.ts b/src/definitions/system.ts index 70795ac6a67..5c9039b43d1 100644 --- a/src/definitions/system.ts +++ b/src/definitions/system.ts @@ -8,14 +8,10 @@ export interface SystemDefinitions { * Returns some common file paths. */ directoryPaths: string[]; - mimeTypes: SystemMimeTypeDefinitions; -} - -/** - * The mime type definitions with some additional information. - */ -export interface SystemMimeTypeDefinitions { - [mimeType: string]: SystemMimeTypeEntryDefinitions; + /** + * The mime type definitions with some additional information. + */ + mimeTypes: { [mimeType: string]: SystemMimeTypeEntryDefinitions }; } /** From a576e95cf9fd38ece752d049ba79fec4dce3b9a3 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 22:07:17 +0100 Subject: [PATCH 36/37] chore: merge import and export statements --- src/definitions/index.ts | 63 ++++++++++++---------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/src/definitions/index.ts b/src/definitions/index.ts index 6deef768568..e4659e0afe6 100644 --- a/src/definitions/index.ts +++ b/src/definitions/index.ts @@ -1,54 +1,27 @@ -import type { AddressDefinitions } from './address'; -import type { AnimalDefinitions } from './animal'; -import type { +export type { AddressDefinitions } from './address'; +export type { AnimalDefinitions } from './animal'; +export type { CommerceDefinitions, CommerceProductNameDefinitions, } from './commerce'; -import type { CompanyDefinitions } from './company'; -import type { DatabaseDefinitions } from './database'; -import type { DateDefinitions, DateEntryDefinition } from './date'; -import type { DefinitionTypes, LocaleDefinition } from './definitions'; -import { DEFINITIONS } from './definitions'; -import type { +export type { CompanyDefinitions } from './company'; +export type { DatabaseDefinitions } from './database'; +export type { DateDefinitions, DateEntryDefinition } from './date'; +export type { DefinitionTypes, LocaleDefinition } from './definitions'; +export { DEFINITIONS } from './definitions'; +export type { FinanceCurrencyEntryDefinitions, FinanceDefinitions, } from './finance'; -import type { HackerDefinitions } from './hacker'; -import type { InternetDefinitions } from './internet'; -import type { LoremDefinitions } from './lorem'; -import type { MusicDefinitions } from './music'; -import type { NameDefinitions, NameTitleDefinitions } from './name'; -import type { PhoneNumberDefinitions } from './phone_number'; -import type { - SystemDefinitions, - SystemMimeTypeEntryDefinitions, -} from './system'; -import type { VehicleDefinitions } from './vehicle'; -import type { WordDefinitions } from './word'; - -export { DEFINITIONS }; +export type { HackerDefinitions } from './hacker'; +export type { InternetDefinitions } from './internet'; +export type { LoremDefinitions } from './lorem'; +export type { MusicDefinitions } from './music'; +export type { NameDefinitions, NameTitleDefinitions } from './name'; +export type { PhoneNumberDefinitions } from './phone_number'; export type { - LocaleDefinition, - DefinitionTypes, - AnimalDefinitions, - AddressDefinitions, - CommerceDefinitions, - CommerceProductNameDefinitions, - CompanyDefinitions, - DatabaseDefinitions, - DateDefinitions, - DateEntryDefinition, - FinanceDefinitions, - FinanceCurrencyEntryDefinitions, - HackerDefinitions, - InternetDefinitions, - LoremDefinitions, - MusicDefinitions, - NameDefinitions, - NameTitleDefinitions, - PhoneNumberDefinitions, SystemDefinitions, SystemMimeTypeEntryDefinitions, - VehicleDefinitions, - WordDefinitions, -}; +} from './system'; +export type { VehicleDefinitions } from './vehicle'; +export type { WordDefinitions } from './word'; From eba1e93e564cea09b566a0101e6b61d26824ffb2 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 31 Jan 2022 22:51:14 +0100 Subject: [PATCH 37/37] chore: apply feedback --- src/definitions/utils.ts | 2 +- src/index.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/definitions/utils.ts b/src/definitions/utils.ts index dfa25be107f..b7b826a1657 100644 --- a/src/definitions/utils.ts +++ b/src/definitions/utils.ts @@ -1,5 +1,5 @@ // https://stackoverflow.com/a/53395649/4573065 -type AllOf = ['Needs to be all of', T]; +export type AllOf = ['Needs to be all of', T]; export function allOf(): ( ...array: U & ([T] extends [U[number]] ? unknown : AllOf[]) diff --git a/src/index.ts b/src/index.ts index 5c9c01acc06..4d9e8438cae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,7 +47,8 @@ export class Faker { locale: UsableLocale; localeFallback: UsableLocale; - readonly definitions: LocaleDefinition = { title: 'loading' }; + // Will be lazy init + readonly definitions: LocaleDefinition = {} as LocaleDefinition; seedValue?: any[] | any; @@ -97,18 +98,17 @@ export class Faker { private loadDefinitions(): void { // TODO @Shinigami92 2022-01-11: Find a way to load this even more dynamically // In a way so that we don't accidentally miss a definition - const types = DEFINITIONS; - Object.keys(types).forEach((t) => { + Object.entries(DEFINITIONS).forEach(([t, v]) => { if (typeof this.definitions[t] === 'undefined') { this.definitions[t] = {}; } - if (typeof types[t] === 'string') { - this.definitions[t] = types[t]; + if (typeof v === 'string') { + this.definitions[t] = v; return; } - types[t].forEach((p) => { + v.forEach((p) => { Object.defineProperty(this.definitions[t], p, { get: () => { if (