diff --git a/docs/guide/upgrading.md b/docs/guide/upgrading.md index d5833e5066e..204ef067e18 100644 --- a/docs/guide/upgrading.md +++ b/docs/guide/upgrading.md @@ -34,6 +34,7 @@ Not the version you are looking for? | `faker.address.citySuffix` | _Removed_ | | `faker.address.streetPrefix` | _Removed_ | | `faker.address.streetSuffix` | _Removed_ | +| `faker.image.lorempixel` | _Removed, as the LoremPixel service is no longer available_ | ### Locale renamed diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 6beae600f4f..cf59627db46 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -2,7 +2,6 @@ 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'; import { Placeholder } from './providers/placeholder'; import { Unsplash } from './providers/unsplash'; @@ -10,11 +9,6 @@ import { Unsplash } from './providers/unsplash'; * Module to generate images. */ export class ImageModule { - /** - * @deprecated Use `faker.image` instead. - */ - readonly lorempixel: Lorempixel; - /** * @deprecated Use `faker.image` instead. */ @@ -39,7 +33,6 @@ export class ImageModule { this[name] = this[name].bind(this); } - this.lorempixel = new Lorempixel(this.faker); this.unsplash = new Unsplash(this.faker); this.lorempicsum = new LoremPicsum(this.faker); this.placeholder = new Placeholder(this.faker); diff --git a/src/modules/image/providers/lorempixel.ts b/src/modules/image/providers/lorempixel.ts deleted file mode 100644 index ac80a8d7d30..00000000000 --- a/src/modules/image/providers/lorempixel.ts +++ /dev/null @@ -1,399 +0,0 @@ -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) {} - - /** - * Generates a new lorempixel image url for a random supported category. - * - * @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', - 'business', - 'cats', - 'city', - 'food', - 'nightlife', - 'fashion', - 'people', - 'nature', - 'sports', - 'technics', - 'transport', - ]; - return this[this.faker.helpers.arrayElement(categories)]( - width, - height, - randomize - ); - } - - /** - * Generates a new lorempixel image url. - * - * @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 randomize Whether to append a seed to the url. Defaults to `false`. - * - * @deprecated Use `faker.image` instead. - */ - imageUrl( - width?: number, - height?: number, - 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; - - let url = `https://lorempixel.com/${width}/${height}`; - if (category != null) { - url += `/${category}`; - } - - if (randomize) { - url += `?${this.faker.number.int()}`; - } - - return url; - } - - /** - * Generates a new lorempixel image url using the "abstract" category. - * - * @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, - 'abstract', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "animals" category. - * - * @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, - 'animals', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "business" category. - * - * @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, - 'business', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "cats" category. - * - * @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, - 'cats', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "city" category. - * - * @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, - 'city', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "food" category. - * - * @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, - 'food', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "nightlife" category. - * - * @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, - 'nightlife', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "fashion" category. - * - * @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, - 'fashion', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "people" category. - * - * @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, - 'people', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "nature" category. - * - * @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, - 'nature', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "sports" category. - * - * @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, - 'sports', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "technics" category. - * - * @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, - 'technics', - randomize - ); - } - - /** - * Generates a new lorempixel image url using the "transport" category. - * - * @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, - 'transport', - randomize - ); - } -} diff --git a/test/image.spec.ts b/test/image.spec.ts index 8ec9b05e287..9cc8f5000de 100644 --- a/test/image.spec.ts +++ b/test/image.spec.ts @@ -88,7 +88,7 @@ describe('image', () => { describe('lorempicsum', () => { describe('imageUrl()', () => { - it('should return a random image url from lorempixel', () => { + it('should return a random image url from lorem picsum', () => { const imageUrl = faker.image.lorempicsum.imageUrl(); expect(imageUrl).toBe('https://picsum.photos/640/480'); @@ -167,53 +167,6 @@ describe('image', () => { }); }); - describe('lorempixel', () => { - describe('imageUrl()', () => { - it('should return a random image url from lorempixel', () => { - const imageUrl = faker.image.lorempixel.imageUrl(); - - expect(imageUrl).toBe('https://lorempixel.com/640/480'); - }); - - it('should return a random image url from lorempixel with width and height', () => { - const imageUrl = faker.image.lorempixel.imageUrl(100, 100); - - expect(imageUrl).toBe('https://lorempixel.com/100/100'); - }); - - it('should return a random image url for a specified category', () => { - const imageUrl = faker.image.lorempixel.imageUrl(100, 100, 'abstract'); - - expect(imageUrl).toBe('https://lorempixel.com/100/100/abstract'); - }); - }); - - const categories = [ - 'abstract', - 'animals', - 'business', - 'cats', - 'city', - 'food', - 'nightlife', - 'fashion', - 'people', - 'nature', - 'sports', - 'technics', - 'transport', - ]; - - for (const category of categories) { - describe(`${category}()`, () => { - it(`should return a random ${category} image url`, () => { - const actual = faker.image.lorempixel[category](); - expect(actual).toBe(`https://lorempixel.com/640/480/${category}`); - }); - }); - } - }); - describe('unsplash', () => { describe('imageUrl()', () => { it('should return a random image url from unsplash', () => {