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

feat(name): extract sex generator from gender to sex #1168

Merged
merged 26 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0198cb0
feat: extract sex generator from name.gender to name.sex
hankucz Jul 19, 2022
398ff3e
test: add tests
hankucz Jul 19, 2022
5fe7664
chore(linting): disable `unbound-method` warnings (#1128)
xDivisionByZerox Jul 19, 2022
8b41348
refactor(name.findName): rename to fullName (#1127)
xDivisionByZerox Jul 19, 2022
a748bbc
feat(system.fileName): file extension count (#1101)
xDivisionByZerox Jul 19, 2022
7d360d7
chore(deps): update doc-dependencies (#1160)
renovate[bot] Jul 19, 2022
d71429d
Merge branch 'main' into binary-gender-2-sex
ST-DDT Jul 20, 2022
b4aba27
fix: restore params in doc
hankucz Jul 20, 2022
6b6c9b5
docs: deprecate param
hankucz Jul 20, 2022
09a6810
Merge branch 'main' into binary-gender-2-sex
hankucz Jul 26, 2022
b2f97a6
fix: tests
hankucz Jul 26, 2022
fc31ca9
Merge branch 'main' into binary-gender-2-sex
hankucz Aug 3, 2022
6df6e0e
chore: rename binary_gender to sex
hankucz Aug 3, 2022
8978205
chore: lowercase pl sex
hankucz Aug 3, 2022
1eaa327
chore: sex use only 2 values for en
hankucz Aug 3, 2022
6f1f5a2
chore: jsdoc
hankucz Aug 3, 2022
8df8923
docs: add @see
hankucz Aug 3, 2022
52d3133
docs: change order
hankucz Aug 3, 2022
7d5744a
fix: fixed tests
hankucz Aug 3, 2022
e145785
docs: do not use
hankucz Aug 3, 2022
edaf8c6
chore: add de
hankucz Aug 3, 2022
4fea09d
chore: apply feedback
hankucz Aug 18, 2022
da8e56e
chore: apply feedback
hankucz Aug 18, 2022
4665cd0
chore: apply feedback
hankucz Aug 18, 2022
be51489
Merge branch 'main' into binary-gender-2-sex
hankucz Aug 18, 2022
ca21e20
Merge branch 'main' into binary-gender-2-sex
Shinigami92 Aug 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/definitions/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { LocaleEntry } from './definitions';
*/
export type NameDefinitions = LocaleEntry<{
gender: string[];
binary_gender: string[];
sex: string[];
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved

prefix?: string[];
female_prefix?: string[];
Expand Down
1 change: 0 additions & 1 deletion src/locales/en/name/binary_gender.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/locales/en/name/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -29,6 +28,7 @@ const name: NameDefinitions = {
middle_name,
name: name_,
prefix,
sex,
suffix,
title,
};
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/name/sex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['female', 'male', 'non-binary'];
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions src/locales/fr/name/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/locales/fr_CH/name/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/locales/pt_BR/name/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/locales/ur/name/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
File renamed without changes.
25 changes: 19 additions & 6 deletions src/modules/name/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Faker } from '../..';
import { deprecated } from '../../internal/deprecated';

export enum Gender {
female = 'female',
Expand Down Expand Up @@ -180,22 +181,34 @@ export class Name {
/**
* Return a random gender.
hankucz marked this conversation as resolved.
Show resolved Hide resolved
*
* @param binary Whether to return only binary gender names. Defaults to `false`.
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
*
* @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()',
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
since: '7.4',
hankucz marked this conversation as resolved.
Show resolved Hide resolved
until: '8.0',
});

return this.faker.name.sex();
}

return this.faker.helpers.arrayElement(this.faker.definitions.name.gender);
}

/**
* Return a random sex.
hankucz marked this conversation as resolved.
Show resolved Hide resolved
hankucz marked this conversation as resolved.
Show resolved Hide resolved
*
* @example
* faker.name.sex() // 'female'
*/
sex(): string {
return this.faker.helpers.arrayElement(this.faker.definitions.name.sex);
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns a random name prefix.
*
Expand Down
6 changes: 6 additions & 0 deletions test/__snapshots__/name.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ exports[`name > seed: 42 > middleName() 1`] = `"Greer"`;

exports[`name > seed: 42 > prefix() 1`] = `"Mrs."`;

exports[`name > seed: 42 > sex() 1`] = `"male"`;

exports[`name > seed: 42 > suffix() 1`] = `"III"`;

exports[`name > seed: 1211 > findName() 1`] = `"Claude Trantow"`;
Expand All @@ -42,6 +44,8 @@ exports[`name > seed: 1211 > middleName() 1`] = `"Sawyer"`;

exports[`name > seed: 1211 > prefix() 1`] = `"Dr."`;

exports[`name > seed: 1211 > sex() 1`] = `"non-binary"`;

exports[`name > seed: 1211 > suffix() 1`] = `"DVM"`;

exports[`name > seed: 1337 > findName() 1`] = `"Leona Cronin"`;
Expand All @@ -64,4 +68,6 @@ exports[`name > seed: 1337 > middleName() 1`] = `"Dakota"`;

exports[`name > seed: 1337 > prefix() 1`] = `"Mrs."`;

exports[`name > seed: 1337 > sex() 1`] = `"female"`;

exports[`name > seed: 1337 > suffix() 1`] = `"I"`;
17 changes: 16 additions & 1 deletion test/name.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const functionNames = [
'findName',
'jobTitle',
'gender',
'sex',
'prefix',
'suffix',
'jobDescriptor',
Expand Down Expand Up @@ -243,7 +244,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);
});
});

Expand Down