From 5f97b343019420842e9b9a02f1c07169f1e84331 Mon Sep 17 00:00:00 2001 From: Hanna Kuczynska Date: Mon, 18 Jul 2022 22:12:34 +0200 Subject: [PATCH 1/9] chore: rename Gender to Sex and use enum instead of string values --- src/index.ts | 3 +- src/modules/name/index.ts | 77 +++++++++++++++++++++------------------ test/name.spec.ts | 16 ++++---- 3 files changed, 50 insertions(+), 46 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8a6b7ecc6b6..42015a69929 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,8 +37,7 @@ export type { NumberColorFormat, StringColorFormat, } from './modules/color'; -export { Gender } from './modules/name'; -export type { GenderType } from './modules/name'; +export type { Sex } from './modules/name'; export type { ChemicalElement, Unit } from './modules/science'; export { Faker }; diff --git a/src/modules/name/index.ts b/src/modules/name/index.ts index 009b35fc45f..02e35fb749e 100644 --- a/src/modules/name/index.ts +++ b/src/modules/name/index.ts @@ -1,26 +1,26 @@ import type { Faker } from '../..'; -export enum Gender { - female = 'female', - male = 'male', +export enum Sex { + Female = 'female', + Male = 'male', } -export type GenderType = 'female' | 'male'; +type SexValue = `${Sex}`; /** - * Select a definition based on given gender. + * Select a definition based on given sex. * * @param faker Faker instance. - * @param gender Gender. + * @param sex Sex. * @param param2 Definitions. - * @param param2.generic Non-gender definitions. + * @param param2.generic Non-sex definitions. * @param param2.female Female definitions. * @param param2.male Male definitions. - * @returns Definition based on given gender. + * @returns Definition based on given sex. */ function selectDefinition( faker: Faker, - gender: GenderType | undefined, + sex: Sex | SexValue | undefined, // TODO @Shinigami92 2022-03-21: Remove fallback empty object when `strict: true` { generic, @@ -29,13 +29,16 @@ function selectDefinition( }: { generic?: string[]; female?: string[]; male?: string[] } = {} ) { let values: string[] | undefined; - switch (gender) { - case 'female': + + switch (sex) { + case Sex.Female: values = female; break; - case 'male': + + case Sex.Male: values = male; break; + default: values = generic; break; @@ -69,7 +72,7 @@ export class Name { /** * Returns a random first name. * - * @param gender The optional gender to use. + * @param sex The optional sex to use. * Can be either `'female'` or `'male'`. * * @example @@ -77,11 +80,11 @@ export class Name { * faker.name.firstName("female") // 'Victoria' * faker.name.firstName("male") // 'Tom' */ - firstName(gender?: GenderType): string { + firstName(sex?: Sex | SexValue): string { const { first_name, female_first_name, male_first_name } = this.faker.definitions.name; - return selectDefinition(this.faker, gender, { + return selectDefinition(this.faker, sex, { generic: first_name, female: female_first_name, male: male_first_name, @@ -91,7 +94,7 @@ export class Name { /** * Returns a random last name. * - * @param gender The optional gender to use. + * @param sex The optional sex to use. * Can be either `'female'` or `'male'`. * * @example @@ -99,11 +102,11 @@ export class Name { * faker.name.lastName("female") // 'Grady' * faker.name.lastName("male") // 'Barton' */ - lastName(gender?: GenderType): string { + lastName(sex?: Sex | SexValue): string { const { last_name, female_last_name, male_last_name } = this.faker.definitions.name; - return selectDefinition(this.faker, gender, { + return selectDefinition(this.faker, sex, { generic: last_name, female: female_last_name, male: male_last_name, @@ -113,7 +116,7 @@ export class Name { /** * Returns a random middle name. * - * @param gender The optional gender to use. + * @param sex The optional sex to use. * Can be either `'female'` or `'male'`. * * @example @@ -121,11 +124,11 @@ export class Name { * faker.name.middleName("female") // 'Анастасівна' * faker.name.middleName("male") // 'Вікторович' */ - middleName(gender?: GenderType): string { + middleName(sex?: Sex | SexValue): string { const { middle_name, female_middle_name, male_middle_name } = this.faker.definitions.name; - return selectDefinition(this.faker, gender, { + return selectDefinition(this.faker, sex, { generic: middle_name, female: female_middle_name, male: male_middle_name, @@ -137,8 +140,7 @@ export class Name { * * @param firstName The optional first name to use. If not specified a random one will be chosen. * @param lastName The optional last name to use. If not specified a random one will be chosen. - * @param gender The optional gender to use. - * Can be either `'female'` or `'male'`. + * @param sex The optional sex to use. Can be either `'female'` or `'male'`. * * @example * faker.name.findName() // 'Allen Brown' @@ -147,17 +149,22 @@ export class Name { * faker.name.findName(undefined, 'Beer') // 'Mr. Alfonso Beer' * faker.name.findName(undefined, undefined, 'male') // 'Fernando Schaefer' */ - findName(firstName?: string, lastName?: string, gender?: GenderType): string { - const normalizedGender: GenderType = - gender ?? this.faker.helpers.arrayElement(['female', 'male']); + findName( + firstName?: string, + lastName?: string, + sex?: Sex | SexValue + ): string { + const normalizedSex: Sex | SexValue = + sex ?? this.faker.helpers.arrayElement([Sex.Female, Sex.Male]); - firstName = firstName || this.firstName(normalizedGender); - lastName = lastName || this.lastName(normalizedGender); + firstName = firstName || this.firstName(normalizedSex); + lastName = lastName || this.lastName(normalizedSex); const nameParts: string[] = []; - const prefix = this.faker.helpers.maybe(() => this.prefix(gender), { + const prefix = this.faker.helpers.maybe(() => this.prefix(sex), { probability: 0.125, }); + if (prefix) { nameParts.push(prefix); } @@ -168,13 +175,12 @@ export class Name { const suffix = this.faker.helpers.maybe(() => this.suffix(), { probability: 0.125, }); + if (suffix) { nameParts.push(suffix); } - const fullName = nameParts.join(' '); - - return fullName; + return nameParts.join(' '); } /** @@ -199,18 +205,17 @@ export class Name { /** * Returns a random name prefix. * - * @param gender The optional gender to use. - * Can be either `'female'` or `'male'`. + * @param sex The optional sex to use. Can be either `'female'` or `'male'`. * * @example * faker.name.prefix() // 'Miss' * faker.name.prefix('female') // 'Ms.' * faker.name.prefix('male') // 'Mr.' */ - prefix(gender?: GenderType): string { + prefix(sex?: Sex | SexValue): string { const { prefix, female_prefix, male_prefix } = this.faker.definitions.name; - return selectDefinition(this.faker, gender, { + return selectDefinition(this.faker, sex, { generic: prefix, female: female_prefix, male: male_prefix, diff --git a/test/name.spec.ts b/test/name.spec.ts index 1d9f44219b2..ed4a4c5129b 100644 --- a/test/name.spec.ts +++ b/test/name.spec.ts @@ -55,7 +55,7 @@ describe('name', () => { expect(first_name.length).toBeGreaterThan(0); }); - it('should return a gender-specific first name', () => { + it('should return a sex-specific first name', () => { let name = faker.name.firstName('female'); expect(faker.definitions.name.female_first_name).toContain(name); @@ -63,7 +63,7 @@ describe('name', () => { expect(faker.definitions.name.male_first_name).toContain(name); }); - it('should return a gender-specific first name when no gender-specific first name was defined', () => { + it('should return a sex-specific first name when no sex-specific first name was defined', () => { faker.locale = 'az'; faker.localeFallback = 'az'; @@ -88,7 +88,7 @@ describe('name', () => { expect(last_name.length).toBeGreaterThan(0); }); - it('should return a gender-specific last name', () => { + it('should return a sex-specific last name', () => { faker.locale = 'az'; let name = faker.name.lastName('female'); @@ -125,7 +125,7 @@ describe('name', () => { expect(faker.definitions.name.male_middle_name).toContain(name); }); - it('should return a gender-specific middle name', () => { + it('should return a sex-specific middle name', () => { faker.locale = 'uk'; let name = faker.name.middleName('female'); @@ -149,7 +149,7 @@ describe('name', () => { expect(fullName).toContain(' '); }); - it('should return a female gender-specific name with firstName and lastName', () => { + it('should return a female sex-specific name with firstName and lastName', () => { faker.locale = 'mk'; const female_specific = [ @@ -167,7 +167,7 @@ describe('name', () => { } }); - it('should return a male gender-specific name with firstName and lastName', () => { + it('should return a male sex-specific name with firstName and lastName', () => { faker.locale = 'mk'; const male_specific = [ @@ -185,7 +185,7 @@ describe('name', () => { } }); - it('should return a female gender-specific name with given firstName and lastName', () => { + it('should return a female sex-specific name with given firstName and lastName', () => { faker.locale = 'mk'; const male_specific = [ @@ -207,7 +207,7 @@ describe('name', () => { } }); - it('should return a male gender-specific name with given firstName and lastName', () => { + it('should return a male sex-specific name with given firstName and lastName', () => { faker.locale = 'mk'; const male_specific = [ From 06eb3e631f6ace37afb08d7c9f35157a06c05bd5 Mon Sep 17 00:00:00 2001 From: Hanna Kuczynska Date: Mon, 18 Jul 2022 22:12:34 +0200 Subject: [PATCH 2/9] chore: rename Gender to Sex and use enum instead of string values --- src/index.ts | 3 +- src/modules/name/index.ts | 83 +++++++++++++++++++++------------------ test/name.spec.ts | 16 ++++---- 3 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8a6b7ecc6b6..42015a69929 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,8 +37,7 @@ export type { NumberColorFormat, StringColorFormat, } from './modules/color'; -export { Gender } from './modules/name'; -export type { GenderType } from './modules/name'; +export type { Sex } from './modules/name'; export type { ChemicalElement, Unit } from './modules/science'; export { Faker }; diff --git a/src/modules/name/index.ts b/src/modules/name/index.ts index 07a4164d7fa..3f768304576 100644 --- a/src/modules/name/index.ts +++ b/src/modules/name/index.ts @@ -1,27 +1,27 @@ import type { Faker } from '../..'; import { deprecated } from '../../internal/deprecated'; -export enum Gender { - female = 'female', - male = 'male', +export enum Sex { + Female = 'female', + Male = 'male', } -export type GenderType = 'female' | 'male'; +type SexValue = `${Sex}`; /** - * Select a definition based on given gender. + * Select a definition based on given sex. * * @param faker Faker instance. - * @param gender Gender. + * @param sex Sex. * @param param2 Definitions. - * @param param2.generic Non-gender definitions. + * @param param2.generic Non-sex definitions. * @param param2.female Female definitions. * @param param2.male Male definitions. - * @returns Definition based on given gender. + * @returns Definition based on given sex. */ function selectDefinition( faker: Faker, - gender: GenderType | undefined, + sex: Sex | SexValue | undefined, // TODO @Shinigami92 2022-03-21: Remove fallback empty object when `strict: true` { generic, @@ -30,13 +30,16 @@ function selectDefinition( }: { generic?: string[]; female?: string[]; male?: string[] } = {} ) { let values: string[] | undefined; - switch (gender) { - case 'female': + + switch (sex) { + case Sex.Female: values = female; break; - case 'male': + + case Sex.Male: values = male; break; + default: values = generic; break; @@ -70,7 +73,7 @@ export class Name { /** * Returns a random first name. * - * @param gender The optional gender to use. + * @param sex The optional sex to use. * Can be either `'female'` or `'male'`. * * @example @@ -78,11 +81,11 @@ export class Name { * faker.name.firstName("female") // 'Victoria' * faker.name.firstName("male") // 'Tom' */ - firstName(gender?: GenderType): string { + firstName(sex?: Sex | SexValue): string { const { first_name, female_first_name, male_first_name } = this.faker.definitions.name; - return selectDefinition(this.faker, gender, { + return selectDefinition(this.faker, sex, { generic: first_name, female: female_first_name, male: male_first_name, @@ -92,7 +95,7 @@ export class Name { /** * Returns a random last name. * - * @param gender The optional gender to use. + * @param sex The optional sex to use. * Can be either `'female'` or `'male'`. * * @example @@ -100,11 +103,11 @@ export class Name { * faker.name.lastName("female") // 'Grady' * faker.name.lastName("male") // 'Barton' */ - lastName(gender?: GenderType): string { + lastName(sex?: Sex | SexValue): string { const { last_name, female_last_name, male_last_name } = this.faker.definitions.name; - return selectDefinition(this.faker, gender, { + return selectDefinition(this.faker, sex, { generic: last_name, female: female_last_name, male: male_last_name, @@ -114,7 +117,7 @@ export class Name { /** * Returns a random middle name. * - * @param gender The optional gender to use. + * @param sex The optional sex to use. * Can be either `'female'` or `'male'`. * * @example @@ -122,11 +125,11 @@ export class Name { * faker.name.middleName("female") // 'Анастасівна' * faker.name.middleName("male") // 'Вікторович' */ - middleName(gender?: GenderType): string { + middleName(sex?: Sex | SexValue): string { const { middle_name, female_middle_name, male_middle_name } = this.faker.definitions.name; - return selectDefinition(this.faker, gender, { + return selectDefinition(this.faker, sex, { generic: middle_name, female: female_middle_name, male: male_middle_name, @@ -138,8 +141,7 @@ export class Name { * * @param firstName The optional first name to use. If not specified a random one will be chosen. * @param lastName The optional last name to use. If not specified a random one will be chosen. - * @param gender The optional gender to use. - * Can be either `'female'` or `'male'`. + * @param sex The optional sex to use. Can be either `'female'` or `'male'`. * * @see faker.name.fullName() * @@ -152,14 +154,19 @@ export class Name { * * @deprecated Use faker.name.fullName() instead. */ - findName(firstName?: string, lastName?: string, gender?: GenderType): string { + findName( + firstName?: string, + lastName?: string, + sex?: Sex | SexValue + ): string { deprecated({ deprecated: 'faker.name.findName()', proposed: 'faker.name.fullName()', since: '7.4', until: '8.0', }); - return this.fullName({ firstName, lastName, gender }); + + return this.fullName({ firstName, lastName, sex }); } /** @@ -168,8 +175,7 @@ export class Name { * @param options An options object. Defaults to `{}`. * @param options.firstName The optional first name to use. If not specified a random one will be chosen. * @param options.lastName The optional last name to use. If not specified a random one will be chosen. - * @param options.gender The optional gender to use. - * Can be either `'female'` or `'male'`. + * @param options.sex The optional sex to use. Can be either `'female'` or `'male'`. * * @example * faker.name.fullName() // 'Allen Brown' @@ -182,19 +188,20 @@ export class Name { options: { firstName?: string; lastName?: string; - gender?: GenderType; + sex?: Sex | SexValue; } = {} ): string { const { - gender = this.faker.helpers.arrayElement(['female', 'male']), - firstName = this.firstName(gender), - lastName = this.lastName(gender), + sex = this.faker.helpers.arrayElement([Sex.Female, Sex.Male]), + firstName = this.firstName(sex), + lastName = this.lastName(sex), } = options; const nameParts: string[] = []; - const prefix = this.faker.helpers.maybe(() => this.prefix(gender), { + const prefix = this.faker.helpers.maybe(() => this.prefix(sex), { probability: 0.125, }); + if (prefix) { nameParts.push(prefix); } @@ -205,13 +212,12 @@ export class Name { const suffix = this.faker.helpers.maybe(() => this.suffix(), { probability: 0.125, }); + if (suffix) { nameParts.push(suffix); } - const fullName = nameParts.join(' '); - - return fullName; + return nameParts.join(' '); } /** @@ -236,18 +242,17 @@ export class Name { /** * Returns a random name prefix. * - * @param gender The optional gender to use. - * Can be either `'female'` or `'male'`. + * @param sex The optional sex to use. Can be either `'female'` or `'male'`. * * @example * faker.name.prefix() // 'Miss' * faker.name.prefix('female') // 'Ms.' * faker.name.prefix('male') // 'Mr.' */ - prefix(gender?: GenderType): string { + prefix(sex?: Sex | SexValue): string { const { prefix, female_prefix, male_prefix } = this.faker.definitions.name; - return selectDefinition(this.faker, gender, { + return selectDefinition(this.faker, sex, { generic: prefix, female: female_prefix, male: male_prefix, diff --git a/test/name.spec.ts b/test/name.spec.ts index c7baf5a9283..0baa14db3dd 100644 --- a/test/name.spec.ts +++ b/test/name.spec.ts @@ -57,7 +57,7 @@ describe('name', () => { expect(first_name.length).toBeGreaterThan(0); }); - it('should return a gender-specific first name', () => { + it('should return a sex-specific first name', () => { let name = faker.name.firstName('female'); expect(faker.definitions.name.female_first_name).toContain(name); @@ -65,7 +65,7 @@ describe('name', () => { expect(faker.definitions.name.male_first_name).toContain(name); }); - it('should return a gender-specific first name when no gender-specific first name was defined', () => { + it('should return a sex-specific first name when no sex-specific first name was defined', () => { faker.locale = 'az'; faker.localeFallback = 'az'; @@ -90,7 +90,7 @@ describe('name', () => { expect(last_name.length).toBeGreaterThan(0); }); - it('should return a gender-specific last name', () => { + it('should return a sex-specific last name', () => { faker.locale = 'az'; let name = faker.name.lastName('female'); @@ -127,7 +127,7 @@ describe('name', () => { expect(faker.definitions.name.male_middle_name).toContain(name); }); - it('should return a gender-specific middle name', () => { + it('should return a sex-specific middle name', () => { faker.locale = 'uk'; let name = faker.name.middleName('female'); @@ -151,7 +151,7 @@ describe('name', () => { expect(fullName).toContain(' '); }); - it('should return a female gender-specific name with firstName and lastName', () => { + it('should return a female sex-specific name with firstName and lastName', () => { faker.locale = 'mk'; const female_specific = [ @@ -169,7 +169,7 @@ describe('name', () => { } }); - it('should return a male gender-specific name with firstName and lastName', () => { + it('should return a male sex-specific name with firstName and lastName', () => { faker.locale = 'mk'; const male_specific = [ @@ -187,7 +187,7 @@ describe('name', () => { } }); - it('should return a female gender-specific name with given firstName and lastName', () => { + it('should return a female sex-specific name with given firstName and lastName', () => { faker.locale = 'mk'; const male_specific = [ @@ -209,7 +209,7 @@ describe('name', () => { } }); - it('should return a male gender-specific name with given firstName and lastName', () => { + it('should return a male sex-specific name with given firstName and lastName', () => { faker.locale = 'mk'; const male_specific = [ From 840d7dd09b580a804bbdd514584ea697cd974c0e Mon Sep 17 00:00:00 2001 From: Hanna Kuczynska Date: Tue, 19 Jul 2022 14:01:27 +0200 Subject: [PATCH 3/9] fix: deprecate Gender enum --- src/index.ts | 2 +- src/modules/name/index.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 42015a69929..5f72d6303f2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,7 +37,7 @@ export type { NumberColorFormat, StringColorFormat, } from './modules/color'; -export type { Sex } from './modules/name'; +export type { Gender, Sex } from './modules/name'; export type { ChemicalElement, Unit } from './modules/science'; export { Faker }; diff --git a/src/modules/name/index.ts b/src/modules/name/index.ts index 3f768304576..62210235779 100644 --- a/src/modules/name/index.ts +++ b/src/modules/name/index.ts @@ -1,6 +1,14 @@ import type { Faker } from '../..'; import { deprecated } from '../../internal/deprecated'; +/** + * @deprecated + */ +export enum Gender { + female = 'female', + male = 'male', +} + export enum Sex { Female = 'female', Male = 'male', From e1d02fe376ec3b303b0b761f46e9c5a53a7012c5 Mon Sep 17 00:00:00 2001 From: Hanna Kuczynska Date: Wed, 20 Jul 2022 12:05:20 +0200 Subject: [PATCH 4/9] chore: SexValue to SexType --- src/modules/name/index.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/modules/name/index.ts b/src/modules/name/index.ts index 62210235779..74acf8394da 100644 --- a/src/modules/name/index.ts +++ b/src/modules/name/index.ts @@ -14,7 +14,7 @@ export enum Sex { Male = 'male', } -type SexValue = `${Sex}`; +type SexType = `${Sex}`; /** * Select a definition based on given sex. @@ -29,7 +29,7 @@ type SexValue = `${Sex}`; */ function selectDefinition( faker: Faker, - sex: Sex | SexValue | undefined, + sex: SexType | undefined, // TODO @Shinigami92 2022-03-21: Remove fallback empty object when `strict: true` { generic, @@ -89,7 +89,7 @@ export class Name { * faker.name.firstName("female") // 'Victoria' * faker.name.firstName("male") // 'Tom' */ - firstName(sex?: Sex | SexValue): string { + firstName(sex?: SexType): string { const { first_name, female_first_name, male_first_name } = this.faker.definitions.name; @@ -111,7 +111,7 @@ export class Name { * faker.name.lastName("female") // 'Grady' * faker.name.lastName("male") // 'Barton' */ - lastName(sex?: Sex | SexValue): string { + lastName(sex?: SexType): string { const { last_name, female_last_name, male_last_name } = this.faker.definitions.name; @@ -133,7 +133,7 @@ export class Name { * faker.name.middleName("female") // 'Анастасівна' * faker.name.middleName("male") // 'Вікторович' */ - middleName(sex?: Sex | SexValue): string { + middleName(sex?: SexType): string { const { middle_name, female_middle_name, male_middle_name } = this.faker.definitions.name; @@ -162,11 +162,7 @@ export class Name { * * @deprecated Use faker.name.fullName() instead. */ - findName( - firstName?: string, - lastName?: string, - sex?: Sex | SexValue - ): string { + findName(firstName?: string, lastName?: string, sex?: SexType): string { deprecated({ deprecated: 'faker.name.findName()', proposed: 'faker.name.fullName()', @@ -196,7 +192,7 @@ export class Name { options: { firstName?: string; lastName?: string; - sex?: Sex | SexValue; + sex?: SexType; } = {} ): string { const { @@ -257,7 +253,7 @@ export class Name { * faker.name.prefix('female') // 'Ms.' * faker.name.prefix('male') // 'Mr.' */ - prefix(sex?: Sex | SexValue): string { + prefix(sex?: SexType): string { const { prefix, female_prefix, male_prefix } = this.faker.definitions.name; return selectDefinition(this.faker, sex, { From dac2e0290797c8869ed58a5e5bd904b660981902 Mon Sep 17 00:00:00 2001 From: Hanna Kuczynska Date: Wed, 20 Jul 2022 12:10:01 +0200 Subject: [PATCH 5/9] fix: bring back export for types --- src/index.ts | 2 +- src/modules/name/index.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5f72d6303f2..de5cdb33ae8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,7 +37,7 @@ export type { NumberColorFormat, StringColorFormat, } from './modules/color'; -export type { Gender, Sex } from './modules/name'; +export type { Gender, GenderType, Sex, SexType } from './modules/name'; export type { ChemicalElement, Unit } from './modules/science'; export { Faker }; diff --git a/src/modules/name/index.ts b/src/modules/name/index.ts index 74acf8394da..38202ac7bf1 100644 --- a/src/modules/name/index.ts +++ b/src/modules/name/index.ts @@ -9,12 +9,17 @@ export enum Gender { male = 'male', } +/** + * @deprecated + */ +export type GenderType = SexType; + export enum Sex { Female = 'female', Male = 'male', } -type SexType = `${Sex}`; +export type SexType = `${Sex}`; /** * Select a definition based on given sex. From c26740fc7a6314edb5edc8d3f091f46aa069a9b8 Mon Sep 17 00:00:00 2001 From: Hanna Kuczynska Date: Tue, 26 Jul 2022 18:22:36 +0200 Subject: [PATCH 6/9] chore: real exports for enums --- src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index de5cdb33ae8..e3b223b0750 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,7 +37,8 @@ export type { NumberColorFormat, StringColorFormat, } from './modules/color'; -export type { Gender, GenderType, Sex, SexType } from './modules/name'; +export { Gender, Sex } from './modules/name'; +export type { GenderType, SexType } from './modules/name'; export type { ChemicalElement, Unit } from './modules/science'; export { Faker }; From 77c24b9658ac8fbb615a8effe2107e010f659066 Mon Sep 17 00:00:00 2001 From: Hanna Kuczynska Date: Tue, 26 Jul 2022 18:58:33 +0200 Subject: [PATCH 7/9] fix: fullName gender param and jsdoc --- src/modules/name/index.ts | 22 +++++++++++++++++----- test/__snapshots__/name.spec.ts.snap | 18 +++++++++++++++--- test/name.spec.ts | 11 +++++++++-- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/modules/name/index.ts b/src/modules/name/index.ts index dd583daba49..9444d888d3b 100644 --- a/src/modules/name/index.ts +++ b/src/modules/name/index.ts @@ -188,27 +188,39 @@ export class Name { * @param options.firstName The optional first name to use. If not specified a random one will be chosen. * @param options.lastName The optional last name to use. If not specified a random one will be chosen. * @param options.sex The optional sex to use. Can be either `'female'` or `'male'`. + * @param options.gender Deprecated. Use `sex` instead. * * @example * faker.name.fullName() // 'Allen Brown' - * faker.name.fullName('Joann') // 'Joann Osinski' - * faker.name.fullName('Marcella', '', 'female') // 'Mrs. Marcella Huels' - * faker.name.fullName(undefined, 'Beer') // 'Mr. Alfonso Beer' - * faker.name.fullName(undefined, undefined, 'male') // 'Fernando Schaefer' + * faker.name.fullName({ firstName: 'Joann' }) // 'Joann Osinski' + * faker.name.fullName({ firstName: 'Marcella', sex: 'female' }) // 'Mrs. Marcella Huels' + * faker.name.fullName({ lastName: 'Beer' }) // 'Mr. Alfonso Beer' + * faker.name.fullName({ sex: 'male' }) // 'Fernando Schaefer' */ fullName( options: { firstName?: string; lastName?: string; + gender?: GenderType; sex?: SexType; } = {} ): string { const { - sex = this.faker.helpers.arrayElement([Sex.Female, Sex.Male]), + gender, + sex = gender || this.faker.helpers.arrayElement([Sex.Female, Sex.Male]), firstName = this.firstName(sex), lastName = this.lastName(sex), } = options; + if (gender) { + deprecated({ + deprecated: `faker.name.fullName({ gender: '...'})`, + proposed: `faker.name.fullName({ sex: '...'})`, + since: '7.4', + until: '8.0', + }); + } + const nameParts: string[] = []; const prefix = this.faker.helpers.maybe(() => this.prefix(sex), { probability: 0.125, diff --git a/test/__snapshots__/name.spec.ts.snap b/test/__snapshots__/name.spec.ts.snap index dc56d58ea46..39043915c7c 100644 --- a/test/__snapshots__/name.spec.ts.snap +++ b/test/__snapshots__/name.spec.ts.snap @@ -14,7 +14,9 @@ exports[`name > 42 > firstName > with gender 1`] = `"Glen"`; exports[`name > 42 > fullName > noArgs 1`] = `"Sadie Wiegand"`; -exports[`name > 42 > fullName > with all 1`] = `"John Doe"`; +exports[`name > 42 > fullName > with all (gender) 1`] = `"John Doe"`; + +exports[`name > 42 > fullName > with all (sex) 1`] = `"John Doe"`; exports[`name > 42 > fullName > with firstName 1`] = `"John Schinner"`; @@ -22,6 +24,8 @@ exports[`name > 42 > fullName > with gender 1`] = `"Melanie Schinner"`; exports[`name > 42 > fullName > with lastName 1`] = `"Sadie Doe"`; +exports[`name > 42 > fullName > with sex 1`] = `"Melanie Schinner"`; + exports[`name > 42 > gender > noArgs 1`] = `"Gender nonconforming"`; exports[`name > 42 > gender > with gender 1`] = `"Female"`; @@ -64,7 +68,9 @@ exports[`name > 1211 > firstName > with gender 1`] = `"Percy"`; exports[`name > 1211 > fullName > noArgs 1`] = `"Claude Trantow"`; -exports[`name > 1211 > fullName > with all 1`] = `"John Doe"`; +exports[`name > 1211 > fullName > with all (gender) 1`] = `"John Doe"`; + +exports[`name > 1211 > fullName > with all (sex) 1`] = `"John Doe"`; exports[`name > 1211 > fullName > with firstName 1`] = `"John Koch"`; @@ -72,6 +78,8 @@ exports[`name > 1211 > fullName > with gender 1`] = `"Patti Koch"`; exports[`name > 1211 > fullName > with lastName 1`] = `"Claude Doe"`; +exports[`name > 1211 > fullName > with sex 1`] = `"Patti Koch"`; + exports[`name > 1211 > gender > noArgs 1`] = `"Trigender"`; exports[`name > 1211 > gender > with gender 1`] = `"Male"`; @@ -114,7 +122,9 @@ exports[`name > 1337 > firstName > with gender 1`] = `"Ray"`; exports[`name > 1337 > fullName > noArgs 1`] = `"Leona Cronin"`; -exports[`name > 1337 > fullName > with all 1`] = `"John Doe"`; +exports[`name > 1337 > fullName > with all (gender) 1`] = `"John Doe"`; + +exports[`name > 1337 > fullName > with all (sex) 1`] = `"John Doe"`; exports[`name > 1337 > fullName > with firstName 1`] = `"John Macejkovic"`; @@ -122,6 +132,8 @@ exports[`name > 1337 > fullName > with gender 1`] = `"Esther Macejkovic"`; exports[`name > 1337 > fullName > with lastName 1`] = `"Leona Doe"`; +exports[`name > 1337 > fullName > with sex 1`] = `"Esther Macejkovic"`; + exports[`name > 1337 > gender > noArgs 1`] = `"Demigender"`; exports[`name > 1337 > gender > with gender 1`] = `"Female"`; diff --git a/test/name.spec.ts b/test/name.spec.ts index d7442fb26b5..be379b70f94 100644 --- a/test/name.spec.ts +++ b/test/name.spec.ts @@ -33,11 +33,18 @@ describe('name', () => { t.it('noArgs') .it('with firstName', { firstName: 'John' }) .it('with lastName', { lastName: 'Doe' }) - .it('with gender', { gender: 'female' }) - .it('with all', { + .it('with gender', { gender: 'female' }) // deprecated + .it('with sex', { sex: 'female' }) + .it('with all (gender)', { firstName: 'John', lastName: 'Doe', + // deprecated gender: 'female', + }) + .it('with all (sex)', { + firstName: 'John', + lastName: 'Doe', + sex: 'female', }); }); }); From 3d693f7a51ea1aa5fcde7c769203bc0ed96a67ad Mon Sep 17 00:00:00 2001 From: Hanna <108692126+hankucz@users.noreply.github.com> Date: Mon, 1 Aug 2022 15:37:46 +0200 Subject: [PATCH 8/9] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Leyla Jähnig --- src/modules/name/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/name/index.ts b/src/modules/name/index.ts index 9444d888d3b..59b940bff01 100644 --- a/src/modules/name/index.ts +++ b/src/modules/name/index.ts @@ -2,7 +2,7 @@ import type { Faker } from '../..'; import { deprecated } from '../../internal/deprecated'; /** - * @deprecated + * @deprecated Use Sex enum instead. */ export enum Gender { // disabled until renamed to Sex @@ -13,7 +13,7 @@ export enum Gender { } /** - * @deprecated + * @deprecated Use SexType instead. */ export type GenderType = SexType; From b603613c5390261898efae0e958218d21822e71f Mon Sep 17 00:00:00 2001 From: Shinigami Date: Mon, 1 Aug 2022 16:07:53 +0200 Subject: [PATCH 9/9] chore: format --- src/modules/name/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/name/index.ts b/src/modules/name/index.ts index 59b940bff01..0a67c382cda 100644 --- a/src/modules/name/index.ts +++ b/src/modules/name/index.ts @@ -214,8 +214,8 @@ export class Name { if (gender) { deprecated({ - deprecated: `faker.name.fullName({ gender: '...'})`, - proposed: `faker.name.fullName({ sex: '...'})`, + deprecated: `faker.name.fullName({ gender: '...' })`, + proposed: `faker.name.fullName({ sex: '...' })`, since: '7.4', until: '8.0', });