Skip to content

Commit c02beea

Browse files
authored
feat(animal): add petName method (#3196)
1 parent 081a795 commit c02beea

6 files changed

Lines changed: 76 additions & 1 deletion

File tree

src/definitions/animal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export type AnimalDefinition = LocaleEntry<{
1919
rodent: string[];
2020
snake: string[];
2121
type: string[];
22+
pet_name: string[];
2223
}>;

src/locales/en/animal/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import fish from './fish';
1414
import horse from './horse';
1515
import insect from './insect';
1616
import lion from './lion';
17+
import pet_name from './pet_name';
1718
import rabbit from './rabbit';
1819
import rodent from './rodent';
1920
import snake from './snake';
@@ -31,6 +32,7 @@ const animal: AnimalDefinition = {
3132
horse,
3233
insect,
3334
lion,
35+
pet_name,
3436
rabbit,
3537
rodent,
3638
snake,

src/locales/en/animal/pet_name.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
export default [
2+
'Ace',
3+
'Archie',
4+
'Bailey',
5+
'Bandit',
6+
'Bella',
7+
'Bentley',
8+
'Bruno',
9+
'Buddy',
10+
'Charlie',
11+
'Coco',
12+
'Cookie',
13+
'Cooper',
14+
'Daisy',
15+
'Dixie',
16+
'Finn',
17+
'Ginger',
18+
'Gracie',
19+
'Gus',
20+
'Hank',
21+
'Jack',
22+
'Jax',
23+
'Joey',
24+
'Kobe',
25+
'Leo',
26+
'Lola',
27+
'Louie',
28+
'Lucy',
29+
'Maggie',
30+
'Max',
31+
'Mia',
32+
'Milo',
33+
'Molly',
34+
'Murphey',
35+
'Nala',
36+
'Nova',
37+
'Ollie',
38+
'Oreo',
39+
'Rosie',
40+
'Scout',
41+
'Stella',
42+
'Teddy',
43+
'Tuffy',
44+
];

src/modules/animal/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,18 @@ export class AnimalModule extends ModuleBase {
201201
type(): string {
202202
return this.faker.helpers.arrayElement(this.faker.definitions.animal.type);
203203
}
204+
205+
/**
206+
* Returns a random pet name.
207+
*
208+
* @example
209+
* faker.animal.petName() // 'Coco'
210+
*
211+
* @since 9.2.0
212+
*/
213+
petName(): string {
214+
return this.faker.helpers.arrayElement(
215+
this.faker.definitions.animal.pet_name
216+
);
217+
}
204218
}

test/modules/__snapshots__/animal.spec.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ exports[`animal > 42 > insect 1`] = `"Gouty oak gall"`;
2222

2323
exports[`animal > 42 > lion 1`] = `"Cape lion"`;
2424

25+
exports[`animal > 42 > petName 1`] = `"Ginger"`;
26+
2527
exports[`animal > 42 > rabbit 1`] = `"English Spot"`;
2628

2729
exports[`animal > 42 > rodent 1`] = `"Famatina chinchilla rat"`;
@@ -52,6 +54,8 @@ exports[`animal > 1211 > insect 1`] = `"Western paper wasp"`;
5254

5355
exports[`animal > 1211 > lion 1`] = `"West African Lion"`;
5456

57+
exports[`animal > 1211 > petName 1`] = `"Scout"`;
58+
5559
exports[`animal > 1211 > rabbit 1`] = `"Silver Marten"`;
5660

5761
exports[`animal > 1211 > rodent 1`] = `"Strong tuco-tuco"`;
@@ -82,6 +86,8 @@ exports[`animal > 1337 > insect 1`] = `"Erythrina gall wasp"`;
8286

8387
exports[`animal > 1337 > lion 1`] = `"Barbary Lion"`;
8488

89+
exports[`animal > 1337 > petName 1`] = `"Cooper"`;
90+
8591
exports[`animal > 1337 > rabbit 1`] = `"Cinnamon"`;
8692

8793
exports[`animal > 1337 > rodent 1`] = `"Crested porcupine"`;

test/modules/animal.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ describe('animal', () => {
2222
'rabbit',
2323
'rodent',
2424
'snake',
25-
'type'
25+
'type',
26+
'petName'
2627
);
2728
});
2829

@@ -133,6 +134,13 @@ describe('animal', () => {
133134
expect(faker.definitions.animal.type).toContain(actual);
134135
});
135136
});
137+
138+
describe('petName()', () => {
139+
it('should return random value from pet name array', () => {
140+
const actual = faker.animal.petName();
141+
expect(faker.definitions.animal.pet_name).toContain(actual);
142+
});
143+
});
136144
}
137145
);
138146
});

0 commit comments

Comments
 (0)