diff --git a/docs/guide/upgrading_v9/2697.md b/docs/guide/upgrading_v9/2697.md new file mode 100644 index 00000000000..9c1d1a350b8 --- /dev/null +++ b/docs/guide/upgrading_v9/2697.md @@ -0,0 +1,21 @@ +### Remove deprecated image methods + +Removed deprecated image methods + +| old | replacement | +| ------------------------- | ------------------------------------------------------------------------------ | +| `faker.image.image()` | `faker.image.url()` | +| `faker.image.imageUrl()` | `faker.image.url()` | +| `faker.image.abstract()` | `faker.image.urlLoremFlickr({ category: 'abstract' })` or `faker.image.url()` | +| `faker.image.animals()` | `faker.image.urlLoremFlickr({ category: 'animals' })` or `faker.image.url()` | +| `faker.image.business()` | `faker.image.urlLoremFlickr({ category: 'business' })` or `faker.image.url()` | +| `faker.image.cats()` | `faker.image.urlLoremFlickr({ category: 'cats' })` or `faker.image.url()` | +| `faker.image.city()` | `faker.image.urlLoremFlickr({ category: 'city' })` or `faker.image.url()` | +| `faker.image.food()` | `faker.image.urlLoremFlickr({ category: 'food' })` or `faker.image.url()` | +| `faker.image.nightlife()` | `faker.image.urlLoremFlickr({ category: 'nightlife' })` or `faker.image.url()` | +| `faker.image.fashion()` | `faker.image.urlLoremFlickr({ category: 'fashion' })` or `faker.image.url()` | +| `faker.image.people()` | `faker.image.urlLoremFlickr({ category: 'people' })` or `faker.image.url()` | +| `faker.image.nature()` | `faker.image.urlLoremFlickr({ category: 'nature' })` or `faker.image.url()` | +| `faker.image.sports()` | `faker.image.urlLoremFlickr({ category: 'sports' })` or `faker.image.url()` | +| `faker.image.technics()` | `faker.image.urlLoremFlickr({ category: 'technics' })` or `faker.image.url()` | +| `faker.image.transport()` | `faker.image.urlLoremFlickr({ category: 'transport' })` or `faker.image.url()` | diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 46bc06e4f27..d396d5fa000 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -1,6 +1,4 @@ -import { deprecated } from '../../internal/deprecated'; import { ModuleBase } from '../../internal/module-base'; -import type { MethodsOf } from '../../utils/types'; /** * Module to generate images. @@ -389,503 +387,4 @@ export class ImageModule extends ModuleBase { 'base64' )}`; } - - /** - * Generates a random image url from one of the supported categories. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @example - * faker.image.image() // 'https://loremflickr.com/640/480/city' - * faker.image.image(1234, 2345) // 'https://loremflickr.com/1234/2345/sports' - * 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', - 'business', - 'cats', - 'city', - 'food', - 'nightlife', - 'fashion', - 'people', - 'nature', - 'sports', - 'technics', - 'transport', - ]; - return this[this.faker.helpers.arrayElement(categories)]( - width, - height, - randomize - ); - } - - /** - * Generates a random 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. By default, a random one will be selected. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @example - * faker.image.imageUrl() // 'https://loremflickr.com/640/480' - * faker.image.imageUrl(1234, 2345) // 'https://loremflickr.com/1234/2345' - * faker.image.imageUrl(1234, 2345, 'cat') // 'https://loremflickr.com/1234/2345/cat' - * 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, - height?: number, - 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}`; - if (category != null) { - url += `/${category}`; - } - - if (randomize) { - url += `?lock=${this.faker.number.int()}`; - } - - return url; - } - - /** - * Generates a random abstract image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.abstract() // 'https://loremflickr.com/640/480/abstract' - * faker.image.abstract(1234, 2345) // 'https://loremflickr.com/1234/2345/abstract' - * faker.image.abstract(1234, 2345, true) // 'https://loremflickr.com/1234/2345/abstract?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'abstract' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - * - */ - abstract(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.abstract', - proposed: - "faker.image.urlLoremFlickr({ category: 'abstract' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'abstract', randomize); - } - - /** - * Generates a random animal image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.animals() // 'https://loremflickr.com/640/480/animals' - * faker.image.animals(1234, 2345) // 'https://loremflickr.com/1234/2345/animals' - * faker.image.animals(1234, 2345, true) // 'https://loremflickr.com/1234/2345/animals?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'animals' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - * - */ - animals(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.animals', - proposed: - "faker.image.urlLoremFlickr({ category: 'animals' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'animals', randomize); - } - - /** - * Generates a random business image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.business() // 'https://loremflickr.com/640/480/business' - * faker.image.business(1234, 2345) // 'https://loremflickr.com/1234/2345/business' - * faker.image.business(1234, 2345, true) // 'https://loremflickr.com/1234/2345/business?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'business' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - * - * - */ - business(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.business', - proposed: - "faker.image.urlLoremFlickr({ category: 'business' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'business', randomize); - } - - /** - * Generates a random cat image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.cats() // 'https://loremflickr.com/640/480/cats' - * faker.image.cats(1234, 2345) // 'https://loremflickr.com/1234/2345/cats' - * faker.image.cats(1234, 2345, true) // 'https://loremflickr.com/1234/2345/cats?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'cats' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - */ - cats(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.cats', - proposed: - "faker.image.urlLoremFlickr({ category: 'cats' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'cats', randomize); - } - - /** - * Generates a random city image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.city() // 'https://loremflickr.com/640/480/city' - * faker.image.city(1234, 2345) // 'https://loremflickr.com/1234/2345/city' - * faker.image.city(1234, 2345, true) // 'https://loremflickr.com/1234/2345/city?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'city' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - */ - city(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.city', - proposed: - "faker.image.urlLoremFlickr({ category: 'city' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'city', randomize); - } - - /** - * Generates a random food image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.food() // 'https://loremflickr.com/640/480/food' - * faker.image.food(1234, 2345) // 'https://loremflickr.com/1234/2345/food' - * faker.image.food(1234, 2345, true) // 'https://loremflickr.com/1234/2345/food?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'food' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - */ - food(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.food', - proposed: - "faker.image.urlLoremFlickr({ category: 'food' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'food', randomize); - } - - /** - * Generates a random nightlife image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.nightlife() // 'https://loremflickr.com/640/480/nightlife' - * faker.image.nightlife(1234, 2345) // 'https://loremflickr.com/1234/2345/nightlife' - * faker.image.nightlife(1234, 2345, true) // 'https://loremflickr.com/1234/2345/nightlife?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'nightlife' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - */ - nightlife(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.nightlife', - proposed: - "faker.image.urlLoremFlickr({ category: 'nightlife' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'nightlife', randomize); - } - - /** - * Generates a random fashion image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.fashion() // 'https://loremflickr.com/640/480/fashion' - * faker.image.fashion(1234, 2345) // 'https://loremflickr.com/1234/2345/fashion' - * faker.image.fashion(1234, 2345, true) // 'https://loremflickr.com/1234/2345/fashion?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'fashion' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - */ - fashion(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.fashion', - proposed: - "faker.image.urlLoremFlickr({ category: 'fashion' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'fashion', randomize); - } - - /** - * Generates a random people image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.people() // 'https://loremflickr.com/640/480/people' - * faker.image.people(1234, 2345) // 'https://loremflickr.com/1234/2345/people' - * faker.image.people(1234, 2345, true) // 'https://loremflickr.com/1234/2345/people?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'people' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - */ - people(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.people', - proposed: - "faker.image.urlLoremFlickr({ category: 'people' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'people', randomize); - } - - /** - * Generates a random nature image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.nature() // 'https://loremflickr.com/640/480/nature' - * faker.image.nature(1234, 2345) // 'https://loremflickr.com/1234/2345/nature' - * faker.image.nature(1234, 2345, true) // 'https://loremflickr.com/1234/2345/nature?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'nature' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - */ - nature(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.nature', - proposed: - "faker.image.urlLoremFlickr({ category: 'nature' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'nature', randomize); - } - - /** - * Generates a random sports image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.sports() // 'https://loremflickr.com/640/480/sports' - * faker.image.sports(1234, 2345) // 'https://loremflickr.com/1234/2345/sports' - * faker.image.sports(1234, 2345, true) // 'https://loremflickr.com/1234/2345/sports?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'sports' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - */ - sports(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.sports', - proposed: - "faker.image.urlLoremFlickr({ category: 'sports' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'sports', randomize); - } - - /** - * Generates a random technics image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.technics() // 'https://loremflickr.com/640/480/technics' - * faker.image.technics(1234, 2345) // 'https://loremflickr.com/1234/2345/technics' - * faker.image.technics(1234, 2345, true) // 'https://loremflickr.com/1234/2345/technics?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'technics' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - */ - technics(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.technics', - proposed: - "faker.image.urlLoremFlickr({ category: 'technics' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'technics', randomize); - } - - /** - * Generates a random transport image url. - * - * @param width The width of the image. Defaults to `640`. - * @param height The height of the image. Defaults to `480`. - * @param randomize Whether to randomize the image or not. Defaults to `false`. - * - * @see faker.image.url(): For generating a random image url (has fewer options, uses multiple image providers). - * @see faker.image.urlLoremFlickr(): For generating a random image url from LoremFlickr. - * - * @example - * faker.image.transport() // 'https://loremflickr.com/640/480/transport' - * faker.image.transport(1234, 2345) // 'https://loremflickr.com/1234/2345/transport' - * faker.image.transport(1234, 2345, true) // 'https://loremflickr.com/1234/2345/transport?lock=56789' - * - * @since 2.0.1 - * - * @deprecated Use `faker.image.urlLoremFlickr({ category: 'transport' })` if you want an image from LoremFlickr in the correct category, or `faker.image.url()` if you just want any image. - * - * - */ - transport(width?: number, height?: number, randomize?: boolean): string { - deprecated({ - deprecated: 'faker.image.transport', - proposed: - "faker.image.urlLoremFlickr({ category: 'transport' }) or faker.image.url", - since: '8.0', - until: '9.0', - }); - // eslint-disable-next-line deprecation/deprecation - return this.imageUrl(width, height, 'transport', randomize); - } } diff --git a/test/modules/image.spec.ts b/test/modules/image.spec.ts index c272e623f65..d2439985ab2 100644 --- a/test/modules/image.spec.ts +++ b/test/modules/image.spec.ts @@ -89,22 +89,6 @@ describe('image', () => { type: 'svg-uri', }); }); - - t.skip('abstract'); - t.skip('animals'); - t.skip('business'); - t.skip('cats'); - t.skip('city'); - 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('avatar', () => {