Skip to content

Commit

Permalink
refactor(locale): group person entries by gender (#2938)
Browse files Browse the repository at this point in the history
  • Loading branch information
xDivisionByZerox authored Jun 30, 2024
1 parent 92a2f17 commit e21fcaf
Show file tree
Hide file tree
Showing 615 changed files with 102,906 additions and 79,850 deletions.
29 changes: 22 additions & 7 deletions docs/guide/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,28 @@ Removed deprecated number parameter

#### Changed Definitions

The locale definitions used by `faker.person.jobTitle()`, `faker.person.jobDescriptor()`, `faker.person.jobArea()` and `faker.person.jobType()` have been reorganized and are no longer nested under `definitions.person.title`. If you are using the public methods, no changes are required. You only need to change your code if you are accessing the raw definitions e.g. in `faker.helpers.fake()`.

| Before | After |
| ------------------------- | ----------------------- |
| `person.title.descriptor` | `person.job_descriptor` |
| `person.title.level` | `person.job_area` |
| `person.title.job` | `person.job_type` |
The locale definitions used by `faker.person.jobTitle()`, `faker.person.jobDescriptor()`, `faker.person.jobArea()` and `faker.person.jobType()` have been reorganized and are no longer nested under `definitions.person.title`. Conversely, the gendered locale definitions used by `faker.person.firstName()`, `faker.person.lastName()`, `faker.person.middleName()` and `faker.person.prefix()` are now consolidated under a single definition property. If you are using the public methods, no changes are required. You only need to change your code if you are accessing the raw definitions e.g. in `faker.helpers.fake()`.

| Before | After |
| --------------------------------- | ---------------------------------- |
| `person.female_first_name` | `person.first_name.female` |
| `person.female_last_name_pattern` | `person.last_name_pattern.female` |
| `person.female_last_name` | `person.last_name.female` |
| `person.female_middle_name` | `person.middle_name.female` |
| `person.female_prefix` | `person.prefix.female` |
| `person.first_name` | `person.first_name.generic` |
| `person.last_name_pattern` | `person.last_name_pattern.generic` |
| `person.last_name` | `person.last_name.generic` |
| `person.male_first_name` | `person.first_name.male` |
| `person.male_last_name_pattern` | `person.last_name_pattern.male` |
| `person.male_last_name` | `person.last_name.male` |
| `person.male_middle_name` | `person.middle_name.male` |
| `person.male_prefix` | `person.prefix.male` |
| `person.middle_name` | `person.middle_name.generic` |
| `person.prefix` | `person.prefix.generic` |
| `person.title.descriptor` | `person.job_descriptor` |
| `person.title.job` | `person.job_type` |
| `person.title.level` | `person.job_area` |

### Phone Module

Expand Down
2 changes: 1 addition & 1 deletion src/definitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type { LocationDefinition } from './location';
export type { LoremDefinition } from './lorem';
export type { MetadataDefinition } from './metadata';
export type { MusicDefinition } from './music';
export type { PersonDefinition } from './person';
export type { PersonDefinition, PersonEntryDefinition } from './person';
export type { PhoneNumberDefinition } from './phone_number';
export type { ScienceDefinition } from './science';
export type { SystemDefinition, SystemMimeTypeEntryDefinition } from './system';
Expand Down
41 changes: 23 additions & 18 deletions src/definitions/person.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import type { LocaleEntry } from './definitions';

export type PersonEntryDefinition<T> =
| {
generic?: T[];
male: T[];
female: T[];
}
| {
generic: T[];
male?: never;
female?: never;
};

type SimplePersonEntryDefinition = PersonEntryDefinition<string>;
type WeightedPersonEntryDefinition = PersonEntryDefinition<{
value: string;
weight: number;
}>;

/**
* The possible definitions related to people's names.
*/
export type PersonDefinition = LocaleEntry<{
gender: string[];
sex: string[];

prefix: string[];
female_prefix: string[];
male_prefix: string[];

first_name: string[];
female_first_name: string[];
male_first_name: string[];

middle_name: string[];
female_middle_name: string[];
male_middle_name: string[];

last_name: string[];
female_last_name: string[];
male_last_name: string[];
prefix: SimplePersonEntryDefinition;
first_name: SimplePersonEntryDefinition;
middle_name: SimplePersonEntryDefinition;
last_name: SimplePersonEntryDefinition;

suffix: string[];

Expand All @@ -33,9 +40,7 @@ export type PersonDefinition = LocaleEntry<{
/**
* A weighted list of patterns used to generate last names.
*/
last_name_pattern: Array<{ value: string; weight: number }>;
male_last_name_pattern: Array<{ value: string; weight: number }>;
female_last_name_pattern: Array<{ value: string; weight: number }>;
last_name_pattern: WeightedPersonEntryDefinition;

bio_pattern: string[];

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type {
MetadataDefinition,
MusicDefinition,
PersonDefinition,
PersonEntryDefinition,
PhoneNumberDefinition,
ScienceDefinition,
SystemDefinition,
Expand Down
109 changes: 0 additions & 109 deletions src/locales/af_ZA/person/female_first_name.ts

This file was deleted.

Loading

0 comments on commit e21fcaf

Please sign in to comment.