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: add option to exclude emoji #2851

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/definitions/person.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { BioType } from '../modules/person';
import type { LocaleEntry } from './definitions';

/**
Expand Down Expand Up @@ -37,7 +38,7 @@ export type PersonDefinition = LocaleEntry<{
male_last_name_pattern: Array<{ value: string; weight: number }>;
female_last_name_pattern: Array<{ value: string; weight: number }>;

bio_pattern: string[];
bio_pattern: Record<BioType, string[]>;

job_descriptor: string[];
job_area: string[];
Expand Down
26 changes: 16 additions & 10 deletions src/locales/en/person/bio_pattern.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
export default [
'{{person.bio_part}}',
'{{person.bio_part}}, {{person.bio_part}}',
'{{person.bio_part}}, {{person.bio_part}}, {{person.bio_part}}',
'{{person.bio_part}}, {{person.bio_part}}, {{person.bio_part}} {{internet.emoji}}',
'{{word.noun}} {{person.bio_supporter}}',
'{{word.noun}} {{person.bio_supporter}} {{internet.emoji}}',
'{{word.noun}} {{person.bio_supporter}}, {{person.bio_part}}',
'{{word.noun}} {{person.bio_supporter}}, {{person.bio_part}} {{internet.emoji}}',
];
export default {
emoji: [
'{{person.bio_part}}, {{internet.emoji}}',
'{{person.bio_part}}, {{person.bio_part}}, {{internet.emoji}}',
'{{person.bio_part}}, {{person.bio_part}}, {{person.bio_part}} {{internet.emoji}}',
'{{word.noun}} {{person.bio_supporter}} {{internet.emoji}}',
'{{word.noun}} {{person.bio_supporter}}, {{person.bio_part}} {{internet.emoji}}',
],
text: [
'{{person.bio_part}}',
'{{person.bio_part}}, {{person.bio_part}}',
'{{person.bio_part}}, {{person.bio_part}}, {{person.bio_part}}',
'{{word.noun}} {{person.bio_supporter}}',
'{{word.noun}} {{person.bio_supporter}}, {{person.bio_part}}',
],
};
20 changes: 12 additions & 8 deletions src/locales/eo/person/bio_pattern.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export default [
'{{person.bio_part}}',
'{{person.bio_part}} {{internet.emoji}}',
'{{person.bio_part}}, {{person.bio_part}}',
'{{person.bio_part}}, {{person.bio_part}} {{internet.emoji}}',
'{{person.bio_part}}, {{person.bio_part}}, {{person.bio_part}}',
'{{person.bio_part}}, {{person.bio_part}}, {{person.bio_part}} {{internet.emoji}}',
];
export default {
emoji: [
'{{person.bio_part}} {{internet.emoji}}',
'{{person.bio_part}}, {{person.bio_part}} {{internet.emoji}}',
'{{person.bio_part}}, {{person.bio_part}}, {{person.bio_part}} {{internet.emoji}}',
],
text: [
'{{person.bio_part}}',
'{{person.bio_part}}, {{person.bio_part}}',
'{{person.bio_part}}, {{person.bio_part}}, {{person.bio_part}}',
],
};
24 changes: 14 additions & 10 deletions src/locales/zh_CN/person/bio_pattern.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
export default [
'{{person.bio_part}}',
'{{person.bio_part}},{{person.bio_part}}',
'{{person.bio_part}},{{person.bio_part}},{{person.bio_part}}',
'{{person.bio_part}},{{person.bio_part}},{{person.bio_part}}{{internet.emoji}}',
'{{word.noun}}{{person.bio_supporter}}',
'{{word.noun}}{{person.bio_supporter}}{{internet.emoji}}',
'{{word.noun}}{{person.bio_supporter}},{{person.bio_part}}',
'{{word.noun}}{{person.bio_supporter}},{{person.bio_part}}{{internet.emoji}}',
];
export default {
emoji: [
'{{person.bio_part}},{{person.bio_part}},{{person.bio_part}}{{internet.emoji}}',
'{{word.noun}}{{person.bio_supporter}}{{internet.emoji}}',
'{{word.noun}}{{person.bio_supporter}},{{person.bio_part}}{{internet.emoji}}',
],
text: [
'{{person.bio_part}}',
'{{person.bio_part}},{{person.bio_part}}',
'{{person.bio_part}},{{person.bio_part}},{{person.bio_part}}',
'{{word.noun}}{{person.bio_supporter}}',
'{{word.noun}}{{person.bio_supporter}},{{person.bio_part}}',
],
};
29 changes: 25 additions & 4 deletions src/modules/person/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export enum Sex {

export type SexType = `${Sex}`;

export type BioType = 'emoji' | 'text';

/**
* Select a definition based on given sex.
*
Expand Down Expand Up @@ -312,15 +314,34 @@ export class PersonModule extends ModuleBase {
/**
* Returns a random short biography
*
* @param options Options object.
* @param options.types A list of pattern types that can be generated. Possible values are `'emoji'`, `'text'`. By default, any pattern will be included.
*
* @example
* faker.person.bio() // 'oatmeal advocate, veteran 🐠'
* faker.person.bio({ types: ['text'] }) // 'oatmeal advocate, veteran'
*
* @since 8.0.0
*/
bio(): string {
const { bio_pattern } = this.faker.definitions.person;

return this.faker.helpers.fake(bio_pattern);
bio(
options: {
/**
* A list of the bio pattern types that should be used.
*
* @default Object.keys(faker.definitions.person.bio_pattern)
*/
types?: ReadonlyArray<BioType>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method options usally not provide extra or even replacement locale data. We usually allow users to control the method outcome through flags. In this case I could see such an option being named "includeEmojis" or "allowEmojis". We have similar options for:

} = {}
): string {
const {
types = Object.keys(
this.faker.definitions.person.bio_pattern
) as BioType[],
} = options;
const bioType = this.faker.helpers.arrayElement(types);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we simply get rid of '{{internet.emoji}}' here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe lets check the requirements and intentions behind including emojis in the next team meeting.

return this.faker.helpers.fake(
this.faker.definitions.person.bio_pattern[bioType]
);
}

/**
Expand Down
12 changes: 9 additions & 3 deletions test/modules/__snapshots__/person.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`person > 42 > bio 1`] = `"traveler, philosopher, model"`;
exports[`person > 42 > bio > noArgs 1`] = `"negotiation devotee, creator 💛"`;

exports[`person > 42 > bio > with options 1`] = `"traveler, philosopher, 🏩"`;

exports[`person > 42 > firstName > noArgs 1`] = `"Garnet"`;

Expand Down Expand Up @@ -50,7 +52,9 @@ exports[`person > 42 > suffix > with sex 1`] = `"III"`;

exports[`person > 42 > zodiacSign 1`] = `"Gemini"`;

exports[`person > 1211 > bio 1`] = `"decongestant supporter, parent 🎲"`;
exports[`person > 1211 > bio > noArgs 1`] = `"yogurt junkie, patriot"`;

exports[`person > 1211 > bio > with options 1`] = `"decongestant supporter, parent 🎲"`;

exports[`person > 1211 > firstName > noArgs 1`] = `"Tito"`;

Expand Down Expand Up @@ -100,7 +104,9 @@ exports[`person > 1211 > suffix > with sex 1`] = `"DVM"`;

exports[`person > 1211 > zodiacSign 1`] = `"Capricorn"`;

exports[`person > 1337 > bio 1`] = `"creator, engineer, friend"`;
exports[`person > 1337 > bio > noArgs 1`] = `"engineer, 🧇"`;

exports[`person > 1337 > bio > with options 1`] = `"creator, engineer, 🧇"`;

exports[`person > 1337 > firstName > noArgs 1`] = `"Devyn"`;

Expand Down
7 changes: 5 additions & 2 deletions test/modules/person.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ describe('person', () => {
'jobTitle',
'jobDescriptor',
'jobArea',
'jobType',
'bio'
'jobType'
);

t.describeEach(
Expand All @@ -39,6 +38,10 @@ describe('person', () => {
});

t.it('zodiacSign');

t.describe('bio', (t) => {
t.it('noArgs').it('with options', { types: ['emoji'] });
});
});

describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))(
Expand Down