From fa41362e8b3629604a0259495f97bfa32f9ed1fa Mon Sep 17 00:00:00 2001 From: Vedanta Krishna Date: Fri, 26 Jul 2024 14:28:11 +0530 Subject: [PATCH] fix the avatar url in faker js --- lib/superstring/dynamic-variables.js | 42 +++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/superstring/dynamic-variables.js b/lib/superstring/dynamic-variables.js index aeff852b4..44637b6c3 100644 --- a/lib/superstring/dynamic-variables.js +++ b/lib/superstring/dynamic-variables.js @@ -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: { @@ -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',