aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinigami <[email protected]>2024-02-14 20:36:10 +0100
committerGitHub <[email protected]>2024-02-14 19:36:10 +0000
commit44d698e14f48a32259fd52a39d1e3028f84f3c06 (patch)
tree60848928995797018024907cd3daa0aefdd61065
parentc96176b359c98c60f3519579dc6fff855e4c3c20 (diff)
downloadfaker-44d698e14f48a32259fd52a39d1e3028f84f3c06.tar.xz
faker-44d698e14f48a32259fd52a39d1e3028f84f3c06.zip
refactor(image)!: remove v8 deprecated providers (#2634)
-rw-r--r--docs/guide/upgrading_v9/2634.md21
-rw-r--r--src/modules/image/index.ts33
-rw-r--r--src/modules/image/providers/lorempicsum.ts169
-rw-r--r--src/modules/image/providers/placeholder.ts129
-rw-r--r--src/modules/image/providers/unsplash.ts221
-rw-r--r--test/modules/image.spec.ts276
6 files changed, 21 insertions, 828 deletions
diff --git a/docs/guide/upgrading_v9/2634.md b/docs/guide/upgrading_v9/2634.md
new file mode 100644
index 00000000..b072d4a7
--- /dev/null
+++ b/docs/guide/upgrading_v9/2634.md
@@ -0,0 +1,21 @@
+### Remove deprecated image providers
+
+Removed deprecated image providers from `faker.image`. They already returned broken image URLs anyways.
+
+| old | replacement |
+| ----------------------------------------- | ------------------------------------------------------ |
+| faker.image.lorempicsum.image | faker.image.urlPicsumPhotos |
+| faker.image.lorempicsum.imageGrayscale | faker.image.urlPicsumPhotos({ grayscale: true }) |
+| faker.image.lorempicsum.imageBlurred | faker.image.urlPicsumPhotos({ blur: 4 }) |
+| faker.image.lorempicsum.imageRandomSeeded | faker.image.urlPicsumPhotos |
+| faker.image.lorempicsum.imageUrl | faker.image.urlPicsumPhotos |
+| faker.image.placeholder.imageUrl | faker.image.urlPlaceholder |
+| faker.image.placeholder.randomUrl | faker.image.urlPlaceholder |
+| faker.image.unsplash.image | faker.image.url |
+| faker.image.unsplash.imageUrl | faker.image.url |
+| faker.image.unsplash.food | faker.image.urlLoremFlickr({ category: 'food' }) |
+| faker.image.unsplash.people | faker.image.urlLoremFlickr({ category: 'people' }) |
+| faker.image.unsplash.nature | faker.image.urlLoremFlickr({ category: 'nature' }) |
+| faker.image.unsplash.technology | faker.image.urlLoremFlickr({ category: 'technology' }) |
+| faker.image.unsplash.objects | faker.image.urlLoremFlickr({ category: 'objects' }) |
+| faker.image.unsplash.buildings | faker.image.urlLoremFlickr({ category: 'buildings' }) |
diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts
index 1a26065d..46bc06e4 100644
--- a/src/modules/image/index.ts
+++ b/src/modules/image/index.ts
@@ -1,10 +1,6 @@
-import type { Faker } from '../..';
import { deprecated } from '../../internal/deprecated';
import { ModuleBase } from '../../internal/module-base';
import type { MethodsOf } from '../../utils/types';
-import { LoremPicsum } from './providers/lorempicsum';
-import { Placeholder } from './providers/placeholder';
-import { Unsplash } from './providers/unsplash';
/**
* Module to generate images.
@@ -21,35 +17,6 @@ import { Unsplash } from './providers/unsplash';
*/
export class ImageModule extends ModuleBase {
/**
- * @deprecated Use `faker.image` instead.
- */
- // eslint-disable-next-line deprecation/deprecation
- readonly unsplash: Unsplash;
-
- /**
- * @deprecated Use `faker.image` instead.
- */
- // eslint-disable-next-line deprecation/deprecation
- readonly lorempicsum: LoremPicsum;
-
- /**
- * @deprecated Use `faker.image.urlPlaceholder` instead.
- */
- // eslint-disable-next-line deprecation/deprecation
- readonly placeholder: Placeholder;
-
- constructor(faker: Faker) {
- super(faker);
-
- // eslint-disable-next-line deprecation/deprecation
- this.unsplash = new Unsplash(this.faker);
- // eslint-disable-next-line deprecation/deprecation
- this.lorempicsum = new LoremPicsum(this.faker);
- // eslint-disable-next-line deprecation/deprecation
- this.placeholder = new Placeholder(this.faker);
- }
-
- /**
* Generates a random avatar image url.
*
* @example
diff --git a/src/modules/image/providers/lorempicsum.ts b/src/modules/image/providers/lorempicsum.ts
deleted file mode 100644
index 6e19b6e1..00000000
--- a/src/modules/image/providers/lorempicsum.ts
+++ /dev/null
@@ -1,169 +0,0 @@
-/* eslint-disable deprecation/deprecation */
-import type { Faker } from '../../..';
-import { deprecated } from '../../../internal/deprecated';
-
-/**
- * Module to generate links to random images on https://picsum.photos.
- *
- * The images generated from this module are fetched from an external service outside the control of Faker and could occasionally contain URLs which are broken or point to unexpected, disturbing, or offensive images. The service may also be subject to usage limits.
- *
- * @deprecated Use `faker.image.urlPicsumPhotos` instead.
- */
-export class LoremPicsum {
- constructor(private readonly faker: Faker) {}
-
- /**
- * Generates a new picsum photos image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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,
- height?: number,
- 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 photos image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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 photos image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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 photos image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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,
- height?: number,
- grayscale?: boolean,
- 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 missing?
- return this.imageUrl(width, height, grayscale, blur, seed);
- }
-
- /**
- * Generates a new picsum photos image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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,
- height?: number,
- grayscale?: boolean,
- 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;
-
- let url = 'https://picsum.photos';
-
- if (seed) {
- url += `/seed/${seed}`;
- }
-
- url += `/${width}/${height}`;
-
- if (grayscale && blur) {
- return `${url}?grayscale&blur=${blur}`;
- }
-
- if (grayscale) {
- return `${url}?grayscale`;
- }
-
- if (blur) {
- return `${url}?blur=${blur}`;
- }
-
- return url;
- }
-}
diff --git a/src/modules/image/providers/placeholder.ts b/src/modules/image/providers/placeholder.ts
deleted file mode 100644
index c7514f23..00000000
--- a/src/modules/image/providers/placeholder.ts
+++ /dev/null
@@ -1,129 +0,0 @@
-/* eslint-disable deprecation/deprecation */
-import type { Faker } from '../../..';
-import { deprecated } from '../../../internal/deprecated';
-
-/**
- * Module to generate links to images on `https://via.placeholder.com/`.
- *
- * The images generated from this module are fetched from an external service outside the control of Faker and could occasionally contain URLs which are broken or point to unexpected, disturbing, or offensive images. The service may also be subject to usage limits.
- *
- * @deprecated Use `faker.image.urlPlaceholder` instead.
- */
-export class Placeholder {
- constructor(private readonly faker: Faker) {
- // Bind `this` so namespaced is working correctly
- for (const name of Object.getOwnPropertyNames(
- Placeholder.prototype
- ) as Array<keyof Placeholder | 'constructor'>) {
- if (name === 'constructor' || typeof this[name] !== 'function') {
- continue;
- }
-
- this[name] = this[name].bind(this);
- }
- }
-
- /**
- * Generates a new placeholder image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image (in pixels). Defaults to `640`.
- * @param height The height of the image (in pixels). Defaults to `width`.
- * @param text The text of the image.
- * @param format The file format of the image. Supports `png`, `jpeg`, `png`, `gif`, `webp`.
- * @param backgroundColor The background color of the placeholder. Supports HEX CODE format.
- * @param textColor The text color of the placeholder. Requires `backgroundColor`. Supports HEX CODE format.
- *
- * @example
- * faker.image.placeholder.imageUrl() // https://via.placeholder.com/640x640
- * faker.image.placeholder.imageUrl(200) // https://via.placeholder.com/200x200
- * faker.image.placeholder.imageUrl(200, 100) // https://via.placeholder.com/200x100
- * faker.image.placeholder.imageUrl(200, 100, 'Fish') // https://via.placeholder.com/200x100?text=Fish
- * faker.image.placeholder.imageUrl(200, 100, 'Fish', 'webp') // https://via.placeholder.com/200x100.webp?text=Fish
- * 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,
- height?: number,
- text?: string,
- format?: 'png' | 'jpeg' | 'jpg' | 'gif' | 'webp',
- 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;
-
- let url = 'https://via.placeholder.com';
- url += `/${width}x${height}`;
-
- if (backgroundColor != null) {
- url += `/${backgroundColor.replace('#', '').toUpperCase()}`;
-
- if (textColor != null) {
- url += `/${textColor.replace('#', '').toUpperCase()}`;
- }
- }
-
- if (format != null) {
- url += `.${format}`;
- }
-
- if (text != null) {
- const urlParam = new URLSearchParams({ text });
- url += `?${urlParam.toString()}`;
- }
-
- return url;
- }
-
- /**
- * Generate a new placeholder image with random colors and text.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image (in pixels). Defaults to `640`.
- * @param height The height of the image (in pixels). Defaults to `width`.
- * @param format The file format of the image. Supports `png` `jpeg` `png` `gif` `webp`.
- *
- * @example
- * faker.image.placeholder.randomUrl() // https://via.placeholder.com/640x640/000000/ffffff?text=lorum
- * 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,
- this.faker.lorem.word(),
- format,
- this.faker.color.rgb({
- casing: 'upper',
- prefix: '',
- }),
- this.faker.color.rgb({ casing: 'upper', prefix: '' })
- );
- }
-}
diff --git a/src/modules/image/providers/unsplash.ts b/src/modules/image/providers/unsplash.ts
deleted file mode 100644
index a2b4ee0e..00000000
--- a/src/modules/image/providers/unsplash.ts
+++ /dev/null
@@ -1,221 +0,0 @@
-/* eslint-disable deprecation/deprecation */
-import type { Faker } from '../../..';
-import { deprecated } from '../../../internal/deprecated';
-
-/**
- * Module to generate links to random images on `https://source.unsplash.com/`.
- *
- * The images generated from this module are fetched from an external service outside the control of Faker and could occasionally contain URLs which are broken or point to unexpected, disturbing, or offensive images. The service may also be subject to usage limits.
- *
- * @deprecated Use `faker.image` instead.
- */
-export class Unsplash {
- constructor(private readonly faker: Faker) {}
-
- /**
- * Generates a new unsplash image url for a random supported category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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);
- }
-
- /**
- * Generates a new unsplash image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image. Defaults to `640`.
- * @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,
- height?: number,
- 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;
-
- let url = 'https://source.unsplash.com';
-
- if (category != null) {
- url += `/category/${category}`;
- }
-
- url += `/${width}x${height}`;
-
- if (keyword != null) {
- const keywordFormat = /^([A-Za-z0-9].+,[A-Za-z0-9]+)$|^([A-Za-z0-9]+)$/;
- if (keywordFormat.test(keyword)) {
- url += `?${keyword}`;
- }
- }
-
- return url;
- }
-
- /**
- * Generates a new unsplash image url using the "food" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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);
- }
-
- /**
- * Generates a new unsplash image url using the "people" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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);
- }
-
- /**
- * Generates a new unsplash image url using the "nature" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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);
- }
-
- /**
- * Generates a new unsplash image url using the "technology" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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,
- 'technology',
- keyword
- );
- }
-
- /**
- * Generates a new unsplash image url using the "objects" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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,
- 'objects',
- keyword
- );
- }
-
- /**
- * Generates a new unsplash image url using the "buildings" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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,
- 'buildings',
- keyword
- );
- }
-}
diff --git a/test/modules/image.spec.ts b/test/modules/image.spec.ts
index 7499d780..c272e623 100644
--- a/test/modules/image.spec.ts
+++ b/test/modules/image.spec.ts
@@ -107,282 +107,6 @@ describe('image', () => {
t.skip('transport');
});
- describe('lorempicsum', () => {
- describe('imageUrl()', () => {
- it('should return a random image url from lorem picsum', () => {
- const imageUrl = faker.image.lorempicsum.imageUrl();
-
- expect(imageUrl).toBe('https://picsum.photos/640/480');
- });
-
- it('should return a random image url from lorem picsum with width and height', () => {
- const imageUrl = faker.image.lorempicsum.imageUrl(100, 100);
-
- expect(imageUrl).toBe('https://picsum.photos/100/100');
- });
-
- it('should return a random image url grayscaled', () => {
- const imageUrl = faker.image.lorempicsum.imageUrl(100, 100, true);
-
- expect(imageUrl).toBe('https://picsum.photos/100/100?grayscale');
- });
-
- it('should return a random image url grayscaled and blurred', () => {
- const imageUrl = faker.image.lorempicsum.imageUrl(100, 100, true, 2);
-
- expect(imageUrl).toBe('https://picsum.photos/100/100?grayscale&blur=2');
- });
-
- it('should return a random image url blurred', () => {
- const imageUrl = faker.image.lorempicsum.imageUrl(
- 100,
- 100,
- undefined,
- 2
- );
-
- expect(imageUrl).toBe('https://picsum.photos/100/100?blur=2');
- });
-
- it('should return a random image url with seed', () => {
- const imageUrl = faker.image.lorempicsum.imageUrl(
- 100,
- 100,
- undefined,
- undefined,
- 'picsum'
- );
-
- expect(imageUrl).toBe('https://picsum.photos/seed/picsum/100/100');
- });
- });
-
- describe('imageGrayscale()', () => {
- it('should return a random URL with grayscale image', () => {
- const imageUrl = faker.image.lorempicsum.imageGrayscale(100, 100, true);
-
- expect(imageUrl).toBe('https://picsum.photos/100/100?grayscale');
- });
- });
-
- describe('imageBlurred()', () => {
- it('should return a random image url blurred', () => {
- const imageUrl = faker.image.lorempicsum.imageBlurred(100, 100, 2);
-
- expect(imageUrl).toBe('https://picsum.photos/100/100?blur=2');
- });
- });
-
- describe('imageRandomSeeded()', () => {
- it('should return a random image url blurred', () => {
- const imageUrl = faker.image.lorempicsum.imageRandomSeeded(
- 100,
- 100,
- undefined,
- undefined,
- 'picsum'
- );
-
- expect(imageUrl).toBe('https://picsum.photos/seed/picsum/100/100');
- });
- });
- });
-
- describe('unsplash', () => {
- describe('imageUrl()', () => {
- it('should return a random image url from unsplash', () => {
- const imageUrl = faker.image.unsplash.imageUrl();
-
- expect(imageUrl).toBe('https://source.unsplash.com/640x480');
- });
-
- it('should return a random image url from unsplash with width and height', () => {
- const imageUrl = faker.image.unsplash.imageUrl(100, 100);
-
- expect(imageUrl).toBe('https://source.unsplash.com/100x100');
- });
-
- it('should return a random image url for a specified category', () => {
- const imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food');
-
- expect(imageUrl).toBe(
- 'https://source.unsplash.com/category/food/100x100'
- );
- });
-
- it('should return a random image url with correct keywords for a specified category', () => {
- const imageUrl = faker.image.unsplash.imageUrl(
- 100,
- 100,
- 'food',
- 'keyword1,keyword2'
- );
-
- expect(imageUrl).toBe(
- 'https://source.unsplash.com/category/food/100x100?keyword1,keyword2'
- );
- });
-
- it('should return a random image url without keyword which format is wrong for a specified category', () => {
- const imageUrl = faker.image.unsplash.imageUrl(
- 100,
- 100,
- 'food',
- 'keyword1,?ds)0123$*908932409'
- );
-
- expect(imageUrl).toBe(
- 'https://source.unsplash.com/category/food/100x100'
- );
- });
- });
-
- describe('image()', () => {
- it('should return a searching image url with keyword', () => {
- const imageUrl = faker.image.unsplash.image(
- 100,
- 200,
- 'keyword1,keyword2,keyword3'
- );
- expect(imageUrl).toBe(
- 'https://source.unsplash.com/100x200?keyword1,keyword2,keyword3'
- );
- });
- });
-
- const categories = [
- 'buildings',
- 'food',
- 'nature',
- 'objects',
- 'people',
- 'technology',
- ] satisfies Array<keyof typeof faker.image.unsplash>;
-
- describe.each(categories)(`%s()`, (category) => {
- it(`should return a random ${category} image url`, () => {
- const actual = faker.image.unsplash[category]();
- expect(actual).toBe(
- `https://source.unsplash.com/category/${category}/640x480`
- );
- });
- });
- });
-
- describe('placeholder', () => {
- describe('imageUrl()', () => {
- it('should return a random image url from placeholder', () => {
- const imageUrl = faker.image.placeholder.imageUrl();
-
- expect(imageUrl).toBe('https://via.placeholder.com/640x640');
- });
-
- it('should return a square random image url from placeholder with width and height', () => {
- const imageUrl = faker.image.placeholder.imageUrl(100);
-
- expect(imageUrl).toBe('https://via.placeholder.com/100x100');
- });
-
- it('should return a random image url with a gif format', () => {
- const imageUrl = faker.image.placeholder.imageUrl(
- 100,
- 100,
- undefined,
- 'gif'
- );
-
- expect(imageUrl).toBe('https://via.placeholder.com/100x100.gif');
- });
-
- it('should return a random image url with correct text for a specified format', () => {
- const imageUrl = faker.image.placeholder.imageUrl(
- 100,
- 100,
- 'I love food',
- 'png'
- );
-
- expect(imageUrl).toBe(
- 'https://via.placeholder.com/100x100.png?text=I+love+food'
- );
- });
-
- it('should return a random image url with specified background color and text color', () => {
- const imageUrl = faker.image.placeholder.imageUrl(
- 100,
- 100,
- undefined,
- undefined,
- '000000',
- 'ffffff'
- );
-
- expect(imageUrl).toBe(
- 'https://via.placeholder.com/100x100/000000/FFFFFF'
- );
- });
-
- it('should return a random image url with specified background color and color without the #', () => {
- const imageUrl = faker.image.placeholder.imageUrl(
- 100,
- 100,
- undefined,
- undefined,
- '#000000',
- '#ffffff'
- );
-
- expect(imageUrl).toBe(
- 'https://via.placeholder.com/100x100/000000/FFFFFF'
- );
- });
-
- it('should return a random image url given all parameter', () => {
- const imageUrl = faker.image.placeholder.imageUrl(
- 100,
- 200,
- 'I love food',
- 'jpg',
- '000000',
- 'ffffff'
- );
-
- expect(imageUrl).toBe(
- 'https://via.placeholder.com/100x200/000000/FFFFFF.jpg?text=I+love+food'
- );
- });
- });
-
- describe('randomUrl()', () => {
- it('should return a random url with specified width and height', () => {
- const imageUrl = faker.image.placeholder.randomUrl(200, 150);
-
- // https://via.placeholder.com/150/000000/FFFFFF/
- const urlSpilt = imageUrl.split('/');
-
- expect(urlSpilt[0]).toBe('https:');
- expect(urlSpilt[2]).toBe('via.placeholder.com');
- expect(urlSpilt[3]).toBe('200x150');
- expect(urlSpilt[4]).toHaveLength(6);
- expect(urlSpilt[5].split('?')[0]).toHaveLength(6);
- expect(urlSpilt[5].split('?')[1]).toContain('text=');
- });
- it('should return a random url with specified width and height and format', () => {
- const imageUrl = faker.image.placeholder.randomUrl(200, 150, 'png');
-
- const urlSpilt = imageUrl.split('/');
-
- expect(urlSpilt[0]).toBe('https:');
- expect(urlSpilt[2]).toBe('via.placeholder.com');
- expect(urlSpilt[3]).toBe('200x150');
- expect(urlSpilt[4]).toHaveLength(6);
- expect(urlSpilt[5].split('?')[0]).toHaveLength(10);
- expect(urlSpilt[5].split('?')[0]).toContain('.png');
- expect(urlSpilt[5].split('?')[1]).toContain('text=');
- });
- });
- });
-
describe('avatar', () => {
it('should return a random avatar url', () => {
const avatarUrl = faker.image.avatar();