From 9530d27967b9d63eed425eb586aaee3670705fba Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Sat, 21 Sep 2024 09:41:16 +0700 Subject: [PATCH 01/25] feat(image): Add AI-generated avatars --- src/modules/image/index.ts | 36 ++++++++++++++++++- test/modules/__snapshots__/image.spec.ts.snap | 12 +++++-- test/modules/image.spec.ts | 12 ++++++- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 93a0adf978c..a5d27a1b730 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -1,5 +1,6 @@ import { deprecated } from '../../internal/deprecated'; import { ModuleBase } from '../../internal/module-base'; +import type { SexType } from '../person'; /** * Module to generate images. @@ -26,7 +27,11 @@ export class ImageModule extends ModuleBase { */ avatar(): string { // Add new avatar providers here, when adding a new one. - return this.avatarGitHub(); + const avatarMethod = this.faker.helpers.arrayElement([ + this.avatarAI, + this.avatarGitHub, + ]); + return avatarMethod(); } /** @@ -44,6 +49,35 @@ export class ImageModule extends ModuleBase { )}`; } + /** + * Generates a random avatar generated by AI. These are currently images of people which were generated by Stable Diffusion 3. The image URLs are served via the JSDelivr CDN and subject to their [terms of use](https://www.jsdelivr.com/terms). + * + * @param options Options for generating an AI avatar. + * @param options.sex The sex of the person for the avatar. Can be 'female' or 'male'. If not provided, defaults to a random selection. + * + * @example + * faker.image.avatarAI() + * // 'https://cdn.jsdelivr.net/.../female/32.jpg' + * faker.image.avatarAI({ sex: 'male' }) + * // 'https://cdn.jsdelivr.net/.../male/32.jpg' + * + * @since 9.1.0 + */ + avatarAI(options?: { + /** + * The sex of the person for the avatar. + * Can be 'female' or 'male'. + * If not provided, defaults to a random selection. + */ + sex?: SexType; + }): string { + const type = options?.sex ?? this.faker.person.sexType(); + // FIXME: This should be replaced by the final CDN url, presumably something like: 'https://cdn.jsdelivr.net/gh/faker-js/faker-media/avatars_ai' + const baseURL = + 'https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt'; + return `${baseURL}/${type}/${this.faker.number.int({ min: 1, max: 50 })}.jpg`; + } + /** * Generates a random avatar from `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar`. * diff --git a/test/modules/__snapshots__/image.spec.ts.snap b/test/modules/__snapshots__/image.spec.ts.snap index dac7d0783c4..a0f163cd3f6 100644 --- a/test/modules/__snapshots__/image.spec.ts.snap +++ b/test/modules/__snapshots__/image.spec.ts.snap @@ -1,6 +1,8 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`image > 42 > avatar 1`] = `"https://avatars.githubusercontent.com/u/37454012"`; +exports[`image > 42 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/male/37.jpg"`; + +exports[`image > 42 > avatarAI 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/48.jpg"`; exports[`image > 42 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/37454012"`; @@ -76,7 +78,9 @@ exports[`image > 42 > urlPlaceholder > with width 1`] = `"https://via.placeholde exports[`image > 42 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/8ead33/1ddf0f.webp?text=benevolentia%20attonbitus%20auctus"`; -exports[`image > 1211 > avatar 1`] = `"https://avatars.githubusercontent.com/u/92852016"`; +exports[`image > 1211 > avatar 1`] = `"https://avatars.githubusercontent.com/u/89347165"`; + +exports[`image > 1211 > avatarAI 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/male/45.jpg"`; exports[`image > 1211 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/92852016"`; @@ -152,7 +156,9 @@ exports[`image > 1211 > urlPlaceholder > with width 1`] = `"https://via.placehol exports[`image > 1211 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/ed4fef/a7fbae.webp?text=dapifer%20usque%20unde"`; -exports[`image > 1337 > avatar 1`] = `"https://avatars.githubusercontent.com/u/26202467"`; +exports[`image > 1337 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/14.jpg"`; + +exports[`image > 1337 > avatarAI 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/8.jpg"`; exports[`image > 1337 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/26202467"`; diff --git a/test/modules/image.spec.ts b/test/modules/image.spec.ts index 8624a9650ff..1bfabc0a89d 100644 --- a/test/modules/image.spec.ts +++ b/test/modules/image.spec.ts @@ -5,7 +5,7 @@ import { seededTests } from '../support/seeded-runs'; describe('image', () => { seededTests(faker, 'image', (t) => { - t.itEach('avatar', 'avatarGitHub', 'avatarLegacy'); + t.itEach('avatar', 'avatarGitHub', 'avatarLegacy', 'avatarAI'); t.describe('url', (t) => { t.it('noArgs') @@ -124,6 +124,16 @@ describe('image', () => { }); }); + describe('avatarAI', () => { + it('should return a random avatar url from AI', () => { + const avatarUrl = faker.image.avatarAI(); + + expect(avatarUrl).toBeTypeOf('string'); + expect(avatarUrl).toMatch(/^https:\/\/cdn\.jsdelivr\.net\/.*\.jpg$/); + expect(() => new URL(avatarUrl)).not.toThrow(); + }); + }); + describe('url', () => { it('should return a random image url', () => { const imageUrl = faker.image.url(); From 2bb43b9427604b9a61effbebdbb7ef6588d5e309 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Sat, 21 Sep 2024 09:54:49 +0700 Subject: [PATCH 02/25] fix tests --- test/modules/__snapshots__/image.spec.ts.snap | 12 +++++++++--- test/modules/image.spec.ts | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/test/modules/__snapshots__/image.spec.ts.snap b/test/modules/__snapshots__/image.spec.ts.snap index a0f163cd3f6..e4672f281fb 100644 --- a/test/modules/__snapshots__/image.spec.ts.snap +++ b/test/modules/__snapshots__/image.spec.ts.snap @@ -2,7 +2,9 @@ exports[`image > 42 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/male/37.jpg"`; -exports[`image > 42 > avatarAI 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/48.jpg"`; +exports[`image > 42 > avatarAI > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/48.jpg"`; + +exports[`image > 42 > avatarAI > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/19.jpg"`; exports[`image > 42 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/37454012"`; @@ -80,7 +82,9 @@ exports[`image > 42 > urlPlaceholder > with width and height 1`] = `"https://via exports[`image > 1211 > avatar 1`] = `"https://avatars.githubusercontent.com/u/89347165"`; -exports[`image > 1211 > avatarAI 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/male/45.jpg"`; +exports[`image > 1211 > avatarAI > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/male/45.jpg"`; + +exports[`image > 1211 > avatarAI > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/47.jpg"`; exports[`image > 1211 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/92852016"`; @@ -158,7 +162,9 @@ exports[`image > 1211 > urlPlaceholder > with width and height 1`] = `"https://v exports[`image > 1337 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/14.jpg"`; -exports[`image > 1337 > avatarAI 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/8.jpg"`; +exports[`image > 1337 > avatarAI > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/8.jpg"`; + +exports[`image > 1337 > avatarAI > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/14.jpg"`; exports[`image > 1337 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/26202467"`; diff --git a/test/modules/image.spec.ts b/test/modules/image.spec.ts index 1bfabc0a89d..f95568f4215 100644 --- a/test/modules/image.spec.ts +++ b/test/modules/image.spec.ts @@ -5,7 +5,7 @@ import { seededTests } from '../support/seeded-runs'; describe('image', () => { seededTests(faker, 'image', (t) => { - t.itEach('avatar', 'avatarGitHub', 'avatarLegacy', 'avatarAI'); + t.itEach('avatar', 'avatarGitHub', 'avatarLegacy'); t.describe('url', (t) => { t.it('noArgs') @@ -89,6 +89,10 @@ describe('image', () => { type: 'svg-uri', }); }); + + t.describe('avatarAI', (t) => { + t.it('noArgs').it('with sex', { sex: 'female' }); + }); }); describe('avatar', () => { From c35923507af896718aa5d53dc98875fa86687c31 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Mon, 3 Feb 2025 17:28:03 +0700 Subject: [PATCH 03/25] update to personPortrait and new URIs --- src/modules/image/index.ts | 26 +++++++----- test/modules/__snapshots__/image.spec.ts.snap | 40 ++++++++++++------- test/modules/image.spec.ts | 20 ++++++---- .../verify-jsdoc-tags.spec.ts.snap | 1 + 4 files changed, 57 insertions(+), 30 deletions(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 7f3552051c3..19212844986 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -29,7 +29,7 @@ export class ImageModule extends ModuleBase { avatar(): string { // Add new avatar providers here, when adding a new one. const avatarMethod = this.faker.helpers.arrayElement([ - this.avatarAI, + this.personPortrait, this.avatarGitHub, ]); return avatarMethod(); @@ -55,28 +55,36 @@ export class ImageModule extends ModuleBase { * * @param options Options for generating an AI avatar. * @param options.sex The sex of the person for the avatar. Can be 'female' or 'male'. If not provided, defaults to a random selection. + * @param options.size The size of the image. Can be 512, 256, 128, 64, 32 or 16. If not provided, defaults to 512. * * @example - * faker.image.avatarAI() - * // 'https://cdn.jsdelivr.net/.../female/32.jpg' - * faker.image.avatarAI({ sex: 'male' }) - * // 'https://cdn.jsdelivr.net/.../male/32.jpg' + * faker.image.personPortrait() + * // 'https://cdn.jsdelivr.net/.../female/512/57.jpg' + * faker.image.personPortrait({ sex: 'male', size:'128' }) + * // 'https://cdn.jsdelivr.net/.../male/128/27.jpg' * * @since 9.1.0 */ - avatarAI(options?: { + personPortrait(options?: { /** * The sex of the person for the avatar. * Can be 'female' or 'male'. * If not provided, defaults to a random selection. */ sex?: SexType; + /** + * The size of the image. + * Can be 512, 256, 128, 64, 32 or 16. + * If not provided, defaults to 512. + */ + size?: 512 | 256 | 128 | 64 | 32 | 16; }): string { const type = options?.sex ?? this.faker.person.sexType(); - // FIXME: This should be replaced by the final CDN url, presumably something like: 'https://cdn.jsdelivr.net/gh/faker-js/faker-media/avatars_ai' + const size = options?.size ?? 512; + // FIXME: This should be replaced by the final CDN url, presumably something like: 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait' const baseURL = - 'https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt'; - return `${baseURL}/${type}/${this.faker.number.int({ min: 1, max: 50 })}.jpg`; + 'https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images'; + return `${baseURL}/${type}/${size}/${this.faker.number.int({ min: 0, max: 99 })}.jpg`; } /** diff --git a/test/modules/__snapshots__/image.spec.ts.snap b/test/modules/__snapshots__/image.spec.ts.snap index 8d951532c8f..d07254c4766 100644 --- a/test/modules/__snapshots__/image.spec.ts.snap +++ b/test/modules/__snapshots__/image.spec.ts.snap @@ -1,10 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`image > 42 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/male/37.jpg"`; - -exports[`image > 42 > avatarAI > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/48.jpg"`; - -exports[`image > 42 > avatarAI > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/19.jpg"`; +exports[`image > 42 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/512/73.jpg"`; exports[`image > 42 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/37454012"`; @@ -26,6 +22,14 @@ exports[`image > 42 > dataUri > with width 1`] = `"data:image/svg+xml;base64,PHN exports[`image > 42 > dataUri > with width and height 1`] = `"data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22%238ead33%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2264%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E128x128%3C%2Ftext%3E%3C%2Fsvg%3E"`; +exports[`image > 42 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/95.jpg"`; + +exports[`image > 42 > personPortrait > with all options 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/128/37.jpg"`; + +exports[`image > 42 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/37.jpg"`; + +exports[`image > 42 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/256/37.jpg"`; + exports[`image > 42 > url > noArgs 1`] = `"https://picsum.photos/seed/993RBH1Y/1498/3802"`; exports[`image > 42 > url > with height 1`] = `"https://picsum.photos/seed/B993RBH1Y/1498/128"`; @@ -82,10 +86,6 @@ exports[`image > 42 > urlPlaceholder > with width and height 1`] = `"https://via exports[`image > 1211 > avatar 1`] = `"https://avatars.githubusercontent.com/u/89347165"`; -exports[`image > 1211 > avatarAI > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/male/45.jpg"`; - -exports[`image > 1211 > avatarAI > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/47.jpg"`; - exports[`image > 1211 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/92852016"`; exports[`image > 1211 > avatarLegacy 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/1160.jpg"`; @@ -106,6 +106,14 @@ exports[`image > 1211 > dataUri > with width 1`] = `"data:image/svg+xml;charset= exports[`image > 1211 > dataUri > with width and height 1`] = `"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgYmFzZVByb2ZpbGU9ImZ1bGwiIHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4Ij48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZWQ0ZmVmIi8+PHRleHQgeD0iNjQiIHk9IjY0IiBmb250LXNpemU9IjIwIiBhbGlnbm1lbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZmlsbD0id2hpdGUiPjEyOHgxMjg8L3RleHQ+PC9zdmc+"`; +exports[`image > 1211 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/512/89.jpg"`; + +exports[`image > 1211 > personPortrait > with all options 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/128/92.jpg"`; + +exports[`image > 1211 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/92.jpg"`; + +exports[`image > 1211 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/256/92.jpg"`; + exports[`image > 1211 > url > noArgs 1`] = `"https://loremflickr.com/3714/3573?lock=8982492793493979"`; exports[`image > 1211 > url > with height 1`] = `"https://picsum.photos/seed/ZFGLlH/3714/128"`; @@ -160,11 +168,7 @@ exports[`image > 1211 > urlPlaceholder > with width 1`] = `"https://via.placehol exports[`image > 1211 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/ed4fef/a7fbae.webp?text=dapifer%20usque%20unde"`; -exports[`image > 1337 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/14.jpg"`; - -exports[`image > 1337 > avatarAI > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/8.jpg"`; - -exports[`image > 1337 > avatarAI > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/sd3-avatars@country-prompt/female/14.jpg"`; +exports[`image > 1337 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/27.jpg"`; exports[`image > 1337 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/26202467"`; @@ -186,6 +190,14 @@ exports[`image > 1337 > dataUri > with width 1`] = `"data:image/svg+xml;base64,P exports[`image > 1337 > dataUri > with width and height 1`] = `"data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22%23536a7b%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2264%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E128x128%3C%2Ftext%3E%3C%2Fsvg%3E"`; +exports[`image > 1337 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/15.jpg"`; + +exports[`image > 1337 > personPortrait > with all options 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/128/26.jpg"`; + +exports[`image > 1337 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/26.jpg"`; + +exports[`image > 1337 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/256/26.jpg"`; + exports[`image > 1337 > url > noArgs 1`] = `"https://loremflickr.com/1048/635?lock=4137158724208997"`; exports[`image > 1337 > url > with height 1`] = `"https://loremflickr.com/1048/128?lock=2505140979113303"`; diff --git a/test/modules/image.spec.ts b/test/modules/image.spec.ts index 4118e83f752..fbae18638c8 100644 --- a/test/modules/image.spec.ts +++ b/test/modules/image.spec.ts @@ -109,8 +109,14 @@ describe('image', () => { }); }); - t.describe('avatarAI', (t) => { - t.it('noArgs').it('with sex', { sex: 'female' }); + t.describe('personPortrait', (t) => { + t.it('noArgs') + .it('with sex', { sex: 'female' }) + .it('with sex and size', { sex: 'male', size: 256 }) + .it('with all options', { + sex: 'female', + size: 128, + }); }); }); @@ -148,13 +154,13 @@ describe('image', () => { }); }); - describe('avatarAI', () => { + describe('personPortrait', () => { it('should return a random avatar url from AI', () => { - const avatarUrl = faker.image.avatarAI(); + const imageUrl = faker.image.personPortrait(); - expect(avatarUrl).toBeTypeOf('string'); - expect(avatarUrl).toMatch(/^https:\/\/cdn\.jsdelivr\.net\/.*\.jpg$/); - expect(() => new URL(avatarUrl)).not.toThrow(); + expect(imageUrl).toBeTypeOf('string'); + expect(imageUrl).toMatch(/^https:\/\/cdn\.jsdelivr\.net\/.*\.jpg$/); + expect(() => new URL(imageUrl)).not.toThrow(); }); }); diff --git a/test/scripts/apidocs/__snapshots__/verify-jsdoc-tags.spec.ts.snap b/test/scripts/apidocs/__snapshots__/verify-jsdoc-tags.spec.ts.snap index c13b2811a53..07983094b8c 100644 --- a/test/scripts/apidocs/__snapshots__/verify-jsdoc-tags.spec.ts.snap +++ b/test/scripts/apidocs/__snapshots__/verify-jsdoc-tags.spec.ts.snap @@ -243,6 +243,7 @@ exports[`check docs completeness > all modules and methods are present 1`] = ` "avatarGitHub", "avatarLegacy", "dataUri", + "personPortrait", "url", "urlLoremFlickr", "urlPicsumPhotos", From 895d6533aad0e2d2327fb1804e526e377fa6d98f Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Tue, 4 Feb 2025 08:10:56 +0700 Subject: [PATCH 04/25] bump since value --- src/modules/image/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 19212844986..cbf83dea912 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -63,7 +63,7 @@ export class ImageModule extends ModuleBase { * faker.image.personPortrait({ sex: 'male', size:'128' }) * // 'https://cdn.jsdelivr.net/.../male/128/27.jpg' * - * @since 9.1.0 + * @since 9.5.0 */ personPortrait(options?: { /** From acfd5878ca9c7a2498df6da053f324e7c46d3a5f Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Tue, 4 Feb 2025 08:11:03 +0700 Subject: [PATCH 05/25] add this to the weekly url availability checks: --- test/integration/modules/image.spec.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/integration/modules/image.spec.ts b/test/integration/modules/image.spec.ts index 611317c610b..5ec9e34bd33 100644 --- a/test/integration/modules/image.spec.ts +++ b/test/integration/modules/image.spec.ts @@ -74,6 +74,13 @@ describe('image', () => { }); }); + describe('personPortrait', () => { + it('should return a random asset url', async () => { + const actual = faker.image.personPortrait(); + await assertWorkingUrl(actual); + }); + }); + describe('url', () => { it('should return a random image url', async () => { const actual = faker.image.url(); From 3438d59f88c624e3b427b9410abed34d922e5b7e Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Tue, 4 Feb 2025 08:56:35 +0700 Subject: [PATCH 06/25] new test --- test/modules/__snapshots__/image.spec.ts.snap | 12 ++++++------ test/modules/image.spec.ts | 7 ++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/test/modules/__snapshots__/image.spec.ts.snap b/test/modules/__snapshots__/image.spec.ts.snap index d07254c4766..44cc836eed9 100644 --- a/test/modules/__snapshots__/image.spec.ts.snap +++ b/test/modules/__snapshots__/image.spec.ts.snap @@ -24,12 +24,12 @@ exports[`image > 42 > dataUri > with width and height 1`] = `"data:image/svg+xml exports[`image > 42 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/95.jpg"`; -exports[`image > 42 > personPortrait > with all options 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/128/37.jpg"`; - exports[`image > 42 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/37.jpg"`; exports[`image > 42 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/256/37.jpg"`; +exports[`image > 42 > personPortrait > with size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/128/95.jpg"`; + exports[`image > 42 > url > noArgs 1`] = `"https://picsum.photos/seed/993RBH1Y/1498/3802"`; exports[`image > 42 > url > with height 1`] = `"https://picsum.photos/seed/B993RBH1Y/1498/128"`; @@ -108,12 +108,12 @@ exports[`image > 1211 > dataUri > with width and height 1`] = `"data:image/svg+x exports[`image > 1211 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/512/89.jpg"`; -exports[`image > 1211 > personPortrait > with all options 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/128/92.jpg"`; - exports[`image > 1211 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/92.jpg"`; exports[`image > 1211 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/256/92.jpg"`; +exports[`image > 1211 > personPortrait > with size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/128/89.jpg"`; + exports[`image > 1211 > url > noArgs 1`] = `"https://loremflickr.com/3714/3573?lock=8982492793493979"`; exports[`image > 1211 > url > with height 1`] = `"https://picsum.photos/seed/ZFGLlH/3714/128"`; @@ -192,12 +192,12 @@ exports[`image > 1337 > dataUri > with width and height 1`] = `"data:image/svg+x exports[`image > 1337 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/15.jpg"`; -exports[`image > 1337 > personPortrait > with all options 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/128/26.jpg"`; - exports[`image > 1337 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/26.jpg"`; exports[`image > 1337 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/256/26.jpg"`; +exports[`image > 1337 > personPortrait > with size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/128/15.jpg"`; + exports[`image > 1337 > url > noArgs 1`] = `"https://loremflickr.com/1048/635?lock=4137158724208997"`; exports[`image > 1337 > url > with height 1`] = `"https://loremflickr.com/1048/128?lock=2505140979113303"`; diff --git a/test/modules/image.spec.ts b/test/modules/image.spec.ts index fbae18638c8..0e891ee45cd 100644 --- a/test/modules/image.spec.ts +++ b/test/modules/image.spec.ts @@ -112,11 +112,8 @@ describe('image', () => { t.describe('personPortrait', (t) => { t.it('noArgs') .it('with sex', { sex: 'female' }) - .it('with sex and size', { sex: 'male', size: 256 }) - .it('with all options', { - sex: 'female', - size: 128, - }); + .it('with size', { size: 128 }) + .it('with sex and size', { sex: 'male', size: 256 }); }); }); From 6b2b0b8ea78c758416250afe145b811af52a24e5 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Tue, 4 Feb 2025 08:57:43 +0700 Subject: [PATCH 07/25] remove 16px size --- src/modules/image/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index cbf83dea912..836752c6f08 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -74,10 +74,10 @@ export class ImageModule extends ModuleBase { sex?: SexType; /** * The size of the image. - * Can be 512, 256, 128, 64, 32 or 16. + * Can be 512, 256, 128, 64 or 32. * If not provided, defaults to 512. */ - size?: 512 | 256 | 128 | 64 | 32 | 16; + size?: 512 | 256 | 128 | 64 | 32; }): string { const type = options?.sex ?? this.faker.person.sexType(); const size = options?.size ?? 512; From b726bb88bc0f12ed22b2697f0ba88631418fd35c Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Tue, 4 Feb 2025 09:04:53 +0700 Subject: [PATCH 08/25] update docs --- src/modules/image/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 836752c6f08..c918bb2372b 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -12,7 +12,7 @@ import type { SexType } from '../person'; * * For a random placeholder image containing only solid color and text, use [`urlPlaceholder()`](https://fakerjs.dev/api/image.html#urlplaceholder) (uses a third-party service) or [`dataUri()`](https://fakerjs.dev/api/image.html#datauri) (returns a SVG string). * - * For a random user avatar image, use [`avatar()`](https://fakerjs.dev/api/image.html#avatar). + * For a random user avatar image, use [`avatar()`](https://fakerjs.dev/api/image.html#avatar), or [`personPortrait()`](https://fakerjs.dev/api/image.html#personportrait) which has more control over the size and sex of the person. * * If you need more control over the content of the images, you can pass a `category` parameter e.g. `'cat'` or `'nature'` to [`urlLoremFlickr()`](https://fakerjs.dev/api/image.html#urlloremflickr) or simply use [`faker.helpers.arrayElement()`](https://fakerjs.dev/api/helpers.html#arrayelement) with your own array of image URLs. */ @@ -51,7 +51,7 @@ export class ImageModule extends ModuleBase { } /** - * Generates a random avatar generated by AI. These are currently images of people which were generated by Stable Diffusion 3. The image URLs are served via the JSDelivr CDN and subject to their [terms of use](https://www.jsdelivr.com/terms). + * Generates a random square portrait of a person (avatar). These are currently images of fake people which were generated by an AI, Stable Diffusion 3. The image URLs are served via the JSDelivr CDN and subject to their [terms of use](https://www.jsdelivr.com/terms). * * @param options Options for generating an AI avatar. * @param options.sex The sex of the person for the avatar. Can be 'female' or 'male'. If not provided, defaults to a random selection. @@ -101,7 +101,7 @@ export class ImageModule extends ModuleBase { avatarLegacy(): string { deprecated({ deprecated: 'faker.image.avatarLegacy()', - proposed: 'faker.image.avatar()', + proposed: 'faker.image.avatar() or faker.image.personPortrait()', since: '9.0.2', until: '10.0.0', }); From e987dbc072925c87adb996fddb0a3c262e0619ad Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:50:57 +0700 Subject: [PATCH 09/25] Update index.ts Co-authored-by: ST-DDT --- src/modules/image/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index c918bb2372b..e2f333d22e8 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -51,7 +51,9 @@ export class ImageModule extends ModuleBase { } /** - * Generates a random square portrait of a person (avatar). These are currently images of fake people which were generated by an AI, Stable Diffusion 3. The image URLs are served via the JSDelivr CDN and subject to their [terms of use](https://www.jsdelivr.com/terms). + * Generates a random square portrait of a person (avatar). + * These are currently images of fake people which were generated by an AI, Stable Diffusion 3. + * The image URLs are served via the JSDelivr CDN and subject to their [terms of use](https://www.jsdelivr.com/terms). * * @param options Options for generating an AI avatar. * @param options.sex The sex of the person for the avatar. Can be 'female' or 'male'. If not provided, defaults to a random selection. From e963e431084a2b02f7d1ed13678f10d59b4fc7d3 Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:51:05 +0700 Subject: [PATCH 10/25] Update index.ts Co-authored-by: ST-DDT --- src/modules/image/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index e2f333d22e8..1bb1892e8ea 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -57,7 +57,7 @@ export class ImageModule extends ModuleBase { * * @param options Options for generating an AI avatar. * @param options.sex The sex of the person for the avatar. Can be 'female' or 'male'. If not provided, defaults to a random selection. - * @param options.size The size of the image. Can be 512, 256, 128, 64, 32 or 16. If not provided, defaults to 512. + * @param options.size The size of the image. Can be `512`, `256`, `128`, `64` or `32`. If not provided, defaults to `512`. * * @example * faker.image.personPortrait() From 6638f8dbf24351d9c768492afcb2581b0fe31068 Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:51:31 +0700 Subject: [PATCH 11/25] Update index.ts Co-authored-by: ST-DDT --- src/modules/image/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 1bb1892e8ea..1a195925476 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -67,7 +67,7 @@ export class ImageModule extends ModuleBase { * * @since 9.5.0 */ - personPortrait(options?: { + personPortrait(options: { /** * The sex of the person for the avatar. * Can be 'female' or 'male'. From 93b964cae266d3b8923acf6882d94db1317c9e52 Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:51:40 +0700 Subject: [PATCH 12/25] Update index.ts Co-authored-by: ST-DDT --- src/modules/image/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 1a195925476..9a60f5b232b 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -80,7 +80,7 @@ export class ImageModule extends ModuleBase { * If not provided, defaults to 512. */ size?: 512 | 256 | 128 | 64 | 32; - }): string { + } = {}): string { const type = options?.sex ?? this.faker.person.sexType(); const size = options?.size ?? 512; // FIXME: This should be replaced by the final CDN url, presumably something like: 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait' From 1c3202263ec32427b97b17a5c19c4f26d185f676 Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:51:46 +0700 Subject: [PATCH 13/25] Update index.ts Co-authored-by: ST-DDT --- src/modules/image/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 9a60f5b232b..8f2667a41cb 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -76,7 +76,7 @@ export class ImageModule extends ModuleBase { sex?: SexType; /** * The size of the image. - * Can be 512, 256, 128, 64 or 32. + * Can be `512`, `256`, `128`, `64` or `32`. * If not provided, defaults to 512. */ size?: 512 | 256 | 128 | 64 | 32; From f7882cb17038da6c65337db54b5b2c2e7847cdad Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:51:52 +0700 Subject: [PATCH 14/25] Update index.ts Co-authored-by: ST-DDT --- src/modules/image/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 8f2667a41cb..f2bffaf6d15 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -77,7 +77,8 @@ export class ImageModule extends ModuleBase { /** * The size of the image. * Can be `512`, `256`, `128`, `64` or `32`. - * If not provided, defaults to 512. + * + * @default 512 */ size?: 512 | 256 | 128 | 64 | 32; } = {}): string { From f8c699efb705fccc6424126eeb00328cf71cac95 Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:51:58 +0700 Subject: [PATCH 15/25] Update index.ts Co-authored-by: ST-DDT --- src/modules/image/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index f2bffaf6d15..d0d51a8d0cc 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -82,8 +82,7 @@ export class ImageModule extends ModuleBase { */ size?: 512 | 256 | 128 | 64 | 32; } = {}): string { - const type = options?.sex ?? this.faker.person.sexType(); - const size = options?.size ?? 512; + const { sex = this.faker.person.sexType(), size = 512 } = options; // FIXME: This should be replaced by the final CDN url, presumably something like: 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait' const baseURL = 'https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images'; From 7ab752223871af51d7c7a58ce8bb0a41a5b3daa2 Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:52:05 +0700 Subject: [PATCH 16/25] Update index.ts Co-authored-by: ST-DDT --- src/modules/image/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index d0d51a8d0cc..e52521340d2 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -70,7 +70,7 @@ export class ImageModule extends ModuleBase { personPortrait(options: { /** * The sex of the person for the avatar. - * Can be 'female' or 'male'. + * Can be `'female'` or `'male'`. * If not provided, defaults to a random selection. */ sex?: SexType; From 425c2cf65529779eca90c6958a3a440df572cc3b Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:52:12 +0700 Subject: [PATCH 17/25] Update index.ts Co-authored-by: ST-DDT --- src/modules/image/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index e52521340d2..e24e428ab11 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -71,7 +71,8 @@ export class ImageModule extends ModuleBase { /** * The sex of the person for the avatar. * Can be `'female'` or `'male'`. - * If not provided, defaults to a random selection. + * + * @default faker.person.sexType() */ sex?: SexType; /** From 5e8dabba0914595040df923484596c3c9e6281dd Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Wed, 5 Feb 2025 17:08:16 +0700 Subject: [PATCH 18/25] fix URL --- src/modules/image/index.ts | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index e24e428ab11..188b96fb923 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -67,27 +67,29 @@ export class ImageModule extends ModuleBase { * * @since 9.5.0 */ - personPortrait(options: { - /** - * The sex of the person for the avatar. - * Can be `'female'` or `'male'`. - * - * @default faker.person.sexType() - */ - sex?: SexType; - /** - * The size of the image. - * Can be `512`, `256`, `128`, `64` or `32`. - * - * @default 512 - */ - size?: 512 | 256 | 128 | 64 | 32; - } = {}): string { + personPortrait( + options: { + /** + * The sex of the person for the avatar. + * Can be `'female'` or `'male'`. + * + * @default faker.person.sexType() + */ + sex?: SexType; + /** + * The size of the image. + * Can be `512`, `256`, `128`, `64` or `32`. + * + * @default 512 + */ + size?: 512 | 256 | 128 | 64 | 32; + } = {} + ): string { const { sex = this.faker.person.sexType(), size = 512 } = options; // FIXME: This should be replaced by the final CDN url, presumably something like: 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait' const baseURL = 'https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images'; - return `${baseURL}/${type}/${size}/${this.faker.number.int({ min: 0, max: 99 })}.jpg`; + return `${baseURL}/${sex}/${size}/${this.faker.number.int({ min: 0, max: 99 })}.jpg`; } /** From 949ccecfae398bf3b06d02095869e09fdba6e157 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Wed, 5 Feb 2025 17:37:56 +0700 Subject: [PATCH 19/25] tweak docs --- src/modules/image/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 188b96fb923..6e7afd104de 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -51,8 +51,8 @@ export class ImageModule extends ModuleBase { } /** - * Generates a random square portrait of a person (avatar). - * These are currently images of fake people which were generated by an AI, Stable Diffusion 3. + * Generates a random square portrait (avatar) of a person. + * These are static images of fictional people created by an AI, Stable Diffusion 3. * The image URLs are served via the JSDelivr CDN and subject to their [terms of use](https://www.jsdelivr.com/terms). * * @param options Options for generating an AI avatar. From 557b25eebf5a0d0cd702bc46d532b228541aeb9b Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Wed, 5 Feb 2025 20:23:10 +0700 Subject: [PATCH 20/25] Update index.ts Co-authored-by: ST-DDT --- src/modules/image/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 6e7afd104de..e77bebd4c72 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -56,7 +56,7 @@ export class ImageModule extends ModuleBase { * The image URLs are served via the JSDelivr CDN and subject to their [terms of use](https://www.jsdelivr.com/terms). * * @param options Options for generating an AI avatar. - * @param options.sex The sex of the person for the avatar. Can be 'female' or 'male'. If not provided, defaults to a random selection. + * @param options.sex The sex of the person for the avatar. Can be `'female'` or `'male'`. If not provided, defaults to a random selection. * @param options.size The size of the image. Can be `512`, `256`, `128`, `64` or `32`. If not provided, defaults to `512`. * * @example From e23fd6661a0abeea32399938204c1b9ba62f3e07 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Fri, 7 Feb 2025 07:49:01 +0700 Subject: [PATCH 21/25] final urls --- src/modules/image/index.ts | 3 +- test/modules/__snapshots__/image.spec.ts.snap | 28 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index e77bebd4c72..bd8d73c9ed3 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -86,9 +86,8 @@ export class ImageModule extends ModuleBase { } = {} ): string { const { sex = this.faker.person.sexType(), size = 512 } = options; - // FIXME: This should be replaced by the final CDN url, presumably something like: 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait' const baseURL = - 'https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images'; + 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait'; return `${baseURL}/${sex}/${size}/${this.faker.number.int({ min: 0, max: 99 })}.jpg`; } diff --git a/test/modules/__snapshots__/image.spec.ts.snap b/test/modules/__snapshots__/image.spec.ts.snap index 44cc836eed9..2bcbe1a3340 100644 --- a/test/modules/__snapshots__/image.spec.ts.snap +++ b/test/modules/__snapshots__/image.spec.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`image > 42 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/512/73.jpg"`; +exports[`image > 42 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/512/73.jpg"`; exports[`image > 42 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/37454012"`; @@ -22,13 +22,13 @@ exports[`image > 42 > dataUri > with width 1`] = `"data:image/svg+xml;base64,PHN exports[`image > 42 > dataUri > with width and height 1`] = `"data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22%238ead33%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2264%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E128x128%3C%2Ftext%3E%3C%2Fsvg%3E"`; -exports[`image > 42 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/95.jpg"`; +exports[`image > 42 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/95.jpg"`; -exports[`image > 42 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/37.jpg"`; +exports[`image > 42 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/37.jpg"`; -exports[`image > 42 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/256/37.jpg"`; +exports[`image > 42 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/256/37.jpg"`; -exports[`image > 42 > personPortrait > with size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/128/95.jpg"`; +exports[`image > 42 > personPortrait > with size 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/128/95.jpg"`; exports[`image > 42 > url > noArgs 1`] = `"https://picsum.photos/seed/993RBH1Y/1498/3802"`; @@ -106,13 +106,13 @@ exports[`image > 1211 > dataUri > with width 1`] = `"data:image/svg+xml;charset= exports[`image > 1211 > dataUri > with width and height 1`] = `"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgYmFzZVByb2ZpbGU9ImZ1bGwiIHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4Ij48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZWQ0ZmVmIi8+PHRleHQgeD0iNjQiIHk9IjY0IiBmb250LXNpemU9IjIwIiBhbGlnbm1lbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZmlsbD0id2hpdGUiPjEyOHgxMjg8L3RleHQ+PC9zdmc+"`; -exports[`image > 1211 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/512/89.jpg"`; +exports[`image > 1211 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/512/89.jpg"`; -exports[`image > 1211 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/92.jpg"`; +exports[`image > 1211 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/92.jpg"`; -exports[`image > 1211 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/256/92.jpg"`; +exports[`image > 1211 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/256/92.jpg"`; -exports[`image > 1211 > personPortrait > with size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/128/89.jpg"`; +exports[`image > 1211 > personPortrait > with size 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/128/89.jpg"`; exports[`image > 1211 > url > noArgs 1`] = `"https://loremflickr.com/3714/3573?lock=8982492793493979"`; @@ -168,7 +168,7 @@ exports[`image > 1211 > urlPlaceholder > with width 1`] = `"https://via.placehol exports[`image > 1211 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/ed4fef/a7fbae.webp?text=dapifer%20usque%20unde"`; -exports[`image > 1337 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/27.jpg"`; +exports[`image > 1337 > avatar 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/27.jpg"`; exports[`image > 1337 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/26202467"`; @@ -190,13 +190,13 @@ exports[`image > 1337 > dataUri > with width 1`] = `"data:image/svg+xml;base64,P exports[`image > 1337 > dataUri > with width and height 1`] = `"data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22128%22%20height%3D%22128%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22%23536a7b%22%2F%3E%3Ctext%20x%3D%2264%22%20y%3D%2264%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E128x128%3C%2Ftext%3E%3C%2Fsvg%3E"`; -exports[`image > 1337 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/15.jpg"`; +exports[`image > 1337 > personPortrait > noArgs 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/15.jpg"`; -exports[`image > 1337 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/512/26.jpg"`; +exports[`image > 1337 > personPortrait > with sex 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/26.jpg"`; -exports[`image > 1337 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/male/256/26.jpg"`; +exports[`image > 1337 > personPortrait > with sex and size 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/256/26.jpg"`; -exports[`image > 1337 > personPortrait > with size 1`] = `"https://cdn.jsdelivr.net/gh/matthewmayer/assets-person-portrait@new-images/female/128/15.jpg"`; +exports[`image > 1337 > personPortrait > with size 1`] = `"https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/128/15.jpg"`; exports[`image > 1337 > url > noArgs 1`] = `"https://loremflickr.com/1048/635?lock=4137158724208997"`; From 8ed7ef7fef473996f631c641bcb94c2dd4188cd5 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Fri, 7 Feb 2025 07:54:40 +0700 Subject: [PATCH 22/25] new tests --- test/modules/image.spec.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/modules/image.spec.ts b/test/modules/image.spec.ts index 0e891ee45cd..b8fcbfe8e3a 100644 --- a/test/modules/image.spec.ts +++ b/test/modules/image.spec.ts @@ -156,7 +156,18 @@ describe('image', () => { const imageUrl = faker.image.personPortrait(); expect(imageUrl).toBeTypeOf('string'); - expect(imageUrl).toMatch(/^https:\/\/cdn\.jsdelivr\.net\/.*\.jpg$/); + expect(imageUrl).toMatch( + /^https:\/\/cdn\.jsdelivr\.net\/gh\/faker-js\/assets-person-portrait\/(female|male)\/512\/\d{1,2}\.jpg$/ + ); + expect(() => new URL(imageUrl)).not.toThrow(); + }); + it('should return a random avatar url from AI with fixed size and sex', () => { + const imageUrl = faker.image.personPortrait({ sex: 'male', size: 128 }); + + expect(imageUrl).toBeTypeOf('string'); + expect(imageUrl).toMatch( + /^https:\/\/cdn\.jsdelivr\.net\/gh\/faker-js\/assets-person-portrait\/male\/128\/\d{1,2}\.jpg$/ + ); expect(() => new URL(imageUrl)).not.toThrow(); }); }); From 5c248a3375e829e48ca0c1edf81b6106ea3593ef Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Fri, 7 Feb 2025 12:52:02 +0700 Subject: [PATCH 23/25] final urls --- src/modules/image/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index bd8d73c9ed3..59b049b293c 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -60,10 +60,8 @@ export class ImageModule extends ModuleBase { * @param options.size The size of the image. Can be `512`, `256`, `128`, `64` or `32`. If not provided, defaults to `512`. * * @example - * faker.image.personPortrait() - * // 'https://cdn.jsdelivr.net/.../female/512/57.jpg' - * faker.image.personPortrait({ sex: 'male', size:'128' }) - * // 'https://cdn.jsdelivr.net/.../male/128/27.jpg' + * faker.image.personPortrait() // 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/57.jpg' + * faker.image.personPortrait({ sex: 'male', size:'128' }) // 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/128/27.jpg' * * @since 9.5.0 */ From a35394b03a0116a081dd0d19a280bee2d11d9681 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Fri, 7 Feb 2025 10:13:18 +0100 Subject: [PATCH 24/25] chore: fix import scan --- test/scripts/apidocs/verify-jsdoc-tags.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scripts/apidocs/verify-jsdoc-tags.spec.ts b/test/scripts/apidocs/verify-jsdoc-tags.spec.ts index 703e42cf37b..dd77620d504 100644 --- a/test/scripts/apidocs/verify-jsdoc-tags.spec.ts +++ b/test/scripts/apidocs/verify-jsdoc-tags.spec.ts @@ -147,7 +147,7 @@ ${examples}`; if (!examples.includes('import ')) { const imports = [ // collect the imports for the various locales e.g. fakerDE_CH - ...new Set(examples.match(/(? 0) { From 242609eafc2024a3a0522da407cd50a84cfef6ba Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Fri, 7 Feb 2025 10:15:10 +0100 Subject: [PATCH 25/25] chore: format --- src/modules/image/index.ts | 2 +- test/modules/image.spec.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 59b049b293c..6b0a70171f8 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -61,7 +61,7 @@ export class ImageModule extends ModuleBase { * * @example * faker.image.personPortrait() // 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/57.jpg' - * faker.image.personPortrait({ sex: 'male', size:'128' }) // 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/128/27.jpg' + * faker.image.personPortrait({ sex: 'male', size: '128' }) // 'https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/128/27.jpg' * * @since 9.5.0 */ diff --git a/test/modules/image.spec.ts b/test/modules/image.spec.ts index b8fcbfe8e3a..0d494cb4a42 100644 --- a/test/modules/image.spec.ts +++ b/test/modules/image.spec.ts @@ -161,6 +161,7 @@ describe('image', () => { ); expect(() => new URL(imageUrl)).not.toThrow(); }); + it('should return a random avatar url from AI with fixed size and sex', () => { const imageUrl = faker.image.personPortrait({ sex: 'male', size: 128 });