diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts
index e0dd9d2212b..6beae600f4f 100644
--- a/src/modules/image/index.ts
+++ b/src/modules/image/index.ts
@@ -1,4 +1,5 @@
import type { Faker } from '../..';
+import { deprecated } from '../../internal/deprecated';
import type { MethodsOf } from '../../utils/types';
import { LoremPicsum } from './providers/lorempicsum';
import { Lorempixel } from './providers/lorempixel';
@@ -6,14 +7,27 @@ import { Placeholder } from './providers/placeholder';
import { Unsplash } from './providers/unsplash';
/**
- * Module to generate placeholder images.
- *
- * Default provider is unsplash image provider.
+ * Module to generate images.
*/
export class ImageModule {
+ /**
+ * @deprecated Use `faker.image` instead.
+ */
readonly lorempixel: Lorempixel;
+
+ /**
+ * @deprecated Use `faker.image` instead.
+ */
readonly unsplash: Unsplash;
+
+ /**
+ * @deprecated Use `faker.image` instead.
+ */
readonly lorempicsum: LoremPicsum;
+
+ /**
+ * @deprecated Use `faker.image.urlPlaceholder` instead.
+ */
readonly placeholder: Placeholder;
constructor(private readonly faker: Faker) {
@@ -31,6 +45,263 @@ export class ImageModule {
this.placeholder = new Placeholder(this.faker);
}
+ /**
+ * Generates a random avatar image url.
+ *
+ * @example
+ * faker.image.avatar()
+ * // 'https://avatars.githubusercontent.com/u/97165289'
+ *
+ * @since 2.0.1
+ */
+ avatar(): string {
+ const avatarMethod = this.faker.helpers.arrayElement([
+ this.avatarLegacy,
+ this.avatarGitHub,
+ ]);
+
+ return avatarMethod();
+ }
+
+ /**
+ * Generates a random avatar from GitHub.
+ *
+ * @example
+ * faker.image.avatarGitHub()
+ * // 'https://avatars.githubusercontent.com/u/97165289'
+ *
+ * @since 8.0.0
+ */
+ avatarGitHub(): string {
+ return `https://avatars.githubusercontent.com/u/${this.faker.number.int(
+ 100000000
+ )}`;
+ }
+
+ /**
+ * 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
+ */
+ // This implementation will change in the future when we tackle https://github.com/faker-js/faker/issues/465.
+ avatarLegacy(): string {
+ return `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/${this.faker.number.int(
+ 1249
+ )}.jpg`;
+ }
+
+ /**
+ * Generates a random image url.
+ *
+ * @param options Options for generating a URL for an image.
+ * @param options.width The width of the image. Defaults to `640`.
+ * @param options.height The height of the image. Defaults to `480`.
+ *
+ * @example
+ * faker.image.url() // 'https://loremflickr.com/640/480?lock=1234'
+ *
+ * @since 8.0.0
+ */
+ url(
+ options: {
+ width?: number;
+ height?: number;
+ } = {}
+ ): string {
+ const { width = 640, height = 480 } = options;
+
+ const urlMethod = this.faker.helpers.arrayElement([
+ this.urlLoremFlickr,
+ this.urlPicsumPhotos,
+ ]);
+
+ return urlMethod({ width, height });
+ }
+
+ /**
+ * Generates a random image url provided via https://loremflickr.com.
+ *
+ * @param options Options for generating a URL for an image.
+ * @param options.width The width of the image. Defaults to `640`.
+ * @param options.height The height of the image. Defaults to `480`.
+ * @param options.category Category to use for the image.
+ *
+ * @example
+ * faker.image.urlLoremFlickr() // 'https://loremflickr.com/640/480?lock=1234'
+ * faker.image.urlLoremFlickr({ width: 128 }) // 'https://loremflickr.com/128/480?lock=1234'
+ * faker.image.urlLoremFlickr({ height: 128 }) // 'https://loremflickr.com/640/128?lock=1234'
+ * faker.image.urlLoremFlickr({ category: 'nature' }) // 'https://loremflickr.com/640/480/nature?lock=1234'
+ *
+ * @since 8.0.0
+ */
+ urlLoremFlickr(
+ options: {
+ width?: number;
+ height?: number;
+ category?: string;
+ } = {}
+ ): string {
+ const { width = 640, height = 480, category } = options;
+
+ return `https://loremflickr.com/${width}/${height}${
+ category != null ? `/${category}` : ''
+ }?lock=${this.faker.number.int()}`;
+ }
+
+ /**
+ * Generates a random image url provided via https://picsum.photos.
+ *
+ * @param options Options for generating a URL for an image.
+ * @param options.width The width of the image. Defaults to `640`.
+ * @param options.height The height of the image. Defaults to `480`.
+ * @param options.grayscale Whether the image should be grayscale. Defaults to `false`.
+ * @param options.blur Whether the image should be blurred. Defaults to `false`.
+ *
+ * @example
+ * faker.image.urlPicsumPhotos() // 'https://picsum.photos/id/241/640/480'
+ * faker.image.urlPicsumPhotos({ width: 128 }) // 'https://picsum.photos/id/241/128/480'
+ * faker.image.urlPicsumPhotos({ height: 128 }) // 'https://picsum.photos/id/241/640/128'
+ * faker.image.urlPicsumPhotos({ grayscale: true }) // 'https://picsum.photos/id/241/640/480?grayscale'
+ * faker.image.urlPicsumPhotos({ blur: 4 }) // 'https://picsum.photos/id/241/640/480?blur=4'
+ * faker.image.urlPicsumPhotos({ blur: 4, grayscale: true }) // 'https://picsum.photos/id/241/640/480?grayscale&blur=4'
+ *
+ * @since 8.0.0
+ */
+ urlPicsumPhotos(
+ options: {
+ width?: number;
+ height?: number;
+ grayscale?: boolean;
+ blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
+ } = {}
+ ): string {
+ const { width = 640, height = 480, grayscale = false, blur } = options;
+
+ let url = `https://picsum.photos/id/${this.faker.number.int(
+ 1000
+ )}/${width}/${height}`;
+
+ const hasValidGrayscale = grayscale === true;
+ const hasValidBlur = typeof blur === 'number' && blur >= 1 && blur <= 10;
+
+ if (hasValidGrayscale || hasValidBlur) {
+ url += '?';
+
+ if (hasValidGrayscale) {
+ url += `grayscale`;
+ }
+
+ if (hasValidGrayscale && hasValidBlur) {
+ url += '&';
+ }
+
+ if (hasValidBlur) {
+ url += `blur=${blur}`;
+ }
+ }
+
+ return url;
+ }
+
+ /**
+ * Generates a random image url provided via https://via.placeholder.com/.
+ *
+ * @param options Options for generating a URL for an image.
+ * @param options.width The width of the image. Defaults to random number between 1 and 3999.
+ * @param options.height The height of the image. Defaults to random number between 1 and 3999.
+ * @param options.backgroundColor The background color of the image. Defaults to random hex color.
+ * @param options.textColor The text color of the image. Defaults to random hex color.
+ * @param options.format The format of the image. Defaults to random format.
+ * @param options.text The text to display on the image. Defaults to string.
+ *
+ * @example
+ * faker.image.urlPlaceholder() // 'https://via.placeholder.com/150x180/FF0000/FFFFFF.webp?text=lorem'
+ * faker.image.urlPlaceholder({ width: 128 }) // 'https://via.placeholder.com/128x180/FF0000/FFFFFF.webp?text=lorem'
+ * faker.image.urlPlaceholder({ height: 128 }) // 'https://via.placeholder.com/150x128/FF0000/FFFFFF.webp?text=lorem'
+ * faker.image.urlPlaceholder({ backgroundColor: '000000' }) // 'https://via.placeholder.com/150x180/000000/FFFFFF.webp?text=lorem'
+ * faker.image.urlPlaceholder({ textColor: '000000' }) // 'https://via.placeholder.com/150x180/FF0000/000000.webp?text=lorem'
+ * faker.image.urlPlaceholder({ format: 'png' }) // 'https://via.placeholder.com/150x180/FF0000/FFFFFF.png?text=lorem'
+ * faker.image.urlPlaceholder({ text: 'lorem ipsum' }) // 'https://via.placeholder.com/150x180/FF0000/FFFFFF.webp?text=lorem+ipsum'
+ * faker.image.urlPlaceholder({ width: 128, height: 128, backgroundColor: '000000', textColor: 'FF0000', format: 'png', text: 'lorem ipsum' }) // 'https://via.placeholder.com/128x128/000000/FF0000.png?text=lorem+ipsum'
+ *
+ * @since 8.0.0
+ */
+ urlPlaceholder(
+ options: {
+ width?: number;
+ height?: number;
+ backgroundColor?: string;
+ textColor?: string;
+ format?: 'gif' | 'jpeg' | 'jpg' | 'png' | 'webp';
+ text?: string;
+ } = {}
+ ): string {
+ const {
+ width = this.faker.number.int({ min: 1, max: 3999 }),
+ height = this.faker.number.int({ min: 1, max: 3999 }),
+ backgroundColor = this.faker.color.rgb({ format: 'hex', prefix: '' }),
+ textColor = this.faker.color.rgb({ format: 'hex', prefix: '' }),
+ format = this.faker.helpers.arrayElement([
+ 'gif',
+ 'jpeg',
+ 'jpg',
+ 'png',
+ 'webp',
+ ]),
+ text = this.faker.lorem.words(),
+ } = options;
+
+ let url = `https://via.placeholder.com`;
+
+ url += `/${width}`;
+ url += `x${height}`;
+
+ url += `/${backgroundColor}`;
+ url += `/${textColor}`;
+
+ url += `.${format}`;
+
+ url += `?text=${encodeURIComponent(text)}`;
+
+ return url;
+ }
+
+ /**
+ * Generates a random data uri containing an svg image.
+ *
+ * @param options Options for generating a data uri.
+ * @param options.width The width of the image. Defaults to `640`.
+ * @param options.height The height of the image. Defaults to `480`.
+ * @param options.color The color of the image. Defaults to `grey`.
+ *
+ * @example
+ * faker.image.dataUri() // 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http...'
+ *
+ * @since 4.0.0
+ */
+ dataUri(
+ options: {
+ width?: number;
+ height?: number;
+ color?: string;
+ } = {}
+ ): string {
+ const { width = 640, height = 480, color = 'grey' } = options;
+
+ const svgString = ``;
+
+ const rawPrefix = 'data:image/svg+xml;charset=UTF-8,';
+ return rawPrefix + encodeURIComponent(svgString);
+ }
+
/**
* Generates a random image url from one of the supported categories.
*
@@ -44,8 +315,16 @@ export class ImageModule {
* faker.image.image(1234, 2345, true) // 'https://loremflickr.com/1234/2345/nature?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
image(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.image',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
const categories: MethodsOf = [
'abstract',
'animals',
@@ -68,19 +347,6 @@ export class ImageModule {
);
}
- /**
- * Generates a random avatar image url.
- *
- * @example
- * faker.image.avatar()
- * // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/170.jpg'
- *
- * @since 2.0.1
- */
- avatar(): string {
- return this.faker.internet.avatar();
- }
-
/**
* Generates a random image url.
*
@@ -96,6 +362,8 @@ export class ImageModule {
* faker.image.imageUrl(1234, 2345, 'cat', true) // 'https://loremflickr.com/1234/2345/cat?lock=6849'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
imageUrl(
width?: number,
@@ -103,6 +371,13 @@ export class ImageModule {
category?: string,
randomize?: boolean
): string {
+ deprecated({
+ deprecated: 'faker.image.imageUrl',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
+
width = width || 640;
height = height || 480;
let url = `https://loremflickr.com/${width}/${height}`;
@@ -130,8 +405,16 @@ export class ImageModule {
* faker.image.abstract(1234, 2345, true) // 'https://loremflickr.com/1234/2345/abstract?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
abstract(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.abstract',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'abstract', randomize);
}
@@ -148,8 +431,16 @@ export class ImageModule {
* faker.image.animals(1234, 2345, true) // 'https://loremflickr.com/1234/2345/animals?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
animals(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.animals',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'animals', randomize);
}
@@ -166,8 +457,16 @@ export class ImageModule {
* faker.image.business(1234, 2345, true) // 'https://loremflickr.com/1234/2345/business?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
business(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.business',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'business', randomize);
}
@@ -184,8 +483,16 @@ export class ImageModule {
* faker.image.cats(1234, 2345, true) // 'https://loremflickr.com/1234/2345/cats?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
cats(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.cats',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'cats', randomize);
}
@@ -202,8 +509,16 @@ export class ImageModule {
* faker.image.city(1234, 2345, true) // 'https://loremflickr.com/1234/2345/city?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
city(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.city',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'city', randomize);
}
@@ -220,8 +535,16 @@ export class ImageModule {
* faker.image.food(1234, 2345, true) // 'https://loremflickr.com/1234/2345/food?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
food(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.food',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'food', randomize);
}
@@ -238,8 +561,16 @@ export class ImageModule {
* faker.image.nightlife(1234, 2345, true) // 'https://loremflickr.com/1234/2345/nightlife?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
nightlife(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.nightlife',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'nightlife', randomize);
}
@@ -256,8 +587,16 @@ export class ImageModule {
* faker.image.fashion(1234, 2345, true) // 'https://loremflickr.com/1234/2345/fashion?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
fashion(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.fashion',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'fashion', randomize);
}
@@ -274,8 +613,16 @@ export class ImageModule {
* faker.image.people(1234, 2345, true) // 'https://loremflickr.com/1234/2345/people?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
people(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.people',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'people', randomize);
}
@@ -292,8 +639,16 @@ export class ImageModule {
* faker.image.nature(1234, 2345, true) // 'https://loremflickr.com/1234/2345/nature?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
nature(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.nature',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'nature', randomize);
}
@@ -310,8 +665,16 @@ export class ImageModule {
* faker.image.sports(1234, 2345, true) // 'https://loremflickr.com/1234/2345/sports?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
sports(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.sports',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'sports', randomize);
}
@@ -328,8 +691,16 @@ export class ImageModule {
* faker.image.technics(1234, 2345, true) // 'https://loremflickr.com/1234/2345/technics?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
technics(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.technics',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'technics', randomize);
}
@@ -346,30 +717,16 @@ export class ImageModule {
* faker.image.transport(1234, 2345, true) // 'https://loremflickr.com/1234/2345/transport?lock=56789'
*
* @since 2.0.1
+ *
+ * @deprecated Use `faker.image.url` instead.
*/
transport(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.image.transport',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, 'transport', randomize);
}
-
- /**
- * Generates a random data uri containing an svg image.
- *
- * @param width The width of the image. Defaults to `640`.
- * @param height The height of the image. Defaults to `480`.
- * @param color The color to use. Defaults to `grey`.
- *
- * @example
- * faker.image.dataUri() // 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http...'
- *
- * @since 4.0.0
- */
- dataUri(width?: number, height?: number, color: string = 'grey'): string {
- const svgString = ``;
- const rawPrefix = 'data:image/svg+xml;charset=UTF-8,';
- return rawPrefix + encodeURIComponent(svgString);
- }
}
diff --git a/src/modules/image/providers/lorempicsum.ts b/src/modules/image/providers/lorempicsum.ts
index d44673bdb42..f2f915eae57 100644
--- a/src/modules/image/providers/lorempicsum.ts
+++ b/src/modules/image/providers/lorempicsum.ts
@@ -1,19 +1,23 @@
import type { Faker } from '../../..';
+import { deprecated } from '../../../internal/deprecated';
/**
- * Module to generate links to random images on `https://picsum.photos/`.
+ * Module to generate links to random images on https://picsum.photos.
+ *
+ * @deprecated Use `faker.image.urlPicsumPhotos` instead.
*/
-// TODO ST-DDT 2022-03-11: Rename to picsum?
export class LoremPicsum {
constructor(private readonly faker: Faker) {}
/**
- * Generates a new picsum image url.
+ * Generates a new picsum photos image url.
*
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param grayscale Whether to return a grayscale image. Default to `false`.
* @param blur The optional level of blur to apply. Supports `1` - `10`.
+ *
+ * @deprecated Use `faker.image.urlPicsumPhotos` instead.
*/
image(
width?: number,
@@ -21,43 +25,67 @@ export class LoremPicsum {
grayscale?: boolean,
blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
): string {
+ deprecated({
+ deprecated: 'faker.lorempicsum.image',
+ proposed: 'faker.image.urlPicsumPhotos',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, grayscale, blur);
}
/**
- * Generates a new picsum image url.
+ * Generates a new picsum photos image url.
*
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param grayscale Whether to return a grayscale image. Default to `false`.
+ *
+ * @deprecated Use `faker.image.urlPicsumPhotos` instead.
*/
imageGrayscale(width?: number, height?: number, grayscale?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempicsum.imageGrayscale',
+ proposed: 'faker.image.urlPicsumPhotos',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, grayscale);
}
/**
- * Generates a new picsum image url.
+ * Generates a new picsum photos image url.
*
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param blur The optional level of blur to apply. Supports `1` - `10`.
+ *
+ * @deprecated Use `faker.image.urlPicsumPhotos` instead.
*/
imageBlurred(
width?: number,
height?: number,
blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
): string {
+ deprecated({
+ deprecated: 'faker.lorempicsum.imageBlurred',
+ proposed: 'faker.image.urlPicsumPhotos',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, undefined, blur);
}
/**
- * Generates a new picsum image url.
+ * Generates a new picsum photos image url.
*
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param grayscale Whether to return a grayscale image. Default to `false`.
* @param blur The optional level of blur to apply. Supports `1` - `10`.
* @param seed The optional seed to use.
+ *
+ * @deprecated Use `faker.image.urlPicsumPhotos` instead.
*/
imageRandomSeeded(
width?: number,
@@ -66,18 +94,26 @@ export class LoremPicsum {
blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10,
seed?: string
): string {
+ deprecated({
+ deprecated: 'faker.lorempicsum.imageRandomSeeded',
+ proposed: 'faker.image.urlPicsumPhotos',
+ since: '8.0',
+ until: '9.0',
+ });
// TODO ST-DDT 2022-03-11: This method does the same as image url, maybe generate a seed, if it is missig?
return this.imageUrl(width, height, grayscale, blur, seed);
}
/**
- * Generates a new picsum image url.
+ * Generates a new picsum photos image url.
*
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param grayscale Whether to return a grayscale image. Default to `false`.
* @param blur The optional level of blur to apply. Supports `1` - `10`.
* @param seed The optional seed to use.
+ *
+ * @deprecated Use `faker.image.urlPicsumPhotos` instead.
*/
imageUrl(
width?: number,
@@ -86,6 +122,12 @@ export class LoremPicsum {
blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10,
seed?: string
): string {
+ deprecated({
+ deprecated: 'faker.lorempicsum.imageUrl',
+ proposed: 'faker.image.urlPicsumPhotos',
+ since: '8.0',
+ until: '9.0',
+ });
width = width || 640;
height = height || 480;
diff --git a/src/modules/image/providers/lorempixel.ts b/src/modules/image/providers/lorempixel.ts
index f8bb81e5da1..ac80a8d7d30 100644
--- a/src/modules/image/providers/lorempixel.ts
+++ b/src/modules/image/providers/lorempixel.ts
@@ -1,8 +1,11 @@
import type { Faker } from '../../..';
+import { deprecated } from '../../../internal/deprecated';
import type { MethodsOf } from '../../../utils/types';
/**
* Module to generate links to random images on `https://lorempixel.com/`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
export class Lorempixel {
constructor(private readonly faker: Faker) {}
@@ -13,8 +16,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
image(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.image',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
const categories: MethodsOf = [
'abstract',
'animals',
@@ -44,6 +55,8 @@ export class Lorempixel {
* @param height The height of the image. Defaults to `480`.
* @param category The category of the image to generate.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
imageUrl(
width?: number,
@@ -51,6 +64,12 @@ export class Lorempixel {
category?: string,
randomize?: boolean
): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.imageUrl',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
width = width || 640;
height = height || 480;
@@ -72,8 +91,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
abstract(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.abstract',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -88,8 +115,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
animals(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.animals',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -104,8 +139,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
business(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.business',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -120,8 +163,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
cats(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.cats',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -136,8 +187,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
city(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.city',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -152,8 +211,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
food(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.food',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -168,8 +235,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
nightlife(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.nightlife',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -184,8 +259,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
fashion(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.fashion',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -200,8 +283,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
people(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.people',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -216,8 +307,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
nature(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.nature',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -232,8 +331,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
sports(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.sports',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -248,8 +355,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
technics(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.technics',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
@@ -264,8 +379,16 @@ export class Lorempixel {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param randomize Whether to append a seed to the url. Defaults to `false`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
transport(width?: number, height?: number, randomize?: boolean): string {
+ deprecated({
+ deprecated: 'faker.lorempixel.transport',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.lorempixel.imageUrl(
width,
height,
diff --git a/src/modules/image/providers/placeholder.ts b/src/modules/image/providers/placeholder.ts
index 224dccfe03a..d2cc9f51004 100644
--- a/src/modules/image/providers/placeholder.ts
+++ b/src/modules/image/providers/placeholder.ts
@@ -1,7 +1,10 @@
import type { Faker } from '../../..';
+import { deprecated } from '../../../internal/deprecated';
/**
* Module to generate links to images on `https://via.placeholder.com/`.
+ *
+ * @deprecated Use `faker.image.urlPlaceholder` instead.
*/
export class Placeholder {
constructor(private readonly faker: Faker) {
@@ -33,6 +36,7 @@ export class Placeholder {
* faker.image.placeholder.imageUrl(200, 100, 'Fish', 'webp') // https://via.placeholder.com/200x100.webp?text=Fish
* faker.image.placeholder.imageUrl(200, 100, 'Fish', 'webp', '000000', 'ffffff) // https://via.placeholder.com/200x100/000000/FFFFFF.webp?text=Fish
*
+ * @deprecated Use `faker.image.urlPlaceholder` instead.
*/
imageUrl(
width?: number,
@@ -42,6 +46,12 @@ export class Placeholder {
backgroundColor?: string,
textColor?: string
): string {
+ deprecated({
+ deprecated: 'faker.placeholder.imageUrl',
+ proposed: 'faker.image.urlPlaceholder',
+ since: '8.0',
+ until: '9.0',
+ });
width = width || 640;
height = height || width;
@@ -80,12 +90,20 @@ export class Placeholder {
* faker.image.placeholder.randomUrl(150) // https://via.placeholder.com/150x150/000000/ffffff?text=lorum
* faker.image.placeholder.randomUrl(150, 200) // https://via.placeholder.com/150x200/000000/ffffff?text=lorum
* faker.image.placeholder.randomUrl(150, 200, 'png') // https://via.placeholder.com/150x200/000000/ffffff.png?text=lorum
+ *
+ * @deprecated Use `faker.image.urlPlaceholder` instead.
*/
randomUrl(
width?: number,
height?: number,
format?: 'png' | 'jpeg' | 'jpg' | 'gif' | 'webp'
): string {
+ deprecated({
+ deprecated: 'faker.placeholder.randomUrl',
+ proposed: 'faker.image.urlPlaceholder',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(
width,
height,
diff --git a/src/modules/image/providers/unsplash.ts b/src/modules/image/providers/unsplash.ts
index 8fc2e324d93..aaaae9c7510 100644
--- a/src/modules/image/providers/unsplash.ts
+++ b/src/modules/image/providers/unsplash.ts
@@ -1,7 +1,10 @@
import type { Faker } from '../../..';
+import { deprecated } from '../../../internal/deprecated';
/**
* Module to generate links to random images on `https://source.unsplash.com/`.
+ *
+ * @deprecated Use `faker.image` instead.
*/
export class Unsplash {
constructor(private readonly faker: Faker) {}
@@ -12,8 +15,16 @@ export class Unsplash {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param keyword The image keywords to use.
+ *
+ * @deprecated Use `faker.image` instead.
*/
image(width?: number, height?: number, keyword?: string): string {
+ deprecated({
+ deprecated: 'faker.unsplash.image',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.imageUrl(width, height, undefined, keyword);
}
@@ -24,6 +35,8 @@ export class Unsplash {
* @param height The height of the image. Defaults to `480`.
* @param category The category of the image to generate.
* @param keyword The image keywords to use.
+ *
+ * @deprecated Use `faker.image` instead.
*/
imageUrl(
width?: number,
@@ -31,6 +44,12 @@ export class Unsplash {
category?: string,
keyword?: string
): string {
+ deprecated({
+ deprecated: 'faker.unsplash.imageUrl',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
width = width || 640;
height = height || 480;
@@ -58,8 +77,16 @@ export class Unsplash {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param keyword The image keywords to use.
+ *
+ * @deprecated Use `faker.image` instead.
*/
food(width?: number, height?: number, keyword?: string): string {
+ deprecated({
+ deprecated: 'faker.unsplash.food',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.unsplash.imageUrl(width, height, 'food', keyword);
}
@@ -69,8 +96,16 @@ export class Unsplash {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param keyword The image keywords to use.
+ *
+ * @deprecated Use `faker.image` instead.
*/
people(width?: number, height?: number, keyword?: string): string {
+ deprecated({
+ deprecated: 'faker.unsplash.people',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.unsplash.imageUrl(width, height, 'people', keyword);
}
@@ -80,8 +115,16 @@ export class Unsplash {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param keyword The image keywords to use.
+ *
+ * @deprecated Use `faker.image` instead.
*/
nature(width?: number, height?: number, keyword?: string): string {
+ deprecated({
+ deprecated: 'faker.unsplash.nature',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.unsplash.imageUrl(width, height, 'nature', keyword);
}
@@ -91,8 +134,16 @@ export class Unsplash {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param keyword The image keywords to use.
+ *
+ * @deprecated Use `faker.image` instead.
*/
technology(width?: number, height?: number, keyword?: string): string {
+ deprecated({
+ deprecated: 'faker.unsplash.technology',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.unsplash.imageUrl(
width,
height,
@@ -107,8 +158,16 @@ export class Unsplash {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param keyword The image keywords to use.
+ *
+ * @deprecated Use `faker.image` instead.
*/
objects(width?: number, height?: number, keyword?: string): string {
+ deprecated({
+ deprecated: 'faker.unsplash.objects',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.unsplash.imageUrl(
width,
height,
@@ -123,8 +182,16 @@ export class Unsplash {
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param keyword The image keywords to use.
+ *
+ * @deprecated Use `faker.image` instead.
*/
buildings(width?: number, height?: number, keyword?: string): string {
+ deprecated({
+ deprecated: 'faker.unsplash.buildings',
+ proposed: 'faker.image.url',
+ since: '8.0',
+ until: '9.0',
+ });
return this.faker.image.unsplash.imageUrl(
width,
height,
diff --git a/test/__snapshots__/image.spec.ts.snap b/test/__snapshots__/image.spec.ts.snap
new file mode 100644
index 00000000000..61a4d245447
--- /dev/null
+++ b/test/__snapshots__/image.spec.ts.snap
@@ -0,0 +1,185 @@
+// Vitest Snapshot v1
+
+exports[`image > 42 > avatar 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/995.jpg"`;
+
+exports[`image > 42 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/37454011"`;
+
+exports[`image > 42 > avatarLegacy 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/468.jpg"`;
+
+exports[`image > 42 > url > noArgs 1`] = `"https://loremflickr.com/640/480?lock=79654"`;
+
+exports[`image > 42 > url > with height 1`] = `"https://loremflickr.com/640/128?lock=79654"`;
+
+exports[`image > 42 > url > with width 1`] = `"https://loremflickr.com/128/480?lock=79654"`;
+
+exports[`image > 42 > url > with width and height 1`] = `"https://loremflickr.com/128/128?lock=79654"`;
+
+exports[`image > 42 > urlLoremFlickr > noArgs 1`] = `"https://loremflickr.com/640/480?lock=37454"`;
+
+exports[`image > 42 > urlLoremFlickr > with all options 1`] = `"https://loremflickr.com/128/128/cats?lock=37454"`;
+
+exports[`image > 42 > urlLoremFlickr > with category 1`] = `"https://loremflickr.com/640/480/cats?lock=37454"`;
+
+exports[`image > 42 > urlLoremFlickr > with height 1`] = `"https://loremflickr.com/640/128?lock=37454"`;
+
+exports[`image > 42 > urlLoremFlickr > with width 1`] = `"https://loremflickr.com/128/480?lock=37454"`;
+
+exports[`image > 42 > urlLoremFlickr > with width and height 1`] = `"https://loremflickr.com/128/128?lock=37454"`;
+
+exports[`image > 42 > urlPicsumPhotos > noArgs 1`] = `"https://picsum.photos/id/374/640/480"`;
+
+exports[`image > 42 > urlPicsumPhotos > with all options 1`] = `"https://picsum.photos/id/374/128/128?grayscale&blur=4"`;
+
+exports[`image > 42 > urlPicsumPhotos > with blur 1`] = `"https://picsum.photos/id/374/640/480?blur=6"`;
+
+exports[`image > 42 > urlPicsumPhotos > with blur and grayscale 1`] = `"https://picsum.photos/id/374/640/480?grayscale&blur=3"`;
+
+exports[`image > 42 > urlPicsumPhotos > with height 1`] = `"https://picsum.photos/id/374/640/128"`;
+
+exports[`image > 42 > urlPicsumPhotos > with width 1`] = `"https://picsum.photos/id/374/128/480"`;
+
+exports[`image > 42 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/id/374/128/128"`;
+
+exports[`image > 42 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/1498x3186/e4abdd/39321a.webp?text=veniam%20unde%20fugit"`;
+
+exports[`image > 42 > urlPlaceholder > with all options 1`] = `"https://via.placeholder.com/128x128/FF0000/0000FF.png?text=hello"`;
+
+exports[`image > 42 > urlPlaceholder > with backgroundColor 1`] = `"https://via.placeholder.com/1498x3186/FF0000/e4abdd.gif?text=in%20quia%20architecto"`;
+
+exports[`image > 42 > urlPlaceholder > with empty colors and text 1`] = `"https://via.placeholder.com/128x128//.png?text="`;
+
+exports[`image > 42 > urlPlaceholder > with format 1`] = `"https://via.placeholder.com/1498x3186/e4abdd/39321a.webp?text=pariatur%20veniam%20unde"`;
+
+exports[`image > 42 > urlPlaceholder > with height 1`] = `"https://via.placeholder.com/1498x128/be4abd/d39321.jpg?text=pariatur%20veniam%20unde"`;
+
+exports[`image > 42 > urlPlaceholder > with text 1`] = `"https://via.placeholder.com/1498x3186/e4abdd/39321a.webp?text=Hello"`;
+
+exports[`image > 42 > urlPlaceholder > with textColor 1`] = `"https://via.placeholder.com/1498x3186/e4abdd/0000FF.gif?text=in%20quia%20architecto"`;
+
+exports[`image > 42 > urlPlaceholder > with width 1`] = `"https://via.placeholder.com/128x1498/be4abd/d39321.jpg?text=pariatur%20veniam%20unde"`;
+
+exports[`image > 42 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/8be4ab/dd3932.gif?text=esse%20pariatur%20veniam"`;
+
+exports[`image > 1211 > avatar 1`] = `"https://avatars.githubusercontent.com/u/45901520"`;
+
+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"`;
+
+exports[`image > 1211 > url > noArgs 1`] = `"https://picsum.photos/id/459/640/480"`;
+
+exports[`image > 1211 > url > with height 1`] = `"https://picsum.photos/id/459/640/128"`;
+
+exports[`image > 1211 > url > with width 1`] = `"https://picsum.photos/id/459/128/480"`;
+
+exports[`image > 1211 > url > with width and height 1`] = `"https://picsum.photos/id/459/128/128"`;
+
+exports[`image > 1211 > urlLoremFlickr > noArgs 1`] = `"https://loremflickr.com/640/480?lock=92852"`;
+
+exports[`image > 1211 > urlLoremFlickr > with all options 1`] = `"https://loremflickr.com/128/128/cats?lock=92852"`;
+
+exports[`image > 1211 > urlLoremFlickr > with category 1`] = `"https://loremflickr.com/640/480/cats?lock=92852"`;
+
+exports[`image > 1211 > urlLoremFlickr > with height 1`] = `"https://loremflickr.com/640/128?lock=92852"`;
+
+exports[`image > 1211 > urlLoremFlickr > with width 1`] = `"https://loremflickr.com/128/480?lock=92852"`;
+
+exports[`image > 1211 > urlLoremFlickr > with width and height 1`] = `"https://loremflickr.com/128/128?lock=92852"`;
+
+exports[`image > 1211 > urlPicsumPhotos > noArgs 1`] = `"https://picsum.photos/id/929/640/480"`;
+
+exports[`image > 1211 > urlPicsumPhotos > with all options 1`] = `"https://picsum.photos/id/929/128/128?grayscale&blur=4"`;
+
+exports[`image > 1211 > urlPicsumPhotos > with blur 1`] = `"https://picsum.photos/id/929/640/480?blur=6"`;
+
+exports[`image > 1211 > urlPicsumPhotos > with blur and grayscale 1`] = `"https://picsum.photos/id/929/640/480?grayscale&blur=3"`;
+
+exports[`image > 1211 > urlPicsumPhotos > with height 1`] = `"https://picsum.photos/id/929/640/128"`;
+
+exports[`image > 1211 > urlPicsumPhotos > with width 1`] = `"https://picsum.photos/id/929/128/480"`;
+
+exports[`image > 1211 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/id/929/128/128"`;
+
+exports[`image > 1211 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/3714x1836/db42f0/e3f4a9.jpeg?text=consequuntur%20quidem%20nobis"`;
+
+exports[`image > 1211 > urlPlaceholder > with all options 1`] = `"https://via.placeholder.com/128x128/FF0000/0000FF.png?text=hello"`;
+
+exports[`image > 1211 > urlPlaceholder > with backgroundColor 1`] = `"https://via.placeholder.com/3714x1836/FF0000/db42f0.png?text=quia%20fuga%20dolorem"`;
+
+exports[`image > 1211 > urlPlaceholder > with empty colors and text 1`] = `"https://via.placeholder.com/128x128//.png?text="`;
+
+exports[`image > 1211 > urlPlaceholder > with format 1`] = `"https://via.placeholder.com/3714x1836/db42f0/e3f4a9.webp?text=ullam%20consequuntur%20quidem"`;
+
+exports[`image > 1211 > urlPlaceholder > with height 1`] = `"https://via.placeholder.com/3714x128/adb42f/0e3f4a.jpg?text=ullam%20consequuntur%20quidem"`;
+
+exports[`image > 1211 > urlPlaceholder > with text 1`] = `"https://via.placeholder.com/3714x1836/db42f0/e3f4a9.jpeg?text=Hello"`;
+
+exports[`image > 1211 > urlPlaceholder > with textColor 1`] = `"https://via.placeholder.com/3714x1836/db42f0/0000FF.png?text=quia%20fuga%20dolorem"`;
+
+exports[`image > 1211 > urlPlaceholder > with width 1`] = `"https://via.placeholder.com/128x3714/adb42f/0e3f4a.jpg?text=ullam%20consequuntur%20quidem"`;
+
+exports[`image > 1211 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/eadb42/f0e3f4.png?text=autem%20ullam%20consequuntur"`;
+
+exports[`image > 1337 > avatar 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/700.jpg"`;
+
+exports[`image > 1337 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/26202467"`;
+
+exports[`image > 1337 > avatarLegacy 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/327.jpg"`;
+
+exports[`image > 1337 > url > noArgs 1`] = `"https://loremflickr.com/640/480?lock=56052"`;
+
+exports[`image > 1337 > url > with height 1`] = `"https://loremflickr.com/640/128?lock=56052"`;
+
+exports[`image > 1337 > url > with width 1`] = `"https://loremflickr.com/128/480?lock=56052"`;
+
+exports[`image > 1337 > url > with width and height 1`] = `"https://loremflickr.com/128/128?lock=56052"`;
+
+exports[`image > 1337 > urlLoremFlickr > noArgs 1`] = `"https://loremflickr.com/640/480?lock=26202"`;
+
+exports[`image > 1337 > urlLoremFlickr > with all options 1`] = `"https://loremflickr.com/128/128/cats?lock=26202"`;
+
+exports[`image > 1337 > urlLoremFlickr > with category 1`] = `"https://loremflickr.com/640/480/cats?lock=26202"`;
+
+exports[`image > 1337 > urlLoremFlickr > with height 1`] = `"https://loremflickr.com/640/128?lock=26202"`;
+
+exports[`image > 1337 > urlLoremFlickr > with width 1`] = `"https://loremflickr.com/128/480?lock=26202"`;
+
+exports[`image > 1337 > urlLoremFlickr > with width and height 1`] = `"https://loremflickr.com/128/128?lock=26202"`;
+
+exports[`image > 1337 > urlPicsumPhotos > noArgs 1`] = `"https://picsum.photos/id/262/640/480"`;
+
+exports[`image > 1337 > urlPicsumPhotos > with all options 1`] = `"https://picsum.photos/id/262/128/128?grayscale&blur=4"`;
+
+exports[`image > 1337 > urlPicsumPhotos > with blur 1`] = `"https://picsum.photos/id/262/640/480?blur=6"`;
+
+exports[`image > 1337 > urlPicsumPhotos > with blur and grayscale 1`] = `"https://picsum.photos/id/262/640/480?grayscale&blur=3"`;
+
+exports[`image > 1337 > urlPicsumPhotos > with height 1`] = `"https://picsum.photos/id/262/640/128"`;
+
+exports[`image > 1337 > urlPicsumPhotos > with width 1`] = `"https://picsum.photos/id/262/128/480"`;
+
+exports[`image > 1337 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/id/262/128/128"`;
+
+exports[`image > 1337 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/1048x2242/346ba0/75bd57.webp?text=tempora%20tempore%20aliquam"`;
+
+exports[`image > 1337 > urlPlaceholder > with all options 1`] = `"https://via.placeholder.com/128x128/FF0000/0000FF.png?text=hello"`;
+
+exports[`image > 1337 > urlPlaceholder > with backgroundColor 1`] = `"https://via.placeholder.com/1048x2242/FF0000/346ba0.jpeg?text=consectetur%20totam%20provident"`;
+
+exports[`image > 1337 > urlPlaceholder > with empty colors and text 1`] = `"https://via.placeholder.com/128x128//.png?text="`;
+
+exports[`image > 1337 > urlPlaceholder > with format 1`] = `"https://via.placeholder.com/1048x2242/346ba0/75bd57.webp?text=voluptatibus%20tempora%20tempore"`;
+
+exports[`image > 1337 > urlPlaceholder > with height 1`] = `"https://via.placeholder.com/1048x128/c346ba/075bd5.jpeg?text=voluptatibus%20tempora%20tempore"`;
+
+exports[`image > 1337 > urlPlaceholder > with text 1`] = `"https://via.placeholder.com/1048x2242/346ba0/75bd57.webp?text=Hello"`;
+
+exports[`image > 1337 > urlPlaceholder > with textColor 1`] = `"https://via.placeholder.com/1048x2242/346ba0/0000FF.jpeg?text=consectetur%20totam%20provident"`;
+
+exports[`image > 1337 > urlPlaceholder > with width 1`] = `"https://via.placeholder.com/128x1048/c346ba/075bd5.jpeg?text=voluptatibus%20tempora%20tempore"`;
+
+exports[`image > 1337 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/5c346b/a075bd.jpeg?text=veniam%20voluptatibus%20tempora"`;
+
+exports[`image > dataUri > should return a background color data URI 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%22200%22%20height%3D%22300%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22red%22%2F%3E%3Ctext%20x%3D%22100%22%20y%3D%22150%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E200x300%3C%2Ftext%3E%3C%2Fsvg%3E"`;
+
+exports[`image > dataUri > should return a blank data 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%22200%22%20height%3D%22300%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22grey%22%2F%3E%3Ctext%20x%3D%22100%22%20y%3D%22150%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E200x300%3C%2Ftext%3E%3C%2Fsvg%3E"`;
diff --git a/test/image.spec.ts b/test/image.spec.ts
index b38edae8e82..8ec9b05e287 100644
--- a/test/image.spec.ts
+++ b/test/image.spec.ts
@@ -1,7 +1,91 @@
import { describe, expect, it } from 'vitest';
import { faker } from '../src';
+import { seededTests } from './support/seededRuns';
describe('image', () => {
+ seededTests(faker, 'image', (t) => {
+ t.itEach('avatar', 'avatarGitHub', 'avatarLegacy');
+
+ t.describe('url', (t) => {
+ t.it('noArgs')
+ .it('with width', { width: 128 })
+ .it('with height', { height: 128 })
+ .it('with width and height', { width: 128, height: 128 });
+ });
+
+ t.describe('urlLoremFlickr', (t) => {
+ t.it('noArgs')
+ .it('with width', { width: 128 })
+ .it('with height', { height: 128 })
+ .it('with width and height', { width: 128, height: 128 })
+ .it('with category', { category: 'cats' })
+ .it('with all options', {
+ width: 128,
+ height: 128,
+ category: 'cats',
+ });
+ });
+
+ t.describe('urlPicsumPhotos', (t) => {
+ t.it('noArgs')
+ .it('with width', { width: 128 })
+ .it('with height', { height: 128 })
+ .it('with width and height', { width: 128, height: 128 })
+ .it('with blur', { blur: 6 })
+ .it('with blur and grayscale', { blur: 3, grayscale: true })
+ .it('with all options', {
+ width: 128,
+ height: 128,
+ blur: 4,
+ grayscale: true,
+ });
+ });
+
+ t.describe('urlPlaceholder', (t) => {
+ t.it('noArgs')
+ .it('with width', { width: 128 })
+ .it('with height', { height: 128 })
+ .it('with width and height', { width: 128, height: 128 })
+ .it('with backgroundColor', { backgroundColor: 'FF0000' })
+ .it('with textColor', { textColor: '0000FF' })
+ .it('with format', { format: 'webp' })
+ .it('with text', { text: 'Hello' })
+ .it('with all options', {
+ width: 128,
+ height: 128,
+ backgroundColor: 'FF0000',
+ textColor: '0000FF',
+ format: 'png',
+ text: 'hello',
+ })
+ .it('with empty colors and text', {
+ width: 128,
+ height: 128,
+ backgroundColor: '',
+ textColor: '',
+ format: 'png',
+ text: '',
+ });
+ });
+
+ t.skip('abstract');
+ t.skip('animals');
+ t.skip('business');
+ t.skip('cats');
+ t.skip('city');
+ t.skip('dataUri');
+ t.skip('fashion');
+ t.skip('food');
+ t.skip('image');
+ t.skip('imageUrl');
+ t.skip('nature');
+ t.skip('nightlife');
+ t.skip('people');
+ t.skip('sports');
+ t.skip('technics');
+ t.skip('transport');
+ });
+
describe('lorempicsum', () => {
describe('imageUrl()', () => {
it('should return a random image url from lorempixel', () => {
@@ -329,19 +413,126 @@ describe('image', () => {
});
});
- describe('dataUri', () => {
- it('should return a blank data', () => {
- const dataUri = faker.image.dataUri(200, 300);
- expect(dataUri).toBe(
- '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%22200%22%20height%3D%22300%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22grey%22%2F%3E%3Ctext%20x%3D%22100%22%20y%3D%22150%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E200x300%3C%2Ftext%3E%3C%2Fsvg%3E'
+ describe('avatar', () => {
+ it('should return a random avatar url', () => {
+ const avatarUrl = faker.image.avatar();
+
+ expect(avatarUrl).toBeTypeOf('string');
+ expect(avatarUrl).toMatch(/^https:\/\//);
+ expect(() => new URL(avatarUrl)).not.toThrow();
+ });
+ });
+
+ describe('avatarGitHub', () => {
+ it('should return a random avatar url from GitHub', () => {
+ const avatarUrl = faker.image.avatarGitHub();
+
+ expect(avatarUrl).toBeTypeOf('string');
+ expect(avatarUrl).toMatch(
+ /^https:\/\/avatars\.githubusercontent\.com\/u\/\d+$/
+ );
+ });
+ });
+
+ describe('avatarLegacy', () => {
+ it('should return a random avatar url from cloudflare-ipfs', () => {
+ const avatarUrl = faker.image.avatarLegacy();
+
+ expect(avatarUrl).toBeTypeOf('string');
+ expect(avatarUrl).toMatch(
+ /^https:\/\/cloudflare\-ipfs\.com\/ipfs\/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye\/avatar\/\d{1,4}\.jpg$/
+ );
+ });
+ });
+
+ describe('url', () => {
+ it('should return a random image url', () => {
+ const imageUrl = faker.image.url();
+
+ expect(imageUrl).toBeTypeOf('string');
+ expect(imageUrl).toMatch(/^https:\/\//);
+ expect(() => new URL(imageUrl)).not.toThrow();
+ });
+
+ it('should return a random image url with a width', () => {
+ const width = 100;
+ const imageUrl = faker.image.url({ width });
+
+ expect(imageUrl).toBeTypeOf('string');
+ expect(imageUrl).toMatch(/^https:\/\//);
+ expect(() => new URL(imageUrl)).not.toThrow();
+ expect(imageUrl).include(`${width}`);
+ });
+
+ it('should return a random image url with a height', () => {
+ const height = 100;
+ const imageUrl = faker.image.url({ height });
+
+ expect(imageUrl).toBeTypeOf('string');
+ expect(imageUrl).toMatch(/^https:\/\//);
+ expect(() => new URL(imageUrl)).not.toThrow();
+ expect(imageUrl).include(`${height}`);
+ });
+
+ it('should return a random image url with a width and height', () => {
+ const width = 128;
+ const height = 64;
+ const imageUrl = faker.image.url({ width, height });
+
+ expect(imageUrl).toBeTypeOf('string');
+ expect(imageUrl).toMatch(/^https:\/\//);
+ expect(() => new URL(imageUrl)).not.toThrow();
+ expect(imageUrl).include(`${width}`);
+ expect(imageUrl).include(`${height}`);
+ });
+ });
+
+ describe('urlLoremFlickr', () => {
+ it('should return a random image url from LoremFlickr', () => {
+ const imageUrl = faker.image.urlLoremFlickr();
+
+ expect(imageUrl).toBeTypeOf('string');
+ expect(imageUrl).toMatch(
+ /^https\:\/\/loremflickr\.com\/\d+\/\d+\?lock=\d+$/
);
});
+ });
- it('should return a custom background color data URI', () => {
- const dataUri = faker.image.dataUri(200, 300, 'red');
- expect(dataUri).toBe(
- '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%22200%22%20height%3D%22300%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22red%22%2F%3E%3Ctext%20x%3D%22100%22%20y%3D%22150%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E200x300%3C%2Ftext%3E%3C%2Fsvg%3E'
+ describe('urlPicsumPhotos', () => {
+ it('should return a random image url from PicsumPhotos', () => {
+ const imageUrl = faker.image.urlPicsumPhotos();
+
+ expect(imageUrl).toBeTypeOf('string');
+ expect(imageUrl).toMatch(
+ /^https\:\/\/picsum\.photos\/id\/\d+\/\d+\/\d+$/
);
});
});
+
+ describe('urlPlaceholder', () => {
+ it('should return a random image url from Placeholder', () => {
+ const imageUrl = faker.image.urlPlaceholder();
+
+ expect(imageUrl).toBeTypeOf('string');
+ expect(imageUrl).toMatch(
+ /^https\:\/\/via\.placeholder\.com\/\d+x\d+\/[0-9a-fA-F]{6}\/[0-9a-fA-F]{6}\.[a-z]{3,4}\?text=.+$/
+ );
+ });
+ });
+
+ describe('dataUri', () => {
+ it('should return a blank data', () => {
+ const dataUri = faker.image.dataUri({ width: 200, height: 300 });
+ expect(dataUri).toMatchSnapshot();
+ });
+
+ it('should return a background color data URI', () => {
+ const dataUri = faker.image.dataUri({
+ width: 200,
+ height: 300,
+ color: 'red',
+ });
+ expect(dataUri).toMatchSnapshot();
+ });
+ });
});