Skip to content

Commit

Permalink
feat(suffix): add name.suffix method
Browse files Browse the repository at this point in the history
+ Add name.suffix method in en and pt_BR
  • Loading branch information
samir-araujo committed Apr 10, 2020
1 parent 965637d commit de922b4
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const anotherName = faker.name.firstName(); // Random first name: Marilyne
- firstName
- lastName
- prefix
- suffix
- helpers
- getLocale
- randomArrayElement
Expand Down Expand Up @@ -188,7 +189,6 @@ const anotherName = faker.name.firstName(); // Random first name: Marilyne
- ronSwanson
- theOffice
- name
- suffix
- title
- phone
- phoneFormats
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 @@ -12,4 +12,8 @@ describe('Name', () => {
it('should have prefix module', () => {
expect(name).toHaveProperty('prefix');
});

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

export default { firstName, lastName, prefix };
export default { firstName, lastName, prefix, suffix };
26 changes: 26 additions & 0 deletions src/name/suffix/__tests__/suffix.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 suffix from '..';

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

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

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

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

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

expect(en).toContain(value);
});
});
10 changes: 10 additions & 0 deletions src/name/suffix/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 '../suffix/locales';
import randomArrayElement from '../../helpers/randomArrayElement';

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

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

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

it('should have pt_BR locale', () => {
expect(locales).toHaveProperty('pt_BR');
});
});
13 changes: 13 additions & 0 deletions src/name/suffix/locales/en/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default [
'Jr.',
'Sr.',
'I',
'II',
'III',
'IV',
'V',
'MD',
'DDS',
'PhD',
'DVM',
];
7 changes: 7 additions & 0 deletions src/name/suffix/locales/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { LocaleObject } from '../../../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/suffix/locales/pt_BR/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['Jr.', 'Neto', 'Filho'];

0 comments on commit de922b4

Please sign in to comment.