-
-
Notifications
You must be signed in to change notification settings - Fork 943
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
Add the concept of order for firstName
and lastName
in name.fullName
#1211
Comments
The suggested solution you provided sounds reasonable to me. Other locales could gain value from this as well. In my opinion, we should call the property in the definition // en version, but that doesn't matter
import { faker } from '@faker-js/faker';
console.log(faker.definitions.name.full_name_order); // 'normal'
// call with no params resolves to the current value of the locale definition (in this case 'normal')
console.log(faker.name.fullName()); // Lexie Bernie
// explicitly set the order, but this doesn't do anything in this case as it's the same as the definitions
console.log(faker.name.fullName({ order: 'normal' })); // Lexie Bernie
// explicitly set the order and override the default value
console.log(faker.name.fullName({ order: 'reverse' })); // Bernie Lexie |
firstName
and lastName
in name.fullName
Yep, Chinese is also "lastname firstname". |
I like the idea, but I wont name it |
Hasn't Spanish(?) some entirely different naming scheme?
Source: https://en.wikipedia.org/wiki/Spanish_naming_customs |
Maybe we can use parameters by country name liked this import { faker } from '@faker-js/faker';
console.log(faker.name.fullName()); // Lexie Bernie
console.log(faker.name.fullName({ country: 'Japan' })); // Bernie Lexie |
If you want Japanese you are most likely using the import { faker } from '@faker-js/faker';
faker.setLocale('jp'); // I'm expecting faker to return Japanese values across all modules
// your suggestion
console.log(faker.name.fullName({ country: 'Japan' }));
// why would I need to set the country to 'Japan' here? I'm already using the Japanese locale. Your suggestion has another flaw. If you provide a |
That makes sense. |
Thank you all for your input. Translated with www.DeepL.com/Translator (free version) |
We are changing our policy to take advantage of legacy templates as you have indicated. And we are considering the following modifications to the fullName function. fullName(
options: {
firstName?: string;
lastName?: string;
gender?: GenderType;
} = {}
): string {
const {
gender = this.faker.helpers.arrayElement(['female', 'male']),
firstName = this.firstName(gender),
lastName = this.lastName(gender),
} = options;
const prefix = this.faker.helpers.maybe(() => this.prefix(gender), {
probability: 0.125,
});
const suffix = this.faker.helpers.maybe(() => this.suffix(), {
probability: 0.125,
});
const nameParts = [];
if (prefix) {
nameParts.push(prefix);
}
nameParts.push(firstName);
nameParts.push(lastName);
if (suffix) {
nameParts.push(suffix);
}
const defaultName = nameParts.join(' ');
if (
!this.faker.definitions.name.name ||
this.faker.definitions.name.name.length === 0
) {
return defaultName;
}
// if (gender || firstName || lastName) {
// return defaultName;
// }
const fullNamePattern = this.faker.helpers.arrayElement(
this.faker.definitions.name.name
);
const fullName = this.faker.helpers.mustache(fullNamePattern, {
'name.gender': () => this.gender(),
'name.binary_gender': () => this.gender(true),
'name.prefix': () => this.prefix(gender),
'name.female_prefix': () => this.prefix(gender),
'name.male_prefix': () => this.prefix(gender),
'name.first_name': () => (firstName ? firstName : this.firstName(gender)),
'name.female_first_name': () =>
firstName ? firstName : this.firstName(gender ? gender : 'female'),
'name.male_first_name': () =>
firstName ? firstName : this.firstName(gender ? gender : 'male'),
'name.middle_name': () => this.middleName(gender),
'name.female_middle_name': () =>
this.middleName(gender ? gender : 'female'),
'name.male_middle_name': () => this.middleName(gender ? gender : 'male'),
'name.last_name': () => (lastName ? lastName : this.lastName(gender)),
'name.female_last_name': () =>
lastName ? lastName : this.lastName(gender ? gender : 'female'),
'name.male_last_name': () =>
lastName ? lastName : this.lastName(gender ? gender : 'male'),
'name.suffix': () => (suffix ? suffix : this.suffix()),
});
return fullName;
} Retrieve the template from the legacy NameDefinitions.name and convert it. Do you have a better idea about this? Thanks for reading. |
Just to note, there's not always a space between the "last" (family) name and first name. For example in |
Team decision We want the full name patterns. |
Clear and concise description of the problem
The sequence of Japanese names is lastName followed by firstName in the Japanese-speaking world.
ex: YAMADA TARO.
YAMADA is lastName.
TARO is firstName.
I would like to incorporate this into faker as well.
// This sentence relies on machine translation.
Suggested solution
Add full_name_order to NameDefinitions.
The full_name_order is as follows.
Add the ordering process using this to fullName in src/modules/name/index.ts.
Alternative
I do not understand Faker or programming that deeply, so the best approach may be something else.
Additional context
In addition to this, we would like to add a collection of first names for Japanese men and a collection of first names for Japanese women.
The text was updated successfully, but these errors were encountered: