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 internet.emoji #504

Merged
merged 26 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bc8d9b6
feat: add internet.emoji
hugoattal Feb 17, 2022
e2dcf98
fix: rebase
hugoattal Apr 8, 2022
8731d5c
feat: Add emojigroups type
hugoattal Apr 9, 2022
82cad3d
fix: Small fixes
hugoattal Apr 9, 2022
6badfaa
fix: singular emoji group
hugoattal Apr 9, 2022
24727ed
fix: Rename group to type
hugoattal Apr 10, 2022
28f13af
fix: Use emoji 13.0
hugoattal Apr 10, 2022
faba4db
fix: Fix type in emoji function
hugoattal Apr 10, 2022
e3fa94c
fix: Update src/internet.ts
hugoattal Apr 10, 2022
06a37b3
fix: Update tests
hugoattal Apr 10, 2022
0a04e5a
fix: Update src/definitions/internet.ts
hugoattal Apr 10, 2022
213ad44
fix: makes links homogeneous
hugoattal Apr 10, 2022
e551544
Merge branch 'main' into add-internet-emoji
ST-DDT Apr 10, 2022
14bdfef
fix: Update test/internet.spec.ts
hugoattal Apr 10, 2022
0052ba0
fix: move EmojiType out of definitions
hugoattal Apr 10, 2022
af8f73b
fix: use options as argument
hugoattal Apr 10, 2022
a6782d1
fix: typescript error
hugoattal Apr 10, 2022
194604e
fix: update options code
hugoattal Apr 10, 2022
cdb5922
fix: update emoji file + fix ts error
hugoattal Apr 10, 2022
51a29d3
fix: remove not fully qualified emojis
hugoattal Apr 16, 2022
b427618
fix: fix tests
hugoattal Apr 16, 2022
ab46439
fix: tests
hugoattal Apr 17, 2022
4e239d7
fix: update emoji list
hugoattal Apr 17, 2022
8f4d3e8
chore: format
Shinigami92 Apr 18, 2022
8173b49
Merge branch 'main' into add-internet-emoji
Shinigami92 Apr 18, 2022
976946e
Merge branch 'main' into add-internet-emoji
ST-DDT Apr 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
19 changes: 18 additions & 1 deletion src/definitions/internet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { allOf } from './utils';

export type EmojiGroups =
| 'smileys'
| 'body'
| 'person'
| 'nature'
| 'food'
| 'travel'
| 'activities'
| 'objects'
| 'symbols'
| 'flags';

/**
* The possible definitions related to internet stuff.
*/
Expand All @@ -16,6 +28,10 @@ export interface InternetDefinitions {
* Some free-mail domains used in that country (e.g. `gmail.de`).
*/
free_email: string[];
/**
* List of all fully-qualified emoji ordered by groups.
*/
emoji: Record<EmojiGroups, string[]>;
}

/**
Expand All @@ -24,5 +40,6 @@ export interface InternetDefinitions {
export const INTERNET = allOf<keyof InternetDefinitions>()(
'domain_suffix',
'example_email',
'free_email'
'free_email',
'emoji'
);
23 changes: 22 additions & 1 deletion src/internet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker, InternetDefinitions } from '.';
import * as random_ua from './utils/user-agent';

/**
Expand Down Expand Up @@ -426,4 +426,25 @@ export class Internet {
};
return _password(len, memorable, pattern, prefix);
}

/**
* Generates a random emoji.
*
* @param filters A list of the emoji groups that should be used.
*
* @example
* faker.internet.emoji() // '🥰'
* faker.internet.emoji(['food', 'nature']) // '🥐'
*/
emoji(filters?: Array<keyof InternetDefinitions['emoji']>): string {
filters =
filters ||
(Object.keys(this.faker.definitions.internet.emoji) as Array<
keyof InternetDefinitions['emoji']
>);
const group = this.faker.random.arrayElement(filters);
return this.faker.random.arrayElement(
this.faker.definitions.internet.emoji[group]
);
}
}
121 changes: 121 additions & 0 deletions src/locales/en/internet/emoji.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/locales/en/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import type { InternetDefinitions } from '../../..';
import avatar_uri from './avatar_uri';
import domain_suffix from './domain_suffix';
import emoji from './emoji';
import example_email from './example_email';
import free_email from './free_email';

const internet = {
avatar_uri,
domain_suffix,
emoji,
example_email,
free_email,
} as InternetDefinitions;
Expand Down
2 changes: 1 addition & 1 deletion src/locales/fa/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import domain_suffix from './domain_suffix';
import example_email from './example_email';
import free_email from './free_email';

const internet: InternetDefinitions = {
const internet: Partial<InternetDefinitions> = {
domain_suffix,
example_email,
free_email,
Expand Down
14 changes: 14 additions & 0 deletions test/internet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const seededRuns = [
color: '#30667a',
mac: '5c:f2:bc:99:27:21',
password: 'Dl2fkYYKLsZdepz',
emoji: '🦟',
},
},
{
Expand All @@ -50,6 +51,7 @@ const seededRuns = [
color: '#214814',
mac: '48:23:48:70:53:89',
password: '9V05TL7RY9fmECg',
emoji: '💇‍♂️',
},
},
{
Expand All @@ -74,6 +76,7 @@ const seededRuns = [
color: '#773a72',
mac: 'e7:ec:32:f0:a2:a3',
password: 'yLuj60b5iHB0bhn',
emoji: '🇮🇸',
},
},
];
Expand All @@ -98,6 +101,7 @@ const functionNames = [
'color',
'mac',
'password',
'emoji',
];

describe('internet', () => {
Expand Down Expand Up @@ -579,6 +583,16 @@ describe('internet', () => {
expect(password).satisfy(validator.isStrongPassword);
});
});

describe('emoji', () => {
it('should return a random emoji', () => {
const emoji = faker.internet.emoji();

expect(emoji).toBeTruthy();
expect(typeof emoji).toBe('string');
expect(emoji.length).toBeGreaterThanOrEqual(1);
});
});
}
});
});