From df5befde7ef9bcfdee70e7eabcd5ee07e363642c Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Sat, 19 Oct 2024 15:48:18 +0530 Subject: [PATCH 1/4] feat(animal): add petName method --- src/definitions/animal.ts | 1 + src/locales/en/animal/index.ts | 2 + src/locales/en/animal/pet_name.ts | 45 +++++++++++++++++++ src/modules/animal/index.ts | 14 ++++++ .../modules/__snapshots__/animal.spec.ts.snap | 6 +++ 5 files changed, 68 insertions(+) create mode 100644 src/locales/en/animal/pet_name.ts diff --git a/src/definitions/animal.ts b/src/definitions/animal.ts index d5d9550563e..afa86753c3f 100644 --- a/src/definitions/animal.ts +++ b/src/definitions/animal.ts @@ -19,4 +19,5 @@ export type AnimalDefinition = LocaleEntry<{ rodent: string[]; snake: string[]; type: string[]; + pet_name: string[]; }>; diff --git a/src/locales/en/animal/index.ts b/src/locales/en/animal/index.ts index f43813a04e9..7a28c5672b3 100644 --- a/src/locales/en/animal/index.ts +++ b/src/locales/en/animal/index.ts @@ -14,6 +14,7 @@ import fish from './fish'; import horse from './horse'; import insect from './insect'; import lion from './lion'; +import pet_name from './pet_name'; import rabbit from './rabbit'; import rodent from './rodent'; import snake from './snake'; @@ -31,6 +32,7 @@ const animal: AnimalDefinition = { horse, insect, lion, + pet_name, rabbit, rodent, snake, diff --git a/src/locales/en/animal/pet_name.ts b/src/locales/en/animal/pet_name.ts new file mode 100644 index 00000000000..6b40a36033a --- /dev/null +++ b/src/locales/en/animal/pet_name.ts @@ -0,0 +1,45 @@ +export default [ + 'Ace', + 'Archie', + 'Bailey', + 'Bandit', + 'Bear', + 'Bella', + 'Bentley', + 'Bruno', + 'Buddy', + 'Charlie', + 'Coco', + 'Cookie', + 'Cooper', + 'Daisy', + 'Dixie', + 'Finn', + 'Ginger', + 'Gracie', + 'Gus', + 'Hank', + 'Jack', + 'Jax', + 'Joey', + 'Kobe', + 'Leo', + 'Lola', + 'Louie', + 'Lucy', + 'Maggie', + 'Max', + 'Mia', + 'Milo', + 'Molly', + 'Murphey', + 'Nala', + 'Nova', + 'Ollie', + 'Oreo', + 'Rosie', + 'Scout', + 'Stella', + 'Teddy', + 'Tuffy', +]; diff --git a/src/modules/animal/index.ts b/src/modules/animal/index.ts index 5a885bbd739..802917f09df 100644 --- a/src/modules/animal/index.ts +++ b/src/modules/animal/index.ts @@ -72,6 +72,20 @@ export class AnimalModule extends ModuleBase { return this.faker.helpers.arrayElement(this.faker.definitions.animal.lion); } + /** + * Returns a random pet name. + * + * @example + * faker.animal.petName() // 'Coco' + * + * @since 5.5.0 + */ + petName(): string { + return this.faker.helpers.arrayElement( + this.faker.definitions.animal.pet_name + ); + } + /** * Returns a random cetacean species. * diff --git a/test/modules/__snapshots__/animal.spec.ts.snap b/test/modules/__snapshots__/animal.spec.ts.snap index f6ddbc3a2dc..d82999d4321 100644 --- a/test/modules/__snapshots__/animal.spec.ts.snap +++ b/test/modules/__snapshots__/animal.spec.ts.snap @@ -22,6 +22,8 @@ exports[`animal > 42 > insect 1`] = `"Gouty oak gall"`; exports[`animal > 42 > lion 1`] = `"Cape lion"`; +exports[`animal > 42 > petName 1`] = `"Ginger"`; + exports[`animal > 42 > rabbit 1`] = `"English Spot"`; exports[`animal > 42 > rodent 1`] = `"Famatina chinchilla rat"`; @@ -52,6 +54,8 @@ exports[`animal > 1211 > insect 1`] = `"Western paper wasp"`; exports[`animal > 1211 > lion 1`] = `"West African Lion"`; +exports[`animal > 1211 > petName 1`] = `"Scout"`; + exports[`animal > 1211 > rabbit 1`] = `"Silver Marten"`; exports[`animal > 1211 > rodent 1`] = `"Strong tuco-tuco"`; @@ -82,6 +86,8 @@ exports[`animal > 1337 > insect 1`] = `"Erythrina gall wasp"`; exports[`animal > 1337 > lion 1`] = `"Barbary Lion"`; +exports[`animal > 1337 > petName 1`] = `"Cookie"`; + exports[`animal > 1337 > rabbit 1`] = `"Cinnamon"`; exports[`animal > 1337 > rodent 1`] = `"Crested porcupine"`; From 5644bca58f56abe35f17162a82d0fe28a2df902c Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Sat, 19 Oct 2024 17:07:04 +0530 Subject: [PATCH 2/4] jsdocs change --- src/modules/animal/index.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/modules/animal/index.ts b/src/modules/animal/index.ts index 802917f09df..bb200a31c0a 100644 --- a/src/modules/animal/index.ts +++ b/src/modules/animal/index.ts @@ -72,20 +72,6 @@ export class AnimalModule extends ModuleBase { return this.faker.helpers.arrayElement(this.faker.definitions.animal.lion); } - /** - * Returns a random pet name. - * - * @example - * faker.animal.petName() // 'Coco' - * - * @since 5.5.0 - */ - petName(): string { - return this.faker.helpers.arrayElement( - this.faker.definitions.animal.pet_name - ); - } - /** * Returns a random cetacean species. * @@ -215,4 +201,18 @@ export class AnimalModule extends ModuleBase { type(): string { return this.faker.helpers.arrayElement(this.faker.definitions.animal.type); } + + /** + * Returns a random pet name. + * + * @example + * faker.animal.petName() // 'Coco' + * + * @since 9.2.0 + */ + petName(): string { + return this.faker.helpers.arrayElement( + this.faker.definitions.animal.pet_name + ); + } } From 8dc5975a6f2a2944c05a340572b4bf2a6fe03f1b Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Mon, 28 Oct 2024 18:26:20 +0530 Subject: [PATCH 3/4] Corrected animal.spec.ts --- test/modules/animal.spec.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/modules/animal.spec.ts b/test/modules/animal.spec.ts index 7ac332cbd4b..4fc95915533 100644 --- a/test/modules/animal.spec.ts +++ b/test/modules/animal.spec.ts @@ -22,7 +22,8 @@ describe('animal', () => { 'rabbit', 'rodent', 'snake', - 'type' + 'type', + 'petName' ); }); @@ -133,6 +134,13 @@ describe('animal', () => { expect(faker.definitions.animal.type).toContain(actual); }); }); + + describe('petName()', () => { + it('should return random value from type array', () => { + const actual = faker.animal.petName(); + expect(faker.definitions.animal.pet_name).toContain(actual); + }); + }); } ); }); From 8eae83ea4b60c869b2e63f6f4fe64c01921a3a52 Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Tue, 29 Oct 2024 17:23:00 +0530 Subject: [PATCH 4/4] Reviews incorporated --- src/locales/en/animal/pet_name.ts | 1 - test/modules/__snapshots__/animal.spec.ts.snap | 2 +- test/modules/animal.spec.ts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/locales/en/animal/pet_name.ts b/src/locales/en/animal/pet_name.ts index 6b40a36033a..acbc0f6034b 100644 --- a/src/locales/en/animal/pet_name.ts +++ b/src/locales/en/animal/pet_name.ts @@ -3,7 +3,6 @@ export default [ 'Archie', 'Bailey', 'Bandit', - 'Bear', 'Bella', 'Bentley', 'Bruno', diff --git a/test/modules/__snapshots__/animal.spec.ts.snap b/test/modules/__snapshots__/animal.spec.ts.snap index d82999d4321..ae25d4f2951 100644 --- a/test/modules/__snapshots__/animal.spec.ts.snap +++ b/test/modules/__snapshots__/animal.spec.ts.snap @@ -86,7 +86,7 @@ exports[`animal > 1337 > insect 1`] = `"Erythrina gall wasp"`; exports[`animal > 1337 > lion 1`] = `"Barbary Lion"`; -exports[`animal > 1337 > petName 1`] = `"Cookie"`; +exports[`animal > 1337 > petName 1`] = `"Cooper"`; exports[`animal > 1337 > rabbit 1`] = `"Cinnamon"`; diff --git a/test/modules/animal.spec.ts b/test/modules/animal.spec.ts index 4fc95915533..ff5767e260b 100644 --- a/test/modules/animal.spec.ts +++ b/test/modules/animal.spec.ts @@ -136,7 +136,7 @@ describe('animal', () => { }); describe('petName()', () => { - it('should return random value from type array', () => { + it('should return random value from pet name array', () => { const actual = faker.animal.petName(); expect(faker.definitions.animal.pet_name).toContain(actual); });