Skip to content

Commit

Permalink
fix the avatar url in faker js
Browse files Browse the repository at this point in the history
  • Loading branch information
vedkribhu committed Jul 26, 2024
1 parent a175ec3 commit ec21a50
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion lib/superstring/dynamic-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,36 @@ var faker = require('@faker-js/faker/locale/en'),
'/var/yp'
],

/**
* Copied over from: https://github.com/faker-js/faker/blob/next/src/modules/image/index.ts#L27
* Generates a random avatar from GitHub.
*
* @example
* faker.image.avatarGitHub()
* // 'https://avatars.githubusercontent.com/u/97165289'
*
* @since 8.0.0
*/
avatarGitHub = () => {
return `https://avatars.githubusercontent.com/u/${faker.datatype.number({ min: 1, max: 1249 })}`;
},

/**
* Copied over from: https://github.com/faker-js/faker/blob/next/src/modules/image/index.ts#L27
* Generates a random avatar from
* `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar`.
*
* @example
* faker.image.avatarLegacy()
* // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/170.jpg'
*
* @since 8.0.0
*/
avatarLegacy = () => {
// eslint-disable-next-line max-len
return `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/${faker.datatype.number(1249)}.jpg`;
},

// generators for $random* variables
dynamicGenerators = {
$guid: {
Expand Down Expand Up @@ -371,7 +401,17 @@ var faker = require('@faker-js/faker/locale/en'),

$randomAvatarImage: {
description: 'A random avatar image',
generator: faker.image.avatar
generator: () => {
// We have overridden the avatar generator to be similar to current
// updated version of faker.js. We don't want to upgrade to the latest
// version of faker.js as it is significantly big in size.
const avatarMethod = faker.random.arrayElement([
avatarLegacy,
avatarGitHub
]);

return avatarMethod();
}
},
$randomImageUrl: {
description: 'A URL for a random image',
Expand Down

0 comments on commit ec21a50

Please sign in to comment.