From 5ebfbb8744174b489078f2726b32b7062a47069e Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Mon, 29 Jan 2024 20:19:37 +0100 Subject: [PATCH 1/4] refactor(image)!: remove v8 deprecated providers --- docs/guide/upgrading_v9/2634.md | 3 + src/modules/image/index.ts | 33 --- src/modules/image/providers/lorempicsum.ts | 169 ------------- src/modules/image/providers/placeholder.ts | 129 ---------- src/modules/image/providers/unsplash.ts | 221 ----------------- test/modules/image.spec.ts | 276 --------------------- 6 files changed, 3 insertions(+), 828 deletions(-) create mode 100644 docs/guide/upgrading_v9/2634.md delete mode 100644 src/modules/image/providers/lorempicsum.ts delete mode 100644 src/modules/image/providers/placeholder.ts delete mode 100644 src/modules/image/providers/unsplash.ts diff --git a/docs/guide/upgrading_v9/2634.md b/docs/guide/upgrading_v9/2634.md new file mode 100644 index 00000000000..628eb412d41 --- /dev/null +++ b/docs/guide/upgrading_v9/2634.md @@ -0,0 +1,3 @@ +### Remove deprecated image providers + +Removed deprecated image providers from `faker.image`. diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index f2c3c9d0d5d..c87cc5f7b4b 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. @@ -20,35 +16,6 @@ import { Unsplash } from './providers/unsplash'; * This module previously also contained methods for specifically themed images like "fashion" or "food", but these are now deprecated. If you need more control over image type, you can request categorized images using [`urlLoremFlickr()`](https://fakerjs.dev/api/image.html#urlloremflickr), use an image provider directly or provide your own set of placeholder images. */ 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. * diff --git a/src/modules/image/providers/lorempicsum.ts b/src/modules/image/providers/lorempicsum.ts deleted file mode 100644 index 6e19b6e1ed7..00000000000 --- 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 c7514f23a83..00000000000 --- 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) { - 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 a2b4ee0e16a..00000000000 --- 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 004905e7d7f..66cb5c3ed38 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; - - 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(); From a944651754532bf86e354d96199361d4984ad5b5 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Fri, 9 Feb 2024 19:21:19 +0100 Subject: [PATCH 2/4] add deprecation table --- docs/guide/upgrading_v9/2634.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/guide/upgrading_v9/2634.md b/docs/guide/upgrading_v9/2634.md index 628eb412d41..28e345b83a4 100644 --- a/docs/guide/upgrading_v9/2634.md +++ b/docs/guide/upgrading_v9/2634.md @@ -1,3 +1,21 @@ ### Remove deprecated image providers Removed deprecated image providers from `faker.image`. + +| old | replacement | +| ----------------------------------- | --------------------------- | +| faker.lorempicsum.image | faker.image.urlPicsumPhotos | +| faker.lorempicsum.imageGrayscale | faker.image.urlPicsumPhotos | +| faker.lorempicsum.imageBlurred | faker.image.urlPicsumPhotos | +| faker.lorempicsum.imageRandomSeeded | faker.image.urlPicsumPhotos | +| faker.lorempicsum.imageUrl | faker.image.urlPicsumPhotos | +| faker.placeholder.imageUrl | faker.image.urlPlaceholder | +| faker.placeholder.randomUrl | faker.image.urlPlaceholder | +| faker.unsplash.image | faker.image.url | +| faker.unsplash.imageUrl | faker.image.url | +| faker.unsplash.food | faker.image.url | +| faker.unsplash.people | faker.image.url | +| faker.unsplash.nature | faker.image.url | +| faker.unsplash.technology | faker.image.url | +| faker.unsplash.objects | faker.image.url | +| faker.unsplash.buildings | faker.image.url | From 5b6aec4eec2c10d206479411e81f8c809ccf4cd0 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Sat, 10 Feb 2024 10:11:34 +0100 Subject: [PATCH 3/4] update table --- docs/guide/upgrading_v9/2634.md | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/guide/upgrading_v9/2634.md b/docs/guide/upgrading_v9/2634.md index 28e345b83a4..aba30fab511 100644 --- a/docs/guide/upgrading_v9/2634.md +++ b/docs/guide/upgrading_v9/2634.md @@ -2,20 +2,20 @@ Removed deprecated image providers from `faker.image`. -| old | replacement | -| ----------------------------------- | --------------------------- | -| faker.lorempicsum.image | faker.image.urlPicsumPhotos | -| faker.lorempicsum.imageGrayscale | faker.image.urlPicsumPhotos | -| faker.lorempicsum.imageBlurred | faker.image.urlPicsumPhotos | -| faker.lorempicsum.imageRandomSeeded | faker.image.urlPicsumPhotos | -| faker.lorempicsum.imageUrl | faker.image.urlPicsumPhotos | -| faker.placeholder.imageUrl | faker.image.urlPlaceholder | -| faker.placeholder.randomUrl | faker.image.urlPlaceholder | -| faker.unsplash.image | faker.image.url | -| faker.unsplash.imageUrl | faker.image.url | -| faker.unsplash.food | faker.image.url | -| faker.unsplash.people | faker.image.url | -| faker.unsplash.nature | faker.image.url | -| faker.unsplash.technology | faker.image.url | -| faker.unsplash.objects | faker.image.url | -| faker.unsplash.buildings | faker.image.url | +| 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' }) | From 82a0f669cb29eec8620a985f8a71767065bd6fce Mon Sep 17 00:00:00 2001 From: Shinigami Date: Sun, 11 Feb 2024 19:11:07 +0100 Subject: [PATCH 4/4] Update docs/guide/upgrading_v9/2634.md --- docs/guide/upgrading_v9/2634.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/upgrading_v9/2634.md b/docs/guide/upgrading_v9/2634.md index aba30fab511..b072d4a7cf9 100644 --- a/docs/guide/upgrading_v9/2634.md +++ b/docs/guide/upgrading_v9/2634.md @@ -1,6 +1,6 @@ ### Remove deprecated image providers -Removed deprecated image providers from `faker.image`. +Removed deprecated image providers from `faker.image`. They already returned broken image URLs anyways. | old | replacement | | ----------------------------------------- | ------------------------------------------------------ |