-
-
Notifications
You must be signed in to change notification settings - Fork 919
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
Conversation
There was a problem hiding this 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?
src/name.ts
Outdated
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 | ||
); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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´.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>);
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 Report
@@ 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
|
@budaG This PR needs a rebase |
I will revert all non-locale changes in this PR and create a PR on my own to fix this |
@Shinigami92 review..