Skip to content

Commit

Permalink
feat(name.prefix): add name.prefix method
Browse files Browse the repository at this point in the history
+ Introduces name.prefix method for en and pt_BR
  • Loading branch information
samir-araujo committed Apr 10, 2020
1 parent 86ebc94 commit 965637d
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 4 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const anotherName = faker.name.firstName(); // Random first name: Marilyne
- name
- firstName
- lastName
- prefix
- helpers
- getLocale
- randomArrayElement
Expand Down Expand Up @@ -187,9 +188,6 @@ const anotherName = faker.name.firstName(); // Random first name: Marilyne
- ronSwanson
- theOffice
- name
- firstName
- lastName
- prefix
- suffix
- title
- phone
Expand Down
4 changes: 4 additions & 0 deletions src/name/__tests__/name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ describe('Name', () => {
it('should have lastName module', () => {
expect(name).toHaveProperty('lastName');
});

it('should have prefix module', () => {
expect(name).toHaveProperty('prefix');
});
});
3 changes: 2 additions & 1 deletion src/name/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import firstName from './firstName';
import lastName from './lastName';
import prefix from './prefix';

export default { firstName, lastName };
export default { firstName, lastName, prefix };
26 changes: 26 additions & 0 deletions src/name/prefix/__tests__/prefix.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Locale } from '../../../types/locale';
import locales from '../locales';
import prefix from '..';

describe('Name | prefix', () => {
it(`should return a random prefix in ${Locale.EN} by default`, () => {
const value = prefix();
const { en } = locales;

expect(en).toContain(value);
});

it('should return a random prefix from given locale', () => {
const value = prefix(Locale.PT_BR);
const { pt_BR } = locales;

expect(pt_BR).toContain(value);
});

it(`should return a random prefix in ${Locale.EN} when given locale is not found`, () => {
const value = prefix(Locale.RU);
const { en } = locales;

expect(en).toContain(value);
});
});
10 changes: 10 additions & 0 deletions src/name/prefix/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Locale } from '../../types/locale';
import getLocale from '../../helpers/getLocale';
import locales from './locales';
import randomArrayElement from '../../helpers/randomArrayElement';

export default function prefix(selectedLocale?: Locale): string {
const collection = getLocale(locales, selectedLocale);

return randomArrayElement(collection);
}
11 changes: 11 additions & 0 deletions src/name/prefix/locales/__tests__/locales.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import locales from '..';

describe('Name | prefix | Locale', () => {
it('should have en locale', () => {
expect(locales).toHaveProperty('en');
});

it('should have pt_BR locale', () => {
expect(locales).toHaveProperty('pt_BR');
});
});
1 change: 1 addition & 0 deletions src/name/prefix/locales/en/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['Mr.', 'Mrs.', 'Ms.', 'Miss', 'Dr.'];
7 changes: 7 additions & 0 deletions src/name/prefix/locales/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { LocaleObject } from '../../../../lib/types/locale';
import en from './en/collection';
import pt_BR from './pt_BR/collection';

const locales: LocaleObject<string[]> = { en, pt_BR };

export default locales;
1 change: 1 addition & 0 deletions src/name/prefix/locales/pt_BR/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['Sr.', 'Sra.', 'Srta.', 'Dr.'];

0 comments on commit 965637d

Please sign in to comment.