Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(locale): added curated names for default(en) locale #440

Merged
merged 3 commits into from
Mar 21, 2022

Conversation

ganeshbudhathoki
Copy link
Contributor

@Shinigami92 review..

Copy link
Member

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add the source of these lists to this PR?

test/name.spec.ts Show resolved Hide resolved
src/name.ts Outdated
Comment on lines 129 to 131
if (typeof gender === 'string') {
if (gender.toLowerCase() === 'male') {
gender = 0;
} else if (gender.toLowerCase() === 'female') {
gender = 1;
}
}

if (typeof gender !== 'number') {
gender = this.faker.datatype.number(1);
if (typeof this.faker.definitions.name.middle_name === 'undefined') {
gender = this.faker.datatype.number(1);
} else {
// Fall back to unisex middle names if they exist and gender wasn't specified
return this.faker.random.arrayElement(
this.faker.definitions.name.middle_name
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code occurs multiple times in the name module, we should move it into a private helper method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shinigami92 I agree. Isolated the duplicated code into a private method. Let me know if it looks good.

src/name.ts Outdated
* @example Name.determineGenderByStringParam('male') // 0
*
*/
private static determineGenderByStringParam(gender: string | number) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this method should do most of the gender related stuff.
String handling, unknown number handling, undefined handling (choose random).
This method should also only ever return `0 | 1´.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you are saying and I agree we should have methods to handle all that separately rather than handling those scenarios in every method but that touches every method. I think it should be a separate story/enhancement/chore to do that. This was to fix the default locale middle name bug.

Copy link
Member

@ST-DDT ST-DDT Feb 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are three ways:

  • Just fix the middle name method without adding a new helper method.
  • Fix the middle name method by creating a separate method, but don't use it in the other methods yet.
  • Fix all name methods by creating a separate method and using it everywhere.

I suggest going for 1 or 2 and then creating a separate PR with option 3 later once this is merged.
@Shinigami92 Any preferences?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the longtime goal, I would really like to deprecate numeric values for gender.
Why is male = 0 and female = 1? What's with binary genders?
The string values would not have a numeric order.

@griest024 also wanted to introduce the possibility to additionally use enum. #352


I would currently like to see just a switch case with default fallback.
But I'm not sure if this becomes to much for this PR and we may want to split it to another PR.
On the other side, as we already targeting 6.1 with this PR, maybe it's okay...


I would write it like so that we can call it this way:

export type Gender = ...;

firstName(gender?: Gender): string
  return this.<functionName>(gender, this.faker.definitions.name.<arrayToUse>);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of Enum, but if we are choosing between lesser of the two evils, switch vs if, for now, I would stick with if, more concise and clear. Let me know your thoughts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-technical nit: can we, like, literally remove the "gender binary" from our codebase (at some point)? I think we can still have the API, but I'd like to make an explicit effort to revamp everything surrounding gender in the lib. I feel pretty strongly about this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is male = 0 and female = 1? What's with binary genders?

lol I love you Shini.

@codecov
Copy link

codecov bot commented Feb 6, 2022

Codecov Report

Merging #440 (f26aebd) into main (1bc622a) will decrease coverage by 0.00%.
The diff coverage is 99.75%.

❗ Current head f26aebd differs from pull request most recent head 3ce0988. Consider uploading reports for the commit 3ce0988 to get more accurate results

@@            Coverage Diff             @@
##             main     #440      +/-   ##
==========================================
- Coverage   99.33%   99.32%   -0.01%     
==========================================
  Files        1920     1923       +3     
  Lines      176471   174617    -1854     
  Branches      905      896       -9     
==========================================
- Hits       175294   173443    -1851     
+ Misses       1121     1118       -3     
  Partials       56       56              
Impacted Files Coverage Δ
src/name.ts 95.79% <96.87%> (+0.87%) ⬆️
src/locales/en/name/female_middle_name.ts 100.00% <100.00%> (ø)
src/locales/en/name/index.ts 100.00% <100.00%> (ø)
src/locales/en/name/male_middle_name.ts 100.00% <100.00%> (ø)
src/locales/en/name/middle_name.ts 100.00% <100.00%> (ø)
src/vendor/user-agent.ts 93.82% <0.00%> (-4.22%) ⬇️
src/finance.ts 99.33% <0.00%> (-0.67%) ⬇️
src/internet.ts 99.42% <0.00%> (-0.58%) ⬇️
src/address.ts 98.55% <0.00%> (-0.16%) ⬇️
... and 463 more

@Shinigami92 Shinigami92 added the needs rebase There is a merge conflict label Mar 10, 2022
@Shinigami92
Copy link
Member

@budaG This PR needs a rebase

@Shinigami92 Shinigami92 added c: bug Something isn't working p: 1-normal Nothing urgent c: locale Permutes locale definitions labels Mar 15, 2022
@Shinigami92
Copy link
Member

I will revert all non-locale changes in this PR and create a PR on my own to fix this

@Shinigami92 Shinigami92 changed the title fix: added curated male, female & unisex middleName for default(en) locale (#373) chore(locale): added curated male, female & unisex middleName for default(en) locale (#373) Mar 21, 2022
@Shinigami92 Shinigami92 requested a review from ST-DDT March 21, 2022 14:26
@Shinigami92 Shinigami92 added s: accepted Accepted feature / Confirmed bug and removed c: feature Request for new feature needs rebase There is a merge conflict labels Mar 21, 2022
@Shinigami92 Shinigami92 changed the title chore(locale): added curated male, female & unisex middleName for default(en) locale (#373) chore(locale): added curated names for default(en) locale (#373) Mar 21, 2022
@Shinigami92 Shinigami92 changed the title chore(locale): added curated names for default(en) locale (#373) chore(locale): added curated names for default(en) locale Mar 21, 2022
@Shinigami92 Shinigami92 enabled auto-merge (squash) March 21, 2022 14:29
@Shinigami92 Shinigami92 merged commit 5642470 into faker-js:main Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working c: locale Permutes locale definitions p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

faker.name lastName and middleName doesn't work correctly with gender selection
4 participants