Skip to content

Commit dfbf6c4

Browse files
authored
refactor(image): deprecate avatarLegacy (#3109)
1 parent f27f9c5 commit dfbf6c4

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/modules/image/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { deprecated } from '../../internal/deprecated';
12
import { ModuleBase } from '../../internal/module-base';
23

34
/**
@@ -24,12 +25,8 @@ export class ImageModule extends ModuleBase {
2425
* @since 2.0.1
2526
*/
2627
avatar(): string {
27-
const avatarMethod = this.faker.helpers.arrayElement([
28-
this.avatarLegacy,
29-
this.avatarGitHub,
30-
]);
31-
32-
return avatarMethod();
28+
// Add new avatar providers here, when adding a new one.
29+
return this.avatarGitHub();
3330
}
3431

3532
/**
@@ -55,9 +52,17 @@ export class ImageModule extends ModuleBase {
5552
* // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/170.jpg'
5653
*
5754
* @since 8.0.0
55+
*
56+
* @deprecated The links are no longer working. Use `avatar()` instead.
5857
*/
59-
// This implementation will change in the future when we tackle https://github.com/faker-js/faker/issues/465.
6058
avatarLegacy(): string {
59+
deprecated({
60+
deprecated: 'faker.image.avatarLegacy()',
61+
proposed: 'faker.image.avatar()',
62+
since: '9.0.1',
63+
until: '10.0.0',
64+
});
65+
6166
return `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/${this.faker.number.int(
6267
1249
6368
)}.jpg`;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`image > 42 > avatar 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/1188.jpg"`;
3+
exports[`image > 42 > avatar 1`] = `"https://avatars.githubusercontent.com/u/37454012"`;
44

55
exports[`image > 42 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/37454012"`;
66

@@ -76,7 +76,7 @@ exports[`image > 42 > urlPlaceholder > with width 1`] = `"https://via.placeholde
7676

7777
exports[`image > 42 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/8ead33/1ddf0f.webp?text=benevolentia%20attonbitus%20auctus"`;
7878

79-
exports[`image > 1211 > avatar 1`] = `"https://avatars.githubusercontent.com/u/89347165"`;
79+
exports[`image > 1211 > avatar 1`] = `"https://avatars.githubusercontent.com/u/92852016"`;
8080

8181
exports[`image > 1211 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/92852016"`;
8282

@@ -152,7 +152,7 @@ exports[`image > 1211 > urlPlaceholder > with width 1`] = `"https://via.placehol
152152

153153
exports[`image > 1211 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/ed4fef/a7fbae.webp?text=dapifer%20usque%20unde"`;
154154

155-
exports[`image > 1337 > avatar 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/198.jpg"`;
155+
exports[`image > 1337 > avatar 1`] = `"https://avatars.githubusercontent.com/u/26202467"`;
156156

157157
exports[`image > 1337 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/26202467"`;
158158

test/modules/image.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ describe('image', () => {
114114

115115
describe('avatarLegacy', () => {
116116
it('should return a random avatar url from cloudflare-ipfs', () => {
117+
// eslint-disable-next-line @typescript-eslint/no-deprecated
117118
const avatarUrl = faker.image.avatarLegacy();
118119

119120
expect(avatarUrl).toBeTypeOf('string');

0 commit comments

Comments
 (0)