diff --git a/src/definitions/name.ts b/src/definitions/name.ts index d4999a30138..03bd404d22e 100644 --- a/src/definitions/name.ts +++ b/src/definitions/name.ts @@ -5,7 +5,7 @@ import type { LocaleEntry } from './definitions'; */ export type NameDefinitions = LocaleEntry<{ gender: string[]; - binary_gender: string[]; + sex: string[]; prefix?: string[]; female_prefix?: string[]; diff --git a/src/locales/de/name/index.ts b/src/locales/de/name/index.ts index ffa039e99b9..0c5886c780b 100644 --- a/src/locales/de/name/index.ts +++ b/src/locales/de/name/index.ts @@ -10,6 +10,7 @@ import male_first_name from './male_first_name'; import name_ from './name'; import nobility_title_prefix from './nobility_title_prefix'; import prefix from './prefix'; +import sex from './sex'; const name: NameDefinitions = { female_first_name, @@ -19,6 +20,7 @@ const name: NameDefinitions = { name: name_, nobility_title_prefix, prefix, + sex, }; export default name; diff --git a/src/locales/de/name/sex.ts b/src/locales/de/name/sex.ts new file mode 100644 index 00000000000..c06d0d66da8 --- /dev/null +++ b/src/locales/de/name/sex.ts @@ -0,0 +1 @@ +export default ['männlich', 'weiblich']; diff --git a/src/locales/en/name/binary_gender.ts b/src/locales/en/name/binary_gender.ts deleted file mode 100644 index 347a852f493..00000000000 --- a/src/locales/en/name/binary_gender.ts +++ /dev/null @@ -1 +0,0 @@ -export default ['Female', 'Male']; diff --git a/src/locales/en/name/index.ts b/src/locales/en/name/index.ts index 67668f73061..c1522a38996 100644 --- a/src/locales/en/name/index.ts +++ b/src/locales/en/name/index.ts @@ -3,7 +3,6 @@ * Run 'pnpm run generate:locales' to update. */ import type { NameDefinitions } from '../../..'; -import binary_gender from './binary_gender'; import female_first_name from './female_first_name'; import female_middle_name from './female_middle_name'; import first_name from './first_name'; @@ -14,11 +13,11 @@ import male_middle_name from './male_middle_name'; import middle_name from './middle_name'; import name_ from './name'; import prefix from './prefix'; +import sex from './sex'; import suffix from './suffix'; import title from './title'; const name: NameDefinitions = { - binary_gender, female_first_name, female_middle_name, first_name, @@ -29,6 +28,7 @@ const name: NameDefinitions = { middle_name, name: name_, prefix, + sex, suffix, title, }; diff --git a/src/locales/en/name/sex.ts b/src/locales/en/name/sex.ts new file mode 100644 index 00000000000..66576370327 --- /dev/null +++ b/src/locales/en/name/sex.ts @@ -0,0 +1 @@ +export default ['female', 'male']; diff --git a/src/locales/fr/name/index.ts b/src/locales/fr/name/index.ts index 64963579864..fb0bbc37f27 100644 --- a/src/locales/fr/name/index.ts +++ b/src/locales/fr/name/index.ts @@ -3,23 +3,23 @@ * Run 'pnpm run generate:locales' to update. */ import type { NameDefinitions } from '../../..'; -import binary_gender from './binary_gender'; import female_first_name from './female_first_name'; import first_name from './first_name'; import last_name from './last_name'; import male_first_name from './male_first_name'; import name_ from './name'; import prefix from './prefix'; +import sex from './sex'; import title from './title'; const name: NameDefinitions = { - binary_gender, female_first_name, first_name, last_name, male_first_name, name: name_, prefix, + sex, title, }; diff --git a/src/locales/fr/name/binary_gender.ts b/src/locales/fr/name/sex.ts similarity index 100% rename from src/locales/fr/name/binary_gender.ts rename to src/locales/fr/name/sex.ts diff --git a/src/locales/fr_CH/name/index.ts b/src/locales/fr_CH/name/index.ts index 64963579864..fb0bbc37f27 100644 --- a/src/locales/fr_CH/name/index.ts +++ b/src/locales/fr_CH/name/index.ts @@ -3,23 +3,23 @@ * Run 'pnpm run generate:locales' to update. */ import type { NameDefinitions } from '../../..'; -import binary_gender from './binary_gender'; import female_first_name from './female_first_name'; import first_name from './first_name'; import last_name from './last_name'; import male_first_name from './male_first_name'; import name_ from './name'; import prefix from './prefix'; +import sex from './sex'; import title from './title'; const name: NameDefinitions = { - binary_gender, female_first_name, first_name, last_name, male_first_name, name: name_, prefix, + sex, title, }; diff --git a/src/locales/fr_CH/name/binary_gender.ts b/src/locales/fr_CH/name/sex.ts similarity index 100% rename from src/locales/fr_CH/name/binary_gender.ts rename to src/locales/fr_CH/name/sex.ts diff --git a/src/locales/pl/name/binary_gender.ts b/src/locales/pl/name/binary_gender.ts deleted file mode 100644 index 6754a9f06eb..00000000000 --- a/src/locales/pl/name/binary_gender.ts +++ /dev/null @@ -1 +0,0 @@ -export default ['Kobieta', 'Mężczyzna']; diff --git a/src/locales/pl/name/index.ts b/src/locales/pl/name/index.ts index ea7c411a1a9..0d874207b13 100644 --- a/src/locales/pl/name/index.ts +++ b/src/locales/pl/name/index.ts @@ -3,7 +3,6 @@ * Run 'pnpm run generate:locales' to update. */ import type { NameDefinitions } from '../../..'; -import binary_gender from './binary_gender'; import female_first_name from './female_first_name'; import first_name from './first_name'; import gender from './gender'; @@ -11,10 +10,10 @@ import last_name from './last_name'; import male_first_name from './male_first_name'; import name_ from './name'; import prefix from './prefix'; +import sex from './sex'; import title from './title'; const name: NameDefinitions = { - binary_gender, female_first_name, first_name, gender, @@ -22,6 +21,7 @@ const name: NameDefinitions = { male_first_name, name: name_, prefix, + sex, title, }; diff --git a/src/locales/pl/name/sex.ts b/src/locales/pl/name/sex.ts new file mode 100644 index 00000000000..913a0aa8306 --- /dev/null +++ b/src/locales/pl/name/sex.ts @@ -0,0 +1 @@ +export default ['kobieta', 'mężczyzna']; diff --git a/src/locales/pt_BR/name/index.ts b/src/locales/pt_BR/name/index.ts index d4c0e73a1df..2565f4d5669 100644 --- a/src/locales/pt_BR/name/index.ts +++ b/src/locales/pt_BR/name/index.ts @@ -3,24 +3,24 @@ * Run 'pnpm run generate:locales' to update. */ import type { NameDefinitions } from '../../..'; -import binary_gender from './binary_gender'; import female_first_name from './female_first_name'; import first_name from './first_name'; import last_name from './last_name'; import male_first_name from './male_first_name'; import name_ from './name'; import prefix from './prefix'; +import sex from './sex'; import suffix from './suffix'; import title from './title'; const name: NameDefinitions = { - binary_gender, female_first_name, first_name, last_name, male_first_name, name: name_, prefix, + sex, suffix, title, }; diff --git a/src/locales/pt_BR/name/binary_gender.ts b/src/locales/pt_BR/name/sex.ts similarity index 100% rename from src/locales/pt_BR/name/binary_gender.ts rename to src/locales/pt_BR/name/sex.ts diff --git a/src/locales/ur/name/index.ts b/src/locales/ur/name/index.ts index d4c0e73a1df..2565f4d5669 100644 --- a/src/locales/ur/name/index.ts +++ b/src/locales/ur/name/index.ts @@ -3,24 +3,24 @@ * Run 'pnpm run generate:locales' to update. */ import type { NameDefinitions } from '../../..'; -import binary_gender from './binary_gender'; import female_first_name from './female_first_name'; import first_name from './first_name'; import last_name from './last_name'; import male_first_name from './male_first_name'; import name_ from './name'; import prefix from './prefix'; +import sex from './sex'; import suffix from './suffix'; import title from './title'; const name: NameDefinitions = { - binary_gender, female_first_name, first_name, last_name, male_first_name, name: name_, prefix, + sex, suffix, title, }; diff --git a/src/locales/ur/name/binary_gender.ts b/src/locales/ur/name/sex.ts similarity index 100% rename from src/locales/ur/name/binary_gender.ts rename to src/locales/ur/name/sex.ts diff --git a/src/modules/name/index.ts b/src/modules/name/index.ts index 0a67c382cda..b42de3db568 100644 --- a/src/modules/name/index.ts +++ b/src/modules/name/index.ts @@ -245,24 +245,45 @@ export class Name { } /** - * Return a random gender. + * Returns a random gender. * - * @param binary Whether to return only binary gender names. Defaults to `false`. + * @param binary (deprecated) Whether to return only binary gender names. Defaults to `false`. + * + * @see faker.name.sex() if you would like to generate binary-gender value * * @example * faker.name.gender() // 'Trans*Man' - * faker.name.gender(true) // 'Female' */ gender(binary?: boolean): string { if (binary) { - return this.faker.helpers.arrayElement( - this.faker.definitions.name.binary_gender - ); + deprecated({ + deprecated: 'faker.name.gender(true)', + proposed: 'faker.name.sex()', + since: '7.5', + until: '8.0', + }); + + return this.faker.name.sex(); } return this.faker.helpers.arrayElement(this.faker.definitions.name.gender); } + /** + * Returns a random sex. + * + * Output of this method is localised, so it should not be used to fill the parameter `sex` + * available in some other modules for example `faker.name.firstName()`. + * + * @see faker.name.gender() if you would like to generate gender related values. + * + * @example + * faker.name.sex() // 'female' + */ + sex(): string { + return this.faker.helpers.arrayElement(this.faker.definitions.name.sex); + } + /** * Returns a random name prefix. * diff --git a/test/__snapshots__/name.spec.ts.snap b/test/__snapshots__/name.spec.ts.snap index 39043915c7c..ed921dcdfe3 100644 --- a/test/__snapshots__/name.spec.ts.snap +++ b/test/__snapshots__/name.spec.ts.snap @@ -28,7 +28,7 @@ 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"`; +exports[`name > 42 > gender > with gender 1`] = `"female"`; exports[`name > 42 > jobArea 1`] = `"Identity"`; @@ -50,6 +50,10 @@ exports[`name > 42 > prefix > noArgs 1`] = `"Mrs."`; exports[`name > 42 > prefix > with gender 1`] = `"Mrs."`; +exports[`name > 42 > sex > noArgs 1`] = `"female"`; + +exports[`name > 42 > sex > with gender 1`] = `"female"`; + exports[`name > 42 > suffix > noArgs 1`] = `"III"`; exports[`name > 42 > suffix > with gender 1`] = `"III"`; @@ -82,7 +86,7 @@ exports[`name > 1211 > fullName > with sex 1`] = `"Patti Koch"`; exports[`name > 1211 > gender > noArgs 1`] = `"Trigender"`; -exports[`name > 1211 > gender > with gender 1`] = `"Male"`; +exports[`name > 1211 > gender > with gender 1`] = `"male"`; exports[`name > 1211 > jobArea 1`] = `"Factors"`; @@ -104,6 +108,10 @@ exports[`name > 1211 > prefix > noArgs 1`] = `"Dr."`; exports[`name > 1211 > prefix > with gender 1`] = `"Dr."`; +exports[`name > 1211 > sex > noArgs 1`] = `"male"`; + +exports[`name > 1211 > sex > with gender 1`] = `"male"`; + exports[`name > 1211 > suffix > noArgs 1`] = `"DVM"`; exports[`name > 1211 > suffix > with gender 1`] = `"DVM"`; @@ -136,7 +144,7 @@ exports[`name > 1337 > fullName > with sex 1`] = `"Esther Macejkovic"`; exports[`name > 1337 > gender > noArgs 1`] = `"Demigender"`; -exports[`name > 1337 > gender > with gender 1`] = `"Female"`; +exports[`name > 1337 > gender > with gender 1`] = `"female"`; exports[`name > 1337 > jobArea 1`] = `"Functionality"`; @@ -158,6 +166,10 @@ exports[`name > 1337 > prefix > noArgs 1`] = `"Mrs."`; exports[`name > 1337 > prefix > with gender 1`] = `"Mrs."`; +exports[`name > 1337 > sex > noArgs 1`] = `"female"`; + +exports[`name > 1337 > sex > with gender 1`] = `"female"`; + exports[`name > 1337 > suffix > noArgs 1`] = `"I"`; exports[`name > 1337 > suffix > with gender 1`] = `"I"`; diff --git a/test/name.spec.ts b/test/name.spec.ts index a8ef5687571..ad55e914933 100644 --- a/test/name.spec.ts +++ b/test/name.spec.ts @@ -19,6 +19,7 @@ describe('name', () => { 'middleName', 'gender', 'prefix', + 'sex', 'suffix' )((t) => t.it('noArgs').it('with gender', 'male')); @@ -346,7 +347,21 @@ describe('name', () => { const gender = faker.name.gender(true); expect(gender).toBeTypeOf('string'); - expect(faker.definitions.name.binary_gender).toContain(gender); + expect(faker.definitions.name.sex).toContain(gender); + }); + }); + + describe('sex()', () => { + beforeEach(() => { + faker.locale = 'en'; + faker.localeFallback = 'en'; + }); + + it('should return a sex', () => { + const sex = faker.name.sex(); + + expect(sex).toBeTypeOf('string'); + expect(faker.definitions.name.sex).toContain(sex); }); }); diff --git a/test/scripts/apidoc/examplesAndDeprecations.spec.ts b/test/scripts/apidoc/examplesAndDeprecations.spec.ts index 023ab77cc4b..2f457b4b33f 100644 --- a/test/scripts/apidoc/examplesAndDeprecations.spec.ts +++ b/test/scripts/apidoc/examplesAndDeprecations.spec.ts @@ -17,7 +17,7 @@ import { loadProject } from './utils'; /* * This test ensures, that every method * - has working examples - * - and running these does not log anything, unless the method is deprecated + * - and running these do not log anything, unless the method is deprecated */ const locales: Record = {